SlideShare a Scribd company logo
1 of 9
Download to read offline
This is a java lab assignment. I have added the first part "java retail class" at the bottom. I am
unsure how to read the txt file into an array from the retail class. The stock txt file has been
added also.
A beginning framework and inventory list has been provided to you to use your Retail Item Class
as an array. Develop a program to accomplish the following menu items that can be selected by
the end user. Discussion of what each menu item should do is provided below the menu item.
Modify your object class file as desired. Please append initials to files created. Use Select-Case
for menu choices and methods to perform those choices. Please make a selection: 1. Open
Inventory File (This should ask the user for the file name, open the file and load the data into the
object array). 2. Display All (This should show a table of all items and data) 3. Display Reorder
Only (This should show only the stock number, Description and current quantity for items
requiring reorder) 4. Find Stock number (Allows the user to enter part of the description and
displays all matching stock numbers and descriptions matching that - case insensitive, such as
“cubs” or “cubs”) 5. Display Stock number (Allows user to enter stock number and displays
record of item) 6. Add Quantity (Asks for stock number and quantity for units, adds it to current,
displays record results) 7. Subtract Quantity (Asks for stock number and quantity, subtracts,
displays results including if reorder is needed.) 8. Change Price (Asks for stick number, changes
price to provided value, display results). 9. New Item (Allows adding a new item, updates count.
Display record results). 10. Save Inventory File (asks user for file name, save all inventory to
that file in a format that can be read back.)
public class RetailItem{
private String description;
private int unitsOnHand;
private double price;
private int restock;
public void setDescription(String userDescription){
description=userDescription;
}
public void setUnitsOnHand(int userUnitsOnHand){
unitsOnHand=userUnitsOnHand;
}
public void setPrice(double userPrice){
price=userPrice;
}
public String getDescription(){
return description;
}
public int getUnitsOnHand(){
return unitsOnHand;
}
public double getPrice(){
return price;
}
public double getTotal(){
int total = unitsOnHand=(int) price;
return total;
}
public boolean getRestock(){
return false;
}
public RetailItem(String descriptionGiven, int unitsOnHandGiven, double priceGiven, int
restockGiven){
description=descriptionGiven;
unitsOnHand=unitsOnHandGiven;
price=priceGiven;
restock=restockGiven;
}
}
Solution
public class RetailItem{
private int stocknumber;
private String description;
private int unitsOnHand;
private double price;
private int restock;
public void setDescription(String userDescription){
description=userDescription;
}
public int getStocknumber() {
return stocknumber;
}
public void setStocknumber(int stocknumber) {
this.stocknumber = stocknumber;
}
public void setUnitsOnHand(int userUnitsOnHand){
unitsOnHand=userUnitsOnHand;
}
public void setPrice(double userPrice){
price=userPrice;
}
public String getDescription(){
return description;
}
public int getUnitsOnHand(){
return unitsOnHand;
}
public double getPrice(){
return price;
}
public double getTotal(){
int total = unitsOnHand=(int) price;
return total;
}
public boolean getRestock(){
return false;
}
@Override
public String toString() {
return stocknumber + " " + description + " " + unitsOnHand + " " + price + " " + restock
+ " ";
}
public RetailItem(int stock,String descriptionGiven, int unitsOnHandGiven, double priceGiven,
int restockGiven){
stocknumber=stock;
description=descriptionGiven;
unitsOnHand=unitsOnHandGiven;
price=priceGiven;
restock=restockGiven;
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class RetailItemStore {
public static RetailItem[] item = new RetailItem[100];
public static int count = 0;
public static int choice = 0;
public static void menu() {
System.out.println("Main Menu: ");
System.out.println("1. Open Inventory File ");
System.out.println("2. Display All ");
System.out.println("3. Display Reorder Only ");
System.out.println("4. Find Stock number ");
System.out.println("5. Display Stock number ");
System.out.println("6. Add Quantity ");
System.out.println("7. Subtract Quantity ");
System.out.println("8. Change Price ");
System.out.println("9. New Item ");
System.out.println("10. Save Inventory File ");
System.out.println("11. Exit ");
System.out.println("Enter your choice:");
}
public static void Load(String filename) {
try {
File f = new File(filename);
Scanner s = new Scanner(f);
while (s.hasNext()) {
item[count] = new RetailItem(s.nextInt(), s.nextLine(), s.nextInt(), s.nextDouble(), s.nextInt());
count++;
}
} catch (FileNotFoundException ex) {
System.out.println(ex.getMessage());
}
}
public static void Save(String filename) {
PrintWriter p = null;
try {
File f = new File(filename);
p = new PrintWriter(f);
for (int i = 0; i < count; i++) {
p.write(item[i].toString());
}
} catch (FileNotFoundException ex) {
System.out.println(ex.getMessage());
} finally {
p.close();
}
}
public static void main(String[] args) {
boolean loop = true;
while (loop) {
menu();
Scanner si = new Scanner(System.in);
choice = si.nextInt();
switch (choice) {
case 1:
System.out.println("Enter the file name: ");
String file = si.next();
Load(file);
break;
case 2:
for (int i = 0; i < count; i++) {
System.out.println(item[i].toString());
}
break;
case 3:
//what is reorder??
break;
case 4:
System.out.println("Enter the description: ");
String des = si.next();
for (int i = 0; i < count; i++) {
if (item[i].getDescription().contains(des)) {
System.out.println(item[i].toString());
}
}
break;
case 5:
System.out.println("Enter the stock number: ");
int num = si.nextInt();
for (int i = 0; i < count; i++) {
if (item[i].getStocknumber() == num) {
System.out.println(item[i].toString());
}
}
break;
case 6:
System.out.println("Enter the stock number: ");
int num1 = si.nextInt();
System.out.println("Enter the Quantity to add: ");
int q1 = si.nextInt();
for (int i = 0; i < count; i++) {
if (item[i].getStocknumber() == num1) {
item[i].setUnitsOnHand(item[i].getUnitsOnHand() + q1);
}
}
break;
case 7:
System.out.println("Enter the stock number: ");
int num2 = si.nextInt();
System.out.println("Enter the Quantity to Subtract: ");
int q2 = si.nextInt();
for (int i = 0; i < count; i++) {
if (item[i].getStocknumber() == num2) {
item[i].setUnitsOnHand(item[i].getUnitsOnHand() - q2);
}
}
break;
case 8:
System.out.println("Enter the stock number: ");
int num3 = si.nextInt();
System.out.println("Enter the New Price: ");
int p1 = si.nextInt();
for (int i = 0; i < count; i++) {
if (item[i].getStocknumber() == num3) {
item[i].setPrice(p1);
}
}
break;
case 9:
int newitemstnum,
newitemsunit,
newitemsprice,
newitemsre;
String desp = "";
System.out.println("Enter the new stock number");
newitemstnum = si.nextInt();
System.out.println("Enter the Description");
desp = si.next();
System.out.println("Enter the quantity");
newitemsunit = si.nextInt();
System.out.println("Enter the price");
newitemsprice = si.nextInt();
System.out.println("Enter the restock");
newitemsre = si.nextInt();
item[count] = new RetailItem(newitemstnum, desp, newitemsunit, newitemsprice, newitemsre);
count++;
System.out.println("Item Added Successfully");
break;
case 10:
System.out.println("Enter the file name: ");
String file1 = si.next();
Save(file1);
System.out.println("Data Saved Successfully");
break;
case 11:
loop = false;
break;
default:
System.out.println("Invalid choice!! please retry");
}
}
}
}

More Related Content

Similar to This is a java lab assignment. I have added the first part java re.pdf

PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docxalfred4lewis58146
 
File Input & Output
File Input & OutputFile Input & Output
File Input & OutputPRN USM
 
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdfUsing Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdffms12345
 
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxC#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxRAHUL126667
 
10 sharing files and data in windows phone 8
10   sharing files and data in windows phone 810   sharing files and data in windows phone 8
10 sharing files and data in windows phone 8WindowsPhoneRocks
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfPRATIKSINHA7304
 
Parameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputParameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputuanna
 
I can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxI can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxhamblymarta
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docxtheodorelove43763
 
Writing Swift code with great testability
Writing Swift code with great testabilityWriting Swift code with great testability
Writing Swift code with great testabilityJohn Sundell
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarROHIT JAISWAR
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdffantoosh1
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfsravi07
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfmayorothenguyenhob69
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfIan5L3Allanm
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfsangeeta borde
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdfganisyedtrd
 

Similar to This is a java lab assignment. I have added the first part java re.pdf (20)

PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docx
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
 
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdfUsing Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
 
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxC#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
 
10 sharing files and data in windows phone 8
10   sharing files and data in windows phone 810   sharing files and data in windows phone 8
10 sharing files and data in windows phone 8
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Parameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputParameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple input
 
Inheritance
InheritanceInheritance
Inheritance
 
I can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxI can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docx
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
 
Writing Swift code with great testability
Writing Swift code with great testabilityWriting Swift code with great testability
Writing Swift code with great testability
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
 
srgoc
srgocsrgoc
srgoc
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 

More from feetshoemart

Convert the following expressions from infix to Reverse Polish Notati.pdf
Convert the following expressions from infix to Reverse Polish Notati.pdfConvert the following expressions from infix to Reverse Polish Notati.pdf
Convert the following expressions from infix to Reverse Polish Notati.pdffeetshoemart
 
Andy and Joan are married and under 65 years of age. They have two c.pdf
Andy and Joan are married and under 65 years of age. They have two c.pdfAndy and Joan are married and under 65 years of age. They have two c.pdf
Andy and Joan are married and under 65 years of age. They have two c.pdffeetshoemart
 
Compare the methods by which the Parsees of India benefitted from th.pdf
Compare the methods by which the Parsees of India benefitted from th.pdfCompare the methods by which the Parsees of India benefitted from th.pdf
Compare the methods by which the Parsees of India benefitted from th.pdffeetshoemart
 
Computer Forensics MethodologiesList them and explain each one.P.pdf
Computer Forensics MethodologiesList them and explain each one.P.pdfComputer Forensics MethodologiesList them and explain each one.P.pdf
Computer Forensics MethodologiesList them and explain each one.P.pdffeetshoemart
 
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdf
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdfDocument2- Word (Product Activation Failed) Mailings Review View Tell.pdf
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdffeetshoemart
 
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdf
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdfDiscussion 1 Choose one of the Opinion Poll questions (click here f.pdf
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdffeetshoemart
 
calculate the hydrogen ion concentration in mol for the following s.pdf
calculate the hydrogen ion concentration in mol for the following s.pdfcalculate the hydrogen ion concentration in mol for the following s.pdf
calculate the hydrogen ion concentration in mol for the following s.pdffeetshoemart
 
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdfAt a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdffeetshoemart
 
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdfConsider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdffeetshoemart
 
wk3 reply to prof.I need help with this question below a 200 words.pdf
wk3 reply to prof.I need help with this question below a 200 words.pdfwk3 reply to prof.I need help with this question below a 200 words.pdf
wk3 reply to prof.I need help with this question below a 200 words.pdffeetshoemart
 
Write a program that prompts the user to enter a positive integer and.pdf
Write a program that prompts the user to enter a positive integer and.pdfWrite a program that prompts the user to enter a positive integer and.pdf
Write a program that prompts the user to enter a positive integer and.pdffeetshoemart
 
Write a function called countElements that counts the number of times.pdf
Write a function called countElements that counts the number of times.pdfWrite a function called countElements that counts the number of times.pdf
Write a function called countElements that counts the number of times.pdffeetshoemart
 
There is no video, All you have to do is show how you reference the .pdf
There is no video, All you have to do is show how you reference the .pdfThere is no video, All you have to do is show how you reference the .pdf
There is no video, All you have to do is show how you reference the .pdffeetshoemart
 
The process of Imperialism and Colonialism played a role in the esta.pdf
The process of Imperialism and Colonialism played a role in the esta.pdfThe process of Imperialism and Colonialism played a role in the esta.pdf
The process of Imperialism and Colonialism played a role in the esta.pdffeetshoemart
 
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdfTerrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdffeetshoemart
 
What do viral genomes look like compared to those of living organism.pdf
What do viral genomes look like compared to those of living organism.pdfWhat do viral genomes look like compared to those of living organism.pdf
What do viral genomes look like compared to those of living organism.pdffeetshoemart
 
Verify the identity Verify the identity by transforming the left-han.pdf
Verify the identity Verify the identity by transforming the left-han.pdfVerify the identity Verify the identity by transforming the left-han.pdf
Verify the identity Verify the identity by transforming the left-han.pdffeetshoemart
 
Using following main file and solve the taskInst.pdf
Using following main file and solve the taskInst.pdfUsing following main file and solve the taskInst.pdf
Using following main file and solve the taskInst.pdffeetshoemart
 
Suppose there are 14 children trying to form two teams with seven ch.pdf
Suppose there are 14 children trying to form two teams with seven ch.pdfSuppose there are 14 children trying to form two teams with seven ch.pdf
Suppose there are 14 children trying to form two teams with seven ch.pdffeetshoemart
 
11. Define a simple deformable model to detect a half-circular shape.pdf
11. Define a simple deformable model to detect a half-circular shape.pdf11. Define a simple deformable model to detect a half-circular shape.pdf
11. Define a simple deformable model to detect a half-circular shape.pdffeetshoemart
 

More from feetshoemart (20)

Convert the following expressions from infix to Reverse Polish Notati.pdf
Convert the following expressions from infix to Reverse Polish Notati.pdfConvert the following expressions from infix to Reverse Polish Notati.pdf
Convert the following expressions from infix to Reverse Polish Notati.pdf
 
Andy and Joan are married and under 65 years of age. They have two c.pdf
Andy and Joan are married and under 65 years of age. They have two c.pdfAndy and Joan are married and under 65 years of age. They have two c.pdf
Andy and Joan are married and under 65 years of age. They have two c.pdf
 
Compare the methods by which the Parsees of India benefitted from th.pdf
Compare the methods by which the Parsees of India benefitted from th.pdfCompare the methods by which the Parsees of India benefitted from th.pdf
Compare the methods by which the Parsees of India benefitted from th.pdf
 
Computer Forensics MethodologiesList them and explain each one.P.pdf
Computer Forensics MethodologiesList them and explain each one.P.pdfComputer Forensics MethodologiesList them and explain each one.P.pdf
Computer Forensics MethodologiesList them and explain each one.P.pdf
 
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdf
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdfDocument2- Word (Product Activation Failed) Mailings Review View Tell.pdf
Document2- Word (Product Activation Failed) Mailings Review View Tell.pdf
 
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdf
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdfDiscussion 1 Choose one of the Opinion Poll questions (click here f.pdf
Discussion 1 Choose one of the Opinion Poll questions (click here f.pdf
 
calculate the hydrogen ion concentration in mol for the following s.pdf
calculate the hydrogen ion concentration in mol for the following s.pdfcalculate the hydrogen ion concentration in mol for the following s.pdf
calculate the hydrogen ion concentration in mol for the following s.pdf
 
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdfAt a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf
At a certain temperature, 0.5011 mol of N2 and 1.781 mol of H2 are pl.pdf
 
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdfConsider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
Consider mappinp, phi Z rightarrow R, defined as phi(x) = 2x, where .pdf
 
wk3 reply to prof.I need help with this question below a 200 words.pdf
wk3 reply to prof.I need help with this question below a 200 words.pdfwk3 reply to prof.I need help with this question below a 200 words.pdf
wk3 reply to prof.I need help with this question below a 200 words.pdf
 
Write a program that prompts the user to enter a positive integer and.pdf
Write a program that prompts the user to enter a positive integer and.pdfWrite a program that prompts the user to enter a positive integer and.pdf
Write a program that prompts the user to enter a positive integer and.pdf
 
Write a function called countElements that counts the number of times.pdf
Write a function called countElements that counts the number of times.pdfWrite a function called countElements that counts the number of times.pdf
Write a function called countElements that counts the number of times.pdf
 
There is no video, All you have to do is show how you reference the .pdf
There is no video, All you have to do is show how you reference the .pdfThere is no video, All you have to do is show how you reference the .pdf
There is no video, All you have to do is show how you reference the .pdf
 
The process of Imperialism and Colonialism played a role in the esta.pdf
The process of Imperialism and Colonialism played a role in the esta.pdfThe process of Imperialism and Colonialism played a role in the esta.pdf
The process of Imperialism and Colonialism played a role in the esta.pdf
 
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdfTerrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
 
What do viral genomes look like compared to those of living organism.pdf
What do viral genomes look like compared to those of living organism.pdfWhat do viral genomes look like compared to those of living organism.pdf
What do viral genomes look like compared to those of living organism.pdf
 
Verify the identity Verify the identity by transforming the left-han.pdf
Verify the identity Verify the identity by transforming the left-han.pdfVerify the identity Verify the identity by transforming the left-han.pdf
Verify the identity Verify the identity by transforming the left-han.pdf
 
Using following main file and solve the taskInst.pdf
Using following main file and solve the taskInst.pdfUsing following main file and solve the taskInst.pdf
Using following main file and solve the taskInst.pdf
 
Suppose there are 14 children trying to form two teams with seven ch.pdf
Suppose there are 14 children trying to form two teams with seven ch.pdfSuppose there are 14 children trying to form two teams with seven ch.pdf
Suppose there are 14 children trying to form two teams with seven ch.pdf
 
11. Define a simple deformable model to detect a half-circular shape.pdf
11. Define a simple deformable model to detect a half-circular shape.pdf11. Define a simple deformable model to detect a half-circular shape.pdf
11. Define a simple deformable model to detect a half-circular shape.pdf
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

This is a java lab assignment. I have added the first part java re.pdf

  • 1. This is a java lab assignment. I have added the first part "java retail class" at the bottom. I am unsure how to read the txt file into an array from the retail class. The stock txt file has been added also. A beginning framework and inventory list has been provided to you to use your Retail Item Class as an array. Develop a program to accomplish the following menu items that can be selected by the end user. Discussion of what each menu item should do is provided below the menu item. Modify your object class file as desired. Please append initials to files created. Use Select-Case for menu choices and methods to perform those choices. Please make a selection: 1. Open Inventory File (This should ask the user for the file name, open the file and load the data into the object array). 2. Display All (This should show a table of all items and data) 3. Display Reorder Only (This should show only the stock number, Description and current quantity for items requiring reorder) 4. Find Stock number (Allows the user to enter part of the description and displays all matching stock numbers and descriptions matching that - case insensitive, such as “cubs” or “cubs”) 5. Display Stock number (Allows user to enter stock number and displays record of item) 6. Add Quantity (Asks for stock number and quantity for units, adds it to current, displays record results) 7. Subtract Quantity (Asks for stock number and quantity, subtracts, displays results including if reorder is needed.) 8. Change Price (Asks for stick number, changes price to provided value, display results). 9. New Item (Allows adding a new item, updates count. Display record results). 10. Save Inventory File (asks user for file name, save all inventory to that file in a format that can be read back.) public class RetailItem{ private String description; private int unitsOnHand; private double price; private int restock; public void setDescription(String userDescription){ description=userDescription; } public void setUnitsOnHand(int userUnitsOnHand){ unitsOnHand=userUnitsOnHand; }
  • 2. public void setPrice(double userPrice){ price=userPrice; } public String getDescription(){ return description; } public int getUnitsOnHand(){ return unitsOnHand; } public double getPrice(){ return price; } public double getTotal(){ int total = unitsOnHand=(int) price; return total; } public boolean getRestock(){ return false; } public RetailItem(String descriptionGiven, int unitsOnHandGiven, double priceGiven, int restockGiven){ description=descriptionGiven; unitsOnHand=unitsOnHandGiven; price=priceGiven; restock=restockGiven; } }
  • 3. Solution public class RetailItem{ private int stocknumber; private String description; private int unitsOnHand; private double price; private int restock; public void setDescription(String userDescription){ description=userDescription; } public int getStocknumber() { return stocknumber; } public void setStocknumber(int stocknumber) { this.stocknumber = stocknumber; } public void setUnitsOnHand(int userUnitsOnHand){ unitsOnHand=userUnitsOnHand; } public void setPrice(double userPrice){ price=userPrice; } public String getDescription(){ return description; } public int getUnitsOnHand(){ return unitsOnHand; }
  • 4. public double getPrice(){ return price; } public double getTotal(){ int total = unitsOnHand=(int) price; return total; } public boolean getRestock(){ return false; } @Override public String toString() { return stocknumber + " " + description + " " + unitsOnHand + " " + price + " " + restock + " "; } public RetailItem(int stock,String descriptionGiven, int unitsOnHandGiven, double priceGiven, int restockGiven){ stocknumber=stock; description=descriptionGiven; unitsOnHand=unitsOnHandGiven; price=priceGiven; restock=restockGiven; } } import java.io.File; import java.io.FileNotFoundException;
  • 5. import java.io.PrintWriter; import java.util.Scanner; public class RetailItemStore { public static RetailItem[] item = new RetailItem[100]; public static int count = 0; public static int choice = 0; public static void menu() { System.out.println("Main Menu: "); System.out.println("1. Open Inventory File "); System.out.println("2. Display All "); System.out.println("3. Display Reorder Only "); System.out.println("4. Find Stock number "); System.out.println("5. Display Stock number "); System.out.println("6. Add Quantity "); System.out.println("7. Subtract Quantity "); System.out.println("8. Change Price "); System.out.println("9. New Item "); System.out.println("10. Save Inventory File "); System.out.println("11. Exit "); System.out.println("Enter your choice:"); } public static void Load(String filename) { try { File f = new File(filename); Scanner s = new Scanner(f); while (s.hasNext()) { item[count] = new RetailItem(s.nextInt(), s.nextLine(), s.nextInt(), s.nextDouble(), s.nextInt()); count++; } } catch (FileNotFoundException ex) { System.out.println(ex.getMessage()); } } public static void Save(String filename) { PrintWriter p = null; try {
  • 6. File f = new File(filename); p = new PrintWriter(f); for (int i = 0; i < count; i++) { p.write(item[i].toString()); } } catch (FileNotFoundException ex) { System.out.println(ex.getMessage()); } finally { p.close(); } } public static void main(String[] args) { boolean loop = true; while (loop) { menu(); Scanner si = new Scanner(System.in); choice = si.nextInt(); switch (choice) { case 1: System.out.println("Enter the file name: "); String file = si.next(); Load(file); break; case 2: for (int i = 0; i < count; i++) { System.out.println(item[i].toString()); } break; case 3: //what is reorder?? break; case 4: System.out.println("Enter the description: "); String des = si.next(); for (int i = 0; i < count; i++) { if (item[i].getDescription().contains(des)) {
  • 7. System.out.println(item[i].toString()); } } break; case 5: System.out.println("Enter the stock number: "); int num = si.nextInt(); for (int i = 0; i < count; i++) { if (item[i].getStocknumber() == num) { System.out.println(item[i].toString()); } } break; case 6: System.out.println("Enter the stock number: "); int num1 = si.nextInt(); System.out.println("Enter the Quantity to add: "); int q1 = si.nextInt(); for (int i = 0; i < count; i++) { if (item[i].getStocknumber() == num1) { item[i].setUnitsOnHand(item[i].getUnitsOnHand() + q1); } } break; case 7: System.out.println("Enter the stock number: "); int num2 = si.nextInt(); System.out.println("Enter the Quantity to Subtract: "); int q2 = si.nextInt(); for (int i = 0; i < count; i++) { if (item[i].getStocknumber() == num2) { item[i].setUnitsOnHand(item[i].getUnitsOnHand() - q2); } } break; case 8:
  • 8. System.out.println("Enter the stock number: "); int num3 = si.nextInt(); System.out.println("Enter the New Price: "); int p1 = si.nextInt(); for (int i = 0; i < count; i++) { if (item[i].getStocknumber() == num3) { item[i].setPrice(p1); } } break; case 9: int newitemstnum, newitemsunit, newitemsprice, newitemsre; String desp = ""; System.out.println("Enter the new stock number"); newitemstnum = si.nextInt(); System.out.println("Enter the Description"); desp = si.next(); System.out.println("Enter the quantity"); newitemsunit = si.nextInt(); System.out.println("Enter the price"); newitemsprice = si.nextInt(); System.out.println("Enter the restock"); newitemsre = si.nextInt(); item[count] = new RetailItem(newitemstnum, desp, newitemsunit, newitemsprice, newitemsre); count++; System.out.println("Item Added Successfully"); break; case 10: System.out.println("Enter the file name: "); String file1 = si.next(); Save(file1); System.out.println("Data Saved Successfully"); break;
  • 9. case 11: loop = false; break; default: System.out.println("Invalid choice!! please retry"); } } } }