zainmomin PRINTED
chamanEiqbal
java
2 years ago
9.0 kB
7
Indexable
public class Bill3 { public static void main(String[] args) { int choice; part pobjlistgetter = new part(); labor laborobjlistgetter = new labor(); int choice2=6; Scanner sc = new Scanner(System.in); while(choice2==6){ System.out.println("Enter 1 for Customer details and Vehicle Details: "); System.out.println("Enter 2 for parts details"); System.out.println("Enter 3 for labor details"); System.out.println("Enter 4 for Output"); System.out.println("Enter 6 to Quit"); choice = sc.nextInt(); if (choice == 1) { String TempVehicleModel, TempVehicleNumber, TempCustomerName, TempCustomerNumber; sc.nextLine(); // consume the newline character left by the previous nextInt() call System.out.println("Enter Customer Name:"); TempCustomerName = sc.nextLine(); System.out.println("Enter Customer Number"); TempCustomerNumber = sc.nextLine(); System.out.println("Enter Vehicle Number"); TempVehicleNumber = sc.nextLine(); System.out.println("Enter Vehicle Model"); TempVehicleModel = sc.nextLine(); vehicle vh = new vehicle(TempVehicleModel, TempVehicleNumber); customer ct = new customer(TempCustomerName, TempCustomerNumber, vh); } else if (choice == 2) { String Description; float Quantity, Total; double Price, Discount; System.out.println("Enter Part Description: "); sc.nextLine(); // consume the newline character left by the previous nextInt() call Description = sc.nextLine(); System.out.println("Enter Part Quantity: "); Quantity = sc.nextFloat(); System.out.println("Enter Part Price: "); Price = sc.nextDouble(); System.out.println("Enter Part Discount: "); Discount = sc.nextDouble(); //Calculations and Object Creation String TypeOfPart = "Parts"; part pobj = new part(Discount); pobj.setDescription(Description); pobj.setType(TypeOfPart); Total =(Quantity*(float)(Price)-(float)Discount); pobj.setTotal(Total); pobj.setQuantity(Quantity); pobj.setPrice(Price); pobjlistgetter.assignparts(pobj); } else if (choice == 3) { String LaborDescription; float LaborTotal; int LaborQuantity; double LaborPrice; sc.nextLine(); // skipping nextInt System.out.println("Enter Labor Description: "); LaborDescription=sc.nextLine(); System.out.println("Enter Labor Quantity: "); LaborQuantity=sc.nextInt(); System.out.println("Enter Labor Price; "); LaborPrice=sc.nextDouble(); String LaborType="Labor"; LaborTotal=((float)(LaborQuantity*LaborPrice)); labor LB=new labor(); LB.setPrice(LaborPrice); LB.setTotal(LaborTotal); LB.setQuantity(LaborQuantity); LB.setType(LaborType); LB.setDescription(LaborDescription); laborobjlistgetter.assignlabor(LB); } else if (choice == 4) { System.out.println("DISPLAY"); // customer ct2=new customer(null,null,null); // ct2.display(); pobjlistgetter.Output(); laborobjlistgetter.LaborDisplay(); } else if(choice==6){ choice2=10; } } } } class vehicle { private String VehicleModel, VehicleNumber; public vehicle(String VehicleModel, String VehicleNumber) { this.VehicleModel = VehicleModel; this.VehicleNumber = VehicleNumber; } public String getVehicleModel() { return VehicleModel; } public void setVehicleModel(String VehicleModel) { this.VehicleModel = VehicleModel; } public String getVehicleNumber() { return VehicleNumber; } public void setVehicleNumber(String VehicleNumber) { this.VehicleNumber = VehicleNumber; } } class customer { private String CustomerName; private String CustomerNumber; private vehicle vh; private ArrayList <customer> CustomerDetails; private ArrayList <vehicle> VehicleDetails; public customer(String CustomerName, String CustomerNumber, vehicle vh) { this.CustomerName = CustomerName; this.CustomerNumber = CustomerNumber; this.vh = vh; } public String getCustomerName() { return CustomerName; } public void setCustomerName(String CustomerName) { this.CustomerName = CustomerName; } public String getCustomerNumber() { return CustomerNumber; } public void setCustomerNumber(String CustomerNumber) { this.CustomerNumber = CustomerNumber; } public vehicle getVehicle() { return vh; } public void setVehicle(vehicle vh) { this.vh = vh; } public void display() { System.out.println("-------------------------------\n"); System.out.println("Customer Name: " + getCustomerName() + "\n"); System.out.println("Customer Number: " + getCustomerNumber() + "\n"); System.out.println("Vehicle Number: " + vh.getVehicleNumber() + "\n"); System.out.println("Vehicle Model: " + vh.getVehicleModel() + "\n"); } } public class part extends description{ //child class private double Discount; ArrayList<part> SoldParts = new ArrayList<>(); //constructor public part() { //default } public part(double Discount){ this.Discount = Discount; } public double getDiscount() { return Discount; } public void setDiscount(double Discount) { this.Discount = Discount; } public void assignparts(part Obj) { SoldParts.add(Obj); } public ArrayList<part> getPartList(){return SoldParts;} public void Output() { System.out.println("----------------------------"); for(int i=0;i<SoldParts.size();i++){ System.out.println("Type: " + SoldParts.get(i).getType()); System.out.println("Quantity: " + SoldParts.get(i).getQuantity()); System.out.println("Price: " + SoldParts.get(i).getPrice()); System.out.println("Description: " + SoldParts.get(i).getDescription()); System.out.println("TotaL: " + SoldParts.get(i).getTotal()); } } } public class labor extends description { //child class ArrayList<labor> LaborDetails = new ArrayList<>(); public labor() { } public labor(String type, String desc, float quantity, float total, double price) { super(type,desc,quantity,total,price); } public void assignlabor(labor Obj){ LaborDetails.add(Obj); } public ArrayList<labor> getLaborList() {return LaborDetails;} public void LaborDisplay(){ System.out.println("---------------------------------------"); for(int i=0;i<LaborDetails.size();i++){ System.out.println("Type: " + LaborDetails.get(i).getType()); System.out.println("Quantity: " + LaborDetails.get(i).getQuantity()); System.out.println("Price: " + LaborDetails.get(i).getPrice()); System.out.println("Description: " + LaborDetails.get(i).getDescription()); System.out.println("Total: " + LaborDetails.get(i).getTotal()); } } } public class description { //parent class private String Type,Description; private float Quantity; private float Total; private Double Price; public description() { } public description(String type, String desc, float quantity, float total, double price) { Type = type; Description = desc; Quantity = quantity; Total = total; Price = price; } public String getType() { return Type; } //setter and getters public void setType(String Type) { this.Type = Type; } public String getDescription() { return Description; } public void setDescription(String Description) { this.Description = Description; } public float getQuantity() { return Quantity; } public void setQuantity(float quantity) { this.Quantity = Quantity; } public float getTotal() { return Total; } public void setTotal(float Total) { this.Total = Total; } public Double getPrice() { return Price; } public void setPrice(Double Price) { this.Price = Price; } }
Editor is loading...