main clss
unknown
java
2 years ago
4.3 kB
5
Indexable
package assigment; import java.util.ArrayList; import java.util.Scanner; public class Bill { public static void setBill(Parts p,ArrayList<Parts> partList) { Scanner sc = new Scanner(System.in); System.out.println("Enter Part Name:"); p.setName(sc.nextLine()); System.out.println("Enter quantity: "); p.setQuantity(sc.nextFloat()); System.out.println("Enter unit price"); p.setUnitPrice(sc.nextFloat()); System.out.println("Enter discount: "); p.setDiscount(sc.nextFloat()); partList.add(p); } public static void setBill(Labour l, ArrayList<Labour> labourList) { Scanner sc = new Scanner(System.in); System.out.println("Enter Name"); l.setName(sc.nextLine()); System.out.println("Enter Quantity"); l.setQuantity(sc.nextFloat()); System.out.println("Enter Unit Price"); l.setUnitPrice(sc.nextFloat()); labourList.add(l); } public static void setCustomer(Customer c) { Scanner sc = new Scanner(System.in); System.out.println("Enter name"); c.setName(sc.nextLine()); System.out.println("Enter contact no."); c.setContact(sc.next()); System.out.println("Enter vehicle No"); String vehNo = sc.next(); System.out.println("Enter vehicle model"); String vehModel = sc.nextLine(); c.setVeh(new Vehicle(vehNo,vehModel)); } public static void printReceipt(Customer customer, ArrayList<Parts> partList, ArrayList<Labour> labourList) { System.out.println("====================================================================="); System.out.printf("%50s","MUTAHHAR AUTO PARTS SERVICE"); System.out.println("====================================================================="); System.out.printf("Customer Name: %-40s",customer.getName()); System.out.printf("%45s %s\n","Vehicle No.", customer.getVehicle().getvehNo()); System.out.printf("Customer Contact No: %-40s",customer.getContactNo()); System.out.printf("%45s %s","Vehicle Model", customer.getVehicle().getvehModel()); System.out.println("---------------------------------------------------------------------"); System.out.printf("%50s","BILL DESCRIPTION"); System.out.println("---------------------------------------------------------------------"); System.out.printf("%-20s%-40s%-20s%-20s%-20s%-20s","Type","Description","Quantity","Unit Price","Discount","Total"); float partsTotal = 0.0f; float labourTotal = 0.0f; for(Parts p: partList) { float totPart = (p.getQuantity() * p.getUnitPrice()) - p.getDiscount(); partsTotal += totPart; System.out.printf("%-20.2s%-40s%-20.2f%-20.2f%-20.2f%-20.2f","Parts",p.getName(),p.getQuantity(),p.getUnitPrice(),p.getDiscount(),totPart); } for(Labour l: labourList) { float totLabour = (l.getQuantity() * l.getUnitPrice()); labourTotal += totLabour; System.out.printf("%-20.2s%-40s%-20.2f%-20.2f%-20.2s%-20.2f","Parts",l.getName(),l.getQuantity(),l.getUnitPrice(),"-",totLabour); } float netTotal = partsTotal + labourTotal; System.out.println("==================================================================="); System.out.printf("%-80s%20.5f","Parts Total: ",partsTotal); System.out.printf("%-80s%20.5f","Services Parts (5%): ",(partsTotal*0.05)); System.out.printf("%-80s%20.5f","Labour Total: ",labourTotal); System.out.printf("%-80s%20.5f"," Grand Total: ", netTotal + (partsTotal * 0.05)); System.out.println("==================================================================="); } public static void main(String[] args) { ArrayList<Parts> partList = new ArrayList<>(); ArrayList<Labour> labourList = new ArrayList<>(); Customer c = new Customer(); Parts p = new Parts(); Labour l = new Labour(); Scanner sc = new Scanner(System.in); String cont; setCustomer(c); do { setBill(p,partList); System.out.println("do you want continue y/n?"); cont = sc.next(); }while(cont.equalsIgnoreCase("YES")||cont.startsWith("y")); do { setBill(l,labourList); System.out.println("do you want to continue y/n"); cont = sc.next(); }while(cont.equalsIgnoreCase("YES") || cont.startsWith("y")); printReceipt(c,partList,labourList); } }
Editor is loading...