Once upon a time I knew Java

After a long time working in Java. Started with the basic Java. Encapsulation, polymorphism, overloading, overriding blah blah blah. So write a small code without anyone’s help.

It takes the item details (item name, item price, item bar-code) from the user and prints the same in the console. Have a look.

ItemDetails.java

package item;

public class ItemDetails
{
public static void main(String[] args)
{
/*Input Data*/
inputreader read = new inputreader();
itemproperties itemprop = new itemproperties();

System.out.println();
System.out.println ("INPUT");

System.out.print("Enter Item Name : ");
itemprop.setItemName(read.getInputDetails());
System.out.print("Enter Item Price : ");
itemprop.setItemPrice(Integer.parseInt(read.getInputDetails()));
System.out.print("Enter Item Barcode : ");
itemprop.setItemBarcode(read.getInputDetails());

/*Output Data*/
System.out.println();
System.out.println ("OUTPUT");
System.out.println("Item Name : " +itemprop.getItemName());
System.out.println("Item Price : " +itemprop.getItemPrice());
System.out.println("Item Barcode : " +itemprop.getItemBarcode());
}
}

inputReader.java

package item;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class inputReader
{
public String getInputDetails()
{
String temp = null;
BufferedReader dataIn = new BufferedReader
(new InputStreamReader(System.in));

try
{
temp = dataIn.readLine();
}
catch( IOException e )
{
System.out.println("Error in getting Input");
}

return temp;
}


}

 

itemProperties.java

package item;

public class itemProperties
{
String itemName;
int itemPrice;
String itemBarcode;

/*Getter and Setter method*/

public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public int getItemPrice() {
return itemPrice;
}
public void setItemPrice(int itemPrice) {
this.itemPrice = itemPrice;
}
public String getItemBarcode() {
return itemBarcode;
}
public void setItemBarcode(String itemBarcode) {
this.itemBarcode = itemBarcode;
}
}

Tried In eclipse environment

eclipse java

After a long time not bad at all huh. What you say?

Advertisements

Published by

Anirban

I am software engineer by profession. Sometimes i post some topics about technology and some other topics which i find out interesting. My hobbies include watching movies,music, reading books(both technical and story books(fiction only)).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s