Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java homework 2

Jstorm1000
Jstorm1000 


It's a multiple class work that takes input of a user and sets it into a file instead of displaying it out on a console Attachments Tags
Clarifications

Answers

Solution to homework2

ravi_singh
ravi_singh 



I have attached three java files corresponding to three classes. put them in your IDE and run the InventoryTrackerInterface.java file.

Sample run of the program is attached. Please ask if you have any doubt.
You can contact me at ravi.kmr.singh8[at]gmail.com if you need further help.
Attachments
Inventory.java (1 K) Download Preview
public void addItem(Item newItem){ if(newItem==null || totalItems>=100){ // newItem is null or inventory is full System.out.println("Item Not Added!"); return; } itemArray[totalItems++]=newItem; } public void saveInventoryToFile(){ try { FileOutputStream fout=new FileOutputStream("inventory.txt"); PrintWriter pw=new PrintWriter(fout); for(int i=0;i<totalItems;i++){ pw.println(itemArray[i].getName());

InventoryTrackerInterface.java (1 K) Download Preview
Item itm=inv.getItem(Integer.parseInt(br.readLine())); System.out.println(itm); break; case 3: System.out.println("Saving Inventory to file..."); inv.saveInventoryToFile(); System.out.println("Inventory Saved"); break; case 4: System.out.println("Loading Inventory from file..."); inv.loadInventoryFromFile(); System.out.println("Inventory Loaded"); break; case 5: break; default: System.out.println("Invalid Input"); }

Item.java (1 K) Download Preview
} public void setName(String name){ this.name=name; } public void setUPC(String upc) { this.upc = upc; } public void setQuantity(int quantity) { this.quantity = quantity; } public void setPrice(double price) { this.price = price; } public

Run1.txt (1 K) Download Preview
the inventory 2)Get an items info 3)Save Inventory to file 4)Load inventory from file 5)Exit 1 Enter new Item's name Tomato Enter new Item's quantity 234 Enter new Item's price 2.45 Enter new Item's upc 12345 1)Add an item to the inventory 2)Get an items info 3)Save Inventory to file

Run2.txt (1 K) Download Preview
to the inventory 2)Get an items info 3)Save Inventory to file 4)Load inventory from file 5)Exit 1 Enter new Item's name Mango Enter new Item's quantity 78 Enter new Item's price 12.67 Enter new Item's upc 1632 1)Add an item to the inventory 2)Get an items info 3)Save Inventory to

Screenshots
Purchase Answer