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(in.
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;