Please help this program has to be in java The project will give you the opportu
ID: 3826170 • Letter: P
Question
Please help this program has to be in java
The project will give you the opportunity to review and practice on the following:
-Types of Data structure: Array Based Structure, Linked List structures, Hashed Data Structure or Binary Search
Tree Data structure
-Condition structure, loop structure
-read from keyboard
-working with the file:
-file: open, check file existing, read file, write to file
-class, object: constructor, mutator methods, accessor methods, toString and others, and how to access the class
members from client site
-display information on screen with requested format on numbers
-Handling input errors
-Write comments
REQUIREMENT:
Provide an application for a Warehouse that stores products for sale. The system keeps all the information of
products in the text file named as productInformation.txt
In the file productInformation.txt, the information of each type of products is writen on one line separated by a
comma (,) that includes itemId (String), model (String), name (String), unitPrice (double), quantity(integer), details (String), For example:
1001655218, ES95BR3065SWD6, Light Bulb, 29.97, 25, EcoSmart 65W Equivalent Soft White BR30 Dimmable CEC LED Light Bulb (6-Pack)
The application should allow users to do the following tasks and only terminate when users want to exit
1.Add One new item
2.Add more existing item
3.Sale item
4.Remove One Item
5.Search item by itemId
6.Search items by name
7.Show all items
Add One New Item:
(Insert) This task helps to insert one new item type to warehouse
-Display messages to ask and read information of one item from the keyboard then insert it to the data structure
Add more existing items:(update:increase quantity)
-Display messages to ask and read itemId from the keyboard, then use the itemId to fetch the information if this existing item, modify the field quantity then update the item to the data structure
Sale Items: (update:reduce quantity)
Remove One Item:(delete) This task helps to delete item type from the data structure
Search Item by ItemID:This task helps to search the item type with the key search is itemId, print out the item
*************************************
************************************
***
Item name: Light Bulbs
Item ID:1001655218
Model:ES95BR3065SWD6
Product name: Light Bulb
Unit price: $29.97
Count: 25
Detail: EcoSmart 65W Equivalent Soft White BR30 Dimmable CEC LED Light Bulb (6-Pack)
************************************
**************
*
*
*
*
*
*
*
*
*
*
************
****
Search Items by the name:This task helps to search theitems with the key search is the name of the item (for example “Light Bulb”, print out the list of all items having the same name but different itemId or model
IMPORTANT HINTS:-When the application starts, FIRST, you have to open the file productInformation.txt For each line, split information, create a node then insert to the data structure.
-During the application, all the tasks provided from the list only process in the data structure
-LAST: before terminating the application, open the file productInformation.txt and write all the nodes in the data structure back to the file, save them in database for next use.
HOW TO DO THE PROJECT
-Read the requirement to understand what the requirement asks for
-Determine how many data type classes we need,, what data structure you want to choose to work for this project and add the driver class that include main() named SP2017 PROJECT_WarehouseService_yourLastName)
Notes:
-Provide the UML of all data type classes
-Procide the pseudo
-code of main()
-You can choose any one of data structure type that we learned from the course to use for your project
-During the process of the application SP2017 PROJECT_WarehouseService_yourLastName, the tasks such as, add,remove or update, etc. on the items are only happened in the data structure; you don’t need to update output file
-When the users select the Exit task, before terminating the program, write all the information of items on the data structure back to the file itemsList_yourLastName.txt to save for future use.
HOW TO TURN IN
-UML of each data type and Pseudo code of your project in word document
-All the source code of data type classes (.java files) and all their .class files
-File productInformation.txt
Explanation / Answer
/*Inventory.java file with all Methods and Functions. Save The File as Inventory.java*/
package Inventory;
import java.io.*;
import java.util.Scanner;
class Inventory
{
private InputStreamReader ir=new InputStreamReader(System.in);
private BufferedReader br;
private FileOutputStream fos;
private PrintStream ps;
private FileReader frs;
Scanner sc;
//function to add new Item
private void addItem()
{
String model,name,details;
String id;
double unitprice=0;
int quantity;
try
{
br=new BufferedReader(ir);
sc=new Scanner(System.in);
System.out.print(" Item ID:");
id=sc.nextLine();
System.out.print(" Item Model:");
model=sc.nextLine();
System.out.print(" Item Name:");
name=sc.nextLine();
System.out.print(" Unit Price:$");
unitprice=sc.nextDouble();
System.out.print(" Item Quantity:");
quantity=sc.nextInt();
System.out.print(" Item Details:");
details=br.readLine();
fos=new FileOutputStream("productInformation.txt",true);
ps=new PrintStream(fos);
ps.println(id+","+model+","+name+","+unitprice+","+quantity+","+details);
fos.close();
System.out.println(" Successfully added one Item.");
}
catch(Exception ex)
{
System.out.println("Error in accepting item specifications.");
}
}
//function to make selling transaction for a specific product
private void makeTransaction()
{
String id;
String msg;
String value[]=new String[6];
double unitprice;
int qty=0,quantity;
try
{
br=new BufferedReader(ir);
System.out.print(" Enter Product ID :");
id=br.readLine();
msg=findProduct(id);
if(msg.equals("Product not found..."))
{
System.out.print(" "+msg);
}
br=new BufferedReader(ir);
value=msg.split(",");
/*if(Integer.parseInt(value[3])==Integer.parseInt(value[4]))
{
System.out.println("Need to generate a purchase order...");
continue;
}*/
id=value[0];
unitprice=Double.parseDouble(value[3]);
quantity=Integer.parseInt(value[4]);
if(quantity==0)
{
System.out.println("Current stock is NIL.");
}
System.out.println("Enter Quantity to be sold:");
qty=Integer.parseInt(br.readLine());
if(qty>quantity)
{
System.out.println("Out of stock.");
}
int d=updateStock(id,qty);
if(d==1)
{
System.out.println("Failed to update the stock.");
}
frs=new FileReader("productInformation.txt");
br=new BufferedReader(frs);
while((msg=br.readLine())!=null)
{
value=msg.split(",");
if(value[0].equals(id))
{
quantity=Integer.parseInt(value[4]);
break;
}
}
System.out.println("Transaction processed successfully.");
}
catch(Exception ex)
{
System.out.println("Item Not Found");
}
}
//function for searching a product id in the productInformation file
private String findProduct(String pID) throws IOException
{
int counter=0,i=0,flag=0;
String s;
String cline[]=new String[255];
String cID[]=new String[6];
String value=" ";
frs=new FileReader("productInformation.txt");
br=new BufferedReader(frs);
try
{
while((s=br.readLine())!=null)
{
counter=counter+1;
cline[counter]=s;
cID=cline[counter].split(",");
if(cID[0].equals(pID))
{
for(;i<cID.length;i++)
{
value=value+","+cID[i];
}
flag=1;
break;
}
}
switch(flag)
{
case 0:
value="Product not found.";
break;
case 1:
value=value.substring(2);
break;
}
}
catch(Exception ex)
{
System.out.println("Could continue operation on searching the product.");
}
return value;
}
//function for searching a product id in the productInformation file
private String findProductbyid(String pID) throws IOException
{
int counter=0,i=0,flag=0;
String s;
String cline[]=new String[255];
String cID[]=new String[6];
String value=" ";
frs=new FileReader("productInformation.txt");
br=new BufferedReader(frs);
try
{
while((s=br.readLine())!=null)
{
counter=counter+1;
cline[counter]=s;
cID=cline[counter].split(",");
if(cID[0].equals(pID))
{
System.out.println("Item Id:"+cID[0]);
System.out.println("Item Model:"+cID[1]);
System.out.println("Item Name:"+cID[2]);
System.out.println("Item Price:"+cID[3]);
System.out.println("Item Count:"+cID[4]);
System.out.println("Item Details:"+cID[5]);
flag=1;
break;
}
}
switch(flag)
{
case 0:
value="Product not found.";
break;
case 1:
break;
}
}
catch(Exception ex)
{
System.out.println("Could continue operation on searching the product.");
}
return value;
}
//function for searching Item name in the productInformation file
private String findProductbyname(String pID) throws IOException
{
int counter=0,i=0,flag=0;
String s,value=" ";
String cline[]=new String[255];
String cID[]=new String[5];
frs=new FileReader("productInformation.txt");
br=new BufferedReader(frs);
try
{
while((s=br.readLine())!=null)
{
counter=counter+1;
cline[counter]=s;
cID=cline[counter].split(",");
if(cID[2].equals(pID))
{
System.out.println("Item Id:"+cID[0]);
System.out.println("Item Model:"+cID[1]);
System.out.println("Item Name:"+cID[2]);
System.out.println("Item Price:"+cID[3]);
System.out.println("Item Count:"+cID[4]);
System.out.println("Item Details:"+cID[5]);
flag=1;
break;
}
}
switch(flag)
{
case 0:
value="Product not found.";
break;
case 1:
break;
}
}
catch(Exception ex)
{
System.out.println("Could continue operation on searching the product.");
}
return value;
}
//function for updating the value of current stock whenever a specific item is sold out
private int updateStock(String pID,int qty) throws IOException
{
int counter=0,i=0,pos=0;
String s;
String cline[]=new String[255];
String cID[]=new String[6];
String row[]=new String[6];
String model,name,details;
String id;
double unitprice=0;
int quantity,status=0;
try
{
frs=new FileReader("productInformation.txt");
br=new BufferedReader(frs);
while((s=br.readLine())!=null)
{
counter=counter+1;
cline[counter]=s;
cID=s.split(",");
if(cID[0].equals(pID))
{
pos=counter;
row=s.split(",");
}
}
fos=new FileOutputStream("productInformation.txt",false);
ps=new PrintStream(fos);
for(i=0;i<cline.length;i++)
{
if(i==pos)
{
id=row[0];
model=row[1];
name=row[2];
unitprice=Double.parseDouble(row[3]);
quantity=Integer.parseInt(row[4])-qty;
details=row[5];
ps.println(id+","+model+","+name+","+unitprice+","+quantity+","+details);
}
else
{
if(cline[i]!=null)
{
ps.println(cline[i]);
}
}
}
fos.close();
status=0;
}
catch(Exception ex)
{
status=1;
}
return status;
}
//Removing record by searching and deleting it
private int remove(String pID) throws IOException
{
int counter=0,i=0,pos=0;
String s;
String cline[]=new String[255];
String cID[]=new String[5];
String row[]=new String[5];
String model,name,details;
String id;
double unitprice=0;
int quantity,status=0;
try
{
frs=new FileReader("productInformation.txt");
br=new BufferedReader(frs);
while((s=br.readLine())!=null)
{
counter=counter+1;
cline[counter]=s;
cID=s.split(",");
if(cID[0].equals(pID))
{
pos=counter;
row=s.split(",");
}
}
fos=new FileOutputStream("productInformation.txt",false);
ps=new PrintStream(fos);
for(i=0;i<cline.length;i++)
{
if(i==pos)
{
id="";
model="";
name="";
unitprice=0.0;
quantity=0;
details="";
}
else
{
if(cline[i]!=null)
{
ps.println(cline[i]);
}
}
}
fos.close();
status=0;
}
catch(Exception ex)
{
status=1;
}
return status;
}
//for adding quantity or modifying the quantity of available item
private int addmoreitem(String pID,int qty) throws IOException
{
int counter=0,i=0,pos=0;
String s;
String cline[]=new String[255];
String cID[]=new String[5];
String row[]=new String[5];
String id,model,name,details;
int quantity,status=0;
double unitprice;
try
{
frs=new FileReader("productInformation.txt");
br=new BufferedReader(frs);
while((s=br.readLine())!=null)
{
counter=counter+1;
cline[counter]=s;
cID=s.split(",");
if(cID[0].equals(pID))
{
pos=counter;
row=s.split(",");
}
}
fos=new FileOutputStream("productInformation.txt",false);
ps=new PrintStream(fos);
for(i=0;i<cline.length;i++)
{
if(i==pos)
{
id=row[0];
model=row[1];
name=row[2];
unitprice=Double.parseDouble(row[3]);
quantity=Integer.parseInt(row[4])+qty;
details=row[5];
ps.println(id+","+model+","+name+","+unitprice+","+quantity+","+details);
}
else
{
if(cline[i]!=null)
{
ps.println(cline[i]);
}
}
}
fos.close();
status=0;
}
catch(Exception ex)
{
status=1;
ex.printStackTrace();
}
return status;
}
//function to generate and print the daily transaction report
private void displayReport()
{
String s,id,model,name,details;
double unitprice=0;
int quantity;
String cline[]=new String[6];
try
{
frs=new FileReader("productInformation.txt");
br=new BufferedReader(frs);
System.out.println(" Item_ID Item_Model Item_Name Item_Price Item_quantity Item_Details");
System.out.println("-------------------------------------------------------------------------");
while((s=br.readLine())!=null)
{
cline=s.split(",");
id=cline[0];
model=cline[1];
name=cline[2];
unitprice=Double.parseDouble(cline[3]);
quantity=Integer.parseInt(cline[4]);
details=cline[5];
System.out.println(id+" "+model+" "+name+" $"+unitprice+" "+quantity+" "+details);
}
}
catch(Exception ex)
{
System.out.println("Some exceptions occured.");
ex.printStackTrace();
}
}
public static void main(String args[]) throws IOException
{
Inventory inv=new Inventory();
int ch=0,qty;
String item,result;
String check = null;
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
do
{
System.out.println("Inventory Management System");
System.out.println("-----------------------------------------------");
System.out.println("1. Add One New Item");
System.out.println("2. Add More Existing Item");
System.out.println("3. Sale Item 4. Remove One Item 5. Search Item By ID 6. Search Item By Name 7. Show All Item");
System.out.println("8. Exit");
System.out.print("Enter Your Choice:");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
inv.addItem();
break;
case 2:
System.out.println("Enter The Item Id:");
item=br.readLine();
result=inv.findProduct(item);
if(result!="Product not found.")
{
System.out.println("Enter The Quantity You Want to Add:");
qty=Integer.parseInt(br.readLine());
inv.addmoreitem(item,qty);
System.out.println("Quantity Added Successfully");
}
else
{
System.out.println("Item Not Found");
}
break;
case 3:
inv.makeTransaction();
break;
case 4:
System.out.println("Enter The Item Id to Be Removed:");
item=br.readLine();
result=inv.findProduct(item);
if(result!="Product not found...")
{
inv.remove(item);
}
else
{
System.out.println("");
}
break;
case 5:
System.out.println("Enter The Item Id:");
item=br.readLine();
result=inv.findProductbyid(item);
if(result.equals("Product not found."))
{
System.out.println("Item Not Found");
}
break;
case 6:
System.out.println("Enter The Item Name:");
item=br.readLine();
result=inv.findProductbyname(item);
if(result.equals("Product not found."))
{
System.out.println("Item Not Found");
}
break;
case 7:
inv.displayReport();
break;
case 8:
System.out.println("Thanks for using this program...!");
check="n";
break;
default:System.out.println("Thanks for using this program...!");
break;
}
if(ch!=8)
{
System.out.println("Do You want to Continue:[Y/N]");
check=br.readLine();
}
}while(check.charAt(0)=='y'||check.charAt(0)=='Y');
}
}
/*productInformation.txt
* 1001655218, ES95BR3065SWD6, Light Bulb, 29.97, 25, EcoSmart 65W Equivalent Soft White BR30 Dimmable CEC LED Light Bulb (6-Pack)
* add items in it..
* I hope your all requirement are fulfilled..
* */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.