This assignment is enhancing your Project 2 solutions. As for now, you can keep the inventory in a file and upload it to

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

This assignment is enhancing your Project 2 solutions. As for now, you can keep the inventory in a file and upload it to

Post by answerhappygod »

This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 1
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 1 (54.43 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 2
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 2 (35.67 KiB) Viewed 15 times
code
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 3
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 3 (39.74 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 4
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 4 (43.66 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 5
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 5 (18.68 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 6
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 6 (27.88 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 7
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 7 (22.26 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 8
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 8 (29.98 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 9
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 9 (20.69 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 10
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 10 (21.71 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 11
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 11 (21.49 KiB) Viewed 15 times
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 12
This Assignment Is Enhancing Your Project 2 Solutions As For Now You Can Keep The Inventory In A File And Upload It To 12 (21.49 KiB) Viewed 15 times
This assignment is enhancing your Project 2 solutions. As for now, you can keep the inventory in a file and upload it to the array available for your program. It is time to think about how to improve the data model and functionality of the application. Note that the three types of products have much in common and something different. Hence, three child classes of an abstract class is a suitable model that allows different pricing methods defined inside different classes. After that, any application can use product classes without knowing how methods work. And if a method needs to be changed, it will be changed only once inside the class definition. Task #1 Add a new property to the product class - a static variable that holds the number of products in the inventory. Its value must grow as reading from the file progresses. Use this variable whenever you need the size of the inventory. Override a default toString() method such that it returns product ID, name, regular price, and type. Update your menu output method such that it uses the toString() method implicitly or explicitly. If you have not done it in your Project 2, make your program repeat until the user decides to quit. The attached file While Loop.java may help to implement the program repetition. Alternatively, you may add the "Quit" item to the bottom of the menu to stop the program.
import java.util.Scanner; public class While Loop { public static void main(String[] args) { loop? (y/n)"); } Scanner scan = new Scanner (System.in); System.out.println("Do you want to continue to while (!s.equals("n") ) { System.out.println("Do you want to continue to loop? (y/n)"); s scan.next(); } Strings scan.next(); }
//product java import public class product { ( } java.util.Scanner; public static void getStoreinventory() System.out.printf("\nThe inventory:"); System.out.printf("1. System.out.printf("2. %-20s % -10s % 5s\n", "Cookies". "$3.00", "X"); %-20s %-10s %5sin", "socks", $5.99", "X"); %-20s % -10s %5s\n", "Pencil". "$0.15". "Y"); %-20s %-10s %5s\n", "Sharpener". "$0.25", "Y"); System.out.printf("3. System.out.printf("4. System.out.printf("5. %-20s % -10s %5s\n", "Teddy bear", "$10.00", "Z"); System.out.printf("6. %-20s % -10s %5s\n", "toy". "15.00", "Z"); //list type of product x,y or z public static void main(String[] args) { double[] amount = new double [] {3,5.99, 0.15, 0.25, 10, 15); int[] products = new int[] (1. 1.2.2, 3,3); //This is the list of inventory int day; int month; int year; // Special sale Scanner scanner = new Scanner(System.in): System.out.println("What month do you plan your purchase?"); month= scanner.nextInt(): scanner.nextLine(): { while(month < 1 || month > 12) System.out.println(" months are from 1 to 12."); month = scanner.nextInt(): scanner.nextLine();}
//This wile loop checks the validity from of the input from day 1 to 31 within a month System.out.print("Day?:"); day scanner.nextInt(): scanner.nextLine(); while(day < 1 || day > 31) { System.out.println("1-31."); day scanner.nextInt(); scanner.nextLine():) System.out.print("What year do you plan your purchase "); year = scanner.nextInt(); scanner.nextLine(); while(year < 2022 || year > 2050) { System.out.println("only 2022-2050."); year = scanner.nextInt(); scanner.nextLine(); getStoreinventory(): //gives a choice for a number corresponding to the product you would like to buy System.out.print("What would you like to buy? "); int material = scanner.nextInt(); scanner.nextLine(): //Program close after choice incorrect if (material < 1 || material > 6) { System.out.println("Choice selected is invalid, Goodbye."); } else { int item Type = products[material - 1]; System.out.print("How many units would you like to purchase?:"); int units = scanner.nextInt(): scanner.nextLine(); //This allows for the program to switch through different item types switch (item Type) { case 1: xProduct X = new xProduct(amount[material - 1], units);
case 1: xProduct X = new xProduct(amount[material - 1], units); X.display(); break; case 2: } yProduct Y = new yProduct(amount[material - 1], units); Y.display(); break; case 3: boolean occSale = false; if (month == 9) { if (day <= 29) ( } } { } occSale = true; if (day >= 10) occSale = true; occSale = true; zProduct Z = new zProduct(amount[material - 1], units, occSale); Z.display(); break;
I/Xproductclass public class xProduct int units; double cost; double fullCost cost * units; int cents; public xProduct( double cost,int units) { this.units units; this.cost = cost;} // getter cost of x product public double getCost() { return cost;} //This setter the price of the x product public void setPrice(double cost) { this.cost = cost; } public double getfullCost() { return cost units } //full cost method public void display() { double output = getfullCost(); int dollar = (int) output;// before discount price double purchaseCents = (output-dollar)* 100; if (purchaseCents-(int) 0.5<=purchaseCents) { cents = (int) purchaseCents ++) else { cents = (int) purchaseCents;} System.out.printf("Your payment is: %d dollars %d cents\n", dollar, cents); } Getter number of units int units() { return units: Setter for number of units public void units(int units) { this.units = units;
IIY Product class public class yProduct { double cost;// int units; double fullCost = cost * units; double output = cost * units; int dollar (int) output; double purchaseCents = (output - dollar) * 100; int cents; public void yProduct(double cost, int units) { this.cost = cost: this.units = units;} /calculate price for y item public void display() { if(units > 100 | units < 500) { cost *= (95);
System.out.printf("Buying more than 500 units of products, means that you have to pay, $%.2f per unit\\", cost *(0.85) ); System.out.printf("Buying more than 1500 units of products, means that you have to pay, $%.2f per unit\\n", cost "(0.75) ); } else if (units < 100) { System.out.printf("if you buy more than 100 units o, you have to pay, $%.2f per unit\n", cost*(1-0.05) ); System.out.printf("If you buy more than 500, you have to pay, $%.2f per unit\\n", cost (1-0.15) //This applies a 15% discount System.out.printf("If you buy more than 100 units, you have to pay, $%.2f per unit\\n",cost * (1-0.25) )://This 1/25% off //out when the if else statement executes } else if (units > 500 | units < 1500) { cost *=(1-0.15);
System.out.printf("Buying more than 1500 units, means that you have to pay $%.2f per unit\n", cost * (1-0.25) ); } else { cost *= (.75); } if (purchaseCents - (int) purchaseCents >= 0.5) { cents = (int) purchaseCents ++; } else { cents = (int) purchaseCents; } System.out.printf("Your payment is %d dollars %d cents\n", dollar, cents); } public int units() { return units; }
I/Z product public class zProduct { final boolean occSale; double cost; int units; double fullCost-cost*units; public zProduct(double cost,int units, boolean occSale) { this.cost =cost; this.occSale = occSale: this.units = units;} public double getCost() { return cost;} public void setCost(double cost) { this.cost =cost :} public double getfullCost() { return fullCost;} // z item cost is calc public void display() { double output;
if (occSale) { units = units- units/3; } output = cost units; int dollar (int) output; double purchaseCents = (output - dollar)* 100; int cents; if (purchaseCents - (int) 0.5<=purchaseCents) { cents = (int) purchaseCents++;: } else { cents (int) purchaseCents; } System.out.printf("your total is %d dollars %d cents\n", dollar, cents); } 1 public int getunits() { return units; } public void setunits(int units) { this.units units; }}
if (occSale) { units = units- units/3; } output = cost units; int dollar (int) output; double purchaseCents = (output - dollar)* 100; int cents; if (purchaseCents - (int) 0.5<=purchaseCents) { cents = (int) purchaseCents++;: } else { cents (int) purchaseCents; } System.out.printf("your total is %d dollars %d cents\n", dollar, cents); } 1 public int getunits() { return units; } public void setunits(int units) { this.units units; }}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply