Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java 1 The Assignment This program will display a menu to the user from which th

ID: 3858772 • Letter: J

Question

Java 1

The Assignment

This program will display a menu to the user from which they can choose an option for the sale of one of three products.
Once the menu selection is made, the user will be prompted for the quantity of the product that is being purchased.
When the quantity has been entered, the program will look up the price of the item. If three or more items of the same type are purchased, a 5% discount will given on the purchase of that item.
A tally of total sales are kept as the program and can be viewed from a menu option.

2.1. Specifications

Use two separate files with a single class in each one (there could actually be more classes, but two will keep it more manageable).

Name the first file (and class) ProductsSold. This is the one that will have all of the methods other than the main method.

Name the second file TestProductsSold. This file will contain the class that has the main method and the logic which controls the program.

There are three products that are sold from the menu: Widget1, Widget2, and Widget3.

There will be a menu option for each of these items plus options to view sales totals and to exit. On the option to exit, use the System.exit(0) statement.

Use methods to accomplish each of the necessary tasks. For instance, you will need a method to calculate the sales tax, a tally method for each of the three products, a method to look up the price of the product, a method to calculate the discount, a method to display the total sales for all of the products, and a method to display the menu. You may need others as well, depending upon the logic.

Use getters and setters where necessary.

The logic flow will be something like the following:

The user makes a selection from the menu to sell one of the three products.

The user will then be prompted for the quantity of that item.

The program will look up the sales price of that item.

The program will calculate the total sale of the item.

If three or more of those items were purchased, the program will calculate a discount and give the 5% discount.

The tally for the total sales for that item will be updated for this item.

At any time, the user can take the option to display the total sales for each of the three products.

2.2. Output Format

There are several ways in which this program could be written. However, in order to grade for following specifications and to have a clear path to a solution, it is required that you write your program using the specifications below.

Explanation / Answer

The required code is as follows. I tried to keep it as simple as I can and hope that I have succeeded in it. Hope you'll understand the code.So here comes the code:

Cust.java

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

public class Cust {

public int id;

String name;

int phoneNo;

ArrayList<prod> al=new ArrayList<prod>();

public void BookedProd(prod object){

object.setprodStat("unavailable");

al.add(object);

}

public int getID() {

return id;

}

public void setID(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getNo() {

return phoneNo;

}

public void setNo(int phoneNo) {

this.phoneNo = phoneNo;

}

public Cust(int id, String name, int phoneNo) {

super();

this.id = id;

this.name = name;

this.phoneNo = phoneNo;

}

}

class prod {

public int prodID;

String prodName;

double prodPc;

String prodStat="available";

public String getProductStatus(String repo) {

return prodStat;

}

public void setprodStat(String prodStat) {

this.prodStat = prodStat;

}

public int quant;

public int getQuant() {

return quant;

}

public void setQuant(int quant) {

this.quant = quant;

}

public int getProdID() {

return prodID;

}

public void setProdID(int prodID) {

this.prodID = prodID;

}

public String getProdName() {

return prodName;

}

public void setProdName(String prodName) {

this.prodName = prodName;

}

public double getProdPc() {

return prodPc;

}

public void setProdPc(double prodPc) {

this.prodPc = prodPc;

}

public prod(int prodID, String prodName, double prodPc) {

super();

this.prodID = prodID;

this.prodName = prodName;

this.prodPc = prodPc;

}

}

Store.java

import java.io.*;

import java.util.ArrayList;

import java.util.Scanner;

public class Store {

String streNm;

ArrayList<Cust> alList=new ArrayList<Cust>();

ArrayList<prod> prodLst=new ArrayList<prod>();

public int genCustID()

{

int cnt=0;

int custId=0;

if(alList.size()==0)

custId=1;

else

{

for(Cust cust:alList)

{

cnt++;

if(cnt==alList.size())

{

custId=cust.getID()+1;

break;

}

}

}

return custId;

}

public int genProdID()

{

int cnt=0;

int prodId=0;

if(prodLst.size()==0)

prodId=1;

else

{

for(prod prod:prodLst)

{

cnt++;

if(cnt==prodLst.size())

{

prodId=prod.getProdID()+1;

break;

}

}

}

return prodId;

}

public void newCust(String name,int cntctNo)

{

int custId=genCustID();

Cust cst=new Cust(custId,name,cntctNo);

alList.add(cst);

}

public void addProduct(String name,String repo,double cost)

{

int proId=genProdID();

prod pd=new prod(proId, name,cost);

pd.getProductStatus(repo);

prodLst.add(pd);

}

public int chckProdAvail(String prodNmme)

{

int cnt=0;

for(prod prod:prodLst)

if((prod.getProdName().equals(prodNmme)) && (prod.getProductStatus(null).equals("Available")))

{cnt++;}

if(cnt>0)

{System.out.println("available");}

return cnt;

}

public String getStNme() {

return streNm;

}

public void setStNme(String streNm) {

this.streNm = streNm;

}

public Store(String streNm) {

super();

this.streNm = streNm;

}

public void print() {

for(Cust cust:alList){

System.out.println("Name: " +cust.getName()+" Number : "+cust.getNo()+" ID: "+cust.getID());

}

for(prod pd:prodLst){

System.out.println("Pd Name : "+pd.getProdName()+"Price : "+pd.getProdPc()+ " P ID : "+pd.getProdID()+" repo :"+pd.getProductStatus( null ));

}

}

public int bookProduct(int custID,String prodNmme, int quantity)

{

int availl=-1;

int cnt1=0;

int cnt2=0;

availl=chckProdAvail(prodNmme);

int cnt3=availl;

int cnt4=quantity;

loop: for(Cust cust:alList)

{

cnt1++;

if(cust.getID()==custID)

{

for(prod prod:prodLst)

{

cnt2++;

if(prod.getProdName().equals(prodNmme))

{

if(availl<=quantity)

{cust.BookedProd(prod);

cnt3--;

if(cnt3==0)

break loop;

}

if(availl>quantity)

{availl=quantity;

cust.BookedProd(prod);

cnt4--;

if(cnt4==0)

break loop;}

}

else if(cnt2==prodLst.size())

{availl=0;break loop;}

}

}

else if(cnt1==alList.size())

{availl=-1;break loop;}

}

return availl;

}

public double calcAmt(int id, double disc)

{

double cost=0;

for(Cust cust:alList)

if(cust.getID()==id)

{

ArrayList<prod> prodList1=cust.al;

for(prod pd:prodList1)

{cost+=pd.getProdPc();

}

break;

}

cost=cost-(cost*disc);

System.out.println("the amount is "+ cost);

return cost;

}

}

ShopeRem.java

public class shopRem {

public static void main(String[] args) throws IOException {

BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));

Store st=new Store("Spencer");

int empppID=0;

String empNAMe="",ast="";

int num;

int choice;

do

{

System.out.println(" Enter the choice:");

System.out.println(" 1.to add Cust 2.add prod 3.check prod availability 4.print 5.book prod 6.calculate net amount 7.Exit");

choice=Integer.parseInt(buff.readLine());

switch(choice)

{

case 1: System.out.println("------Cust Addition-------");

System.out.println("Enter the name of Cust:");

empNAMe=buff.readLine();

System.out.println("enter the contact num");

num=Integer.parseInt(buff.readLine());

st.newCust(empNAMe,num);

break;

case 2: System.out.println("------prod Addition-------");

System.out.println("Enter prod name:");

empNAMe=buff.readLine();

System.out.println("Enter the cost of prod:");

double cost=Double.parseDouble(buff.readLine());

System.out.println("enter the repo");

ast=buff.readLine();

st.addProduct(empNAMe,ast, cost);

break;

case 3: System.out.println("------check Availability-------");

System.out.println("Enter the prod name:");

empNAMe=buff.readLine();

int num=st.chckProdAvail(empNAMe);

System.out.println("available prod="+num);

break;

case 4: System.out.println("------Display-------");

st.print();

break;

case 5: System.out.println("------booked Product-------");

System.out.println("Enter the Cust id:");

empppID=Integer.parseInt(buff.readLine());

System.out.println("enter the prod name");

empNAMe=buff.readLine();

System.out.println("Enter the num of products:");

num=Integer.parseInt(buff.readLine());

st.bookProduct(empppID, empNAMe, num);

break;

case 6: System.out.println("------calculate cost-------");

System.out.println("Enter the Cust id:");

empppID=Integer.parseInt(buff.readLine());

System.out.println("Enter the disc:");

double disc=Double.parseDouble(buff.readLine());

double cost=st.calcAmt(empppID, disc);

System.out.println("Total cost="+cost);

break;

case 7: System.out.println("Sorry");

break;

default:System.out.println("Invalid selection!!");

}

}while(choice!=7);

}

}

Please rate the answer if it helped......Thankyou

Hope it helps......

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote