new main class
chamanEiqbal
java
3 years ago
5.7 kB
16
Indexable
package assignment2;
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("\n\nEnter Part Name:");
p.setName(sc.nextLine());
System.out.println("Enter quantity: ");
p.setQuantity(sc.nextFloat());
System.out.println("Enter unit price");
p.setPrice(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("\n\nEnter Name");
l.setName(sc.nextLine());
System.out.println("Enter Quantity");
l.setQuantity(sc.nextFloat());
System.out.println("Enter Unit Price");
l.setPrice(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.setContactNo(sc.nextLine());
System.out.println("Enter vehicle No");
String vehNo = sc.nextLine();
System.out.println("Enter vehicle model");
String vehModel = sc.nextLine();
c.hasTheVeh(new Vehicle(vehNo, vehModel));
}
public static void printReceipt(Customer customer, ArrayList < Parts > partList, ArrayList < Labour > labourList) {
System.out.println("\n\n\n");
System.out.println("***********************************************************************************************************************************");
System.out.printf("%82s", "KARACHI AUTOSERVICES PVT. LTD.\n");
System.out.println("***********************************************************************************************************************************");
System.out.printf("Customer Name: %-40s", customer.getName()); // customername);
System.out.printf("%60s %s\n", "Vehicle No.: ", customer.getVehicle().getVehNo());
System.out.printf("Contact No.: %-40s", customer.getContactNo());
System.out.printf("%64s %s\n", "Vehicle Model: ", customer.getVehicle().getModel());
System.out.println("***********************************************************************************************************************************");
System.out.printf("%75s", "BILL DESCRIPTION: \n");
System.out.println("***********************************************************************************************************************************");
System.out.printf("%-20s%-40s%-20s%-20s%-20s%-20s\n", "Type", "Name", "Price", "Quantity", "Discount", "Total");
System.out.println("-----------------------------------------------------------------------------------------------------------------------------------");
float partsTotal = 0.0 f;
float labourTotal = 0.0 f;
for (int i = 0; i < partList.size(); i++) {
float totPart = (partList.get(i).getQuantity() * partList.get(i).getPrice()) - partList.get(i).getDiscount();
partsTotal += totPart;
System.out.printf("%-20s%-40s%15.2f%15.2f%15.2f%20.2f\n", "Parts", partList.get(i).getName(), partList.get(i).getPrice(), partList.get(i).getQuantity(), partList.get(i).getDiscount(), totPart);
}
for (int i = 0; i < labourList.size(); i++) {
float totLabour = (labourList.get(i).getQuantity() * labourList.get(i).getPrice());
labourTotal += totLabour;
System.out.printf("%-20s%-40s%15.2f%15.2f%15.2s%20.2f\n", "Labour", labourList.get(i).getName(), labourList.get(i).getPrice(), labourList.get(i).getQuantity(), "-", totLabour);
}
float netTotal = partsTotal + labourTotal;
System.out.println("-----------------------------------------------------------------------------------------------------------------------------------");
System.out.printf("%-80s%45.2f\n", "Parts Total:", partsTotal);
System.out.printf("%-80s%45.2f\n", "Service Tax (5%):", (partsTotal * 0.05));
System.out.printf("%-80s%45.2f\n", "Labour Total:", labourTotal);
System.out.printf("%-80s%45.2f\n", "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();
Scanner sc = new Scanner(System.in);
String cont;
setCustomer(c);
System.out.println("\n\nEnter parts INFO: ");
do {
Parts p = new Parts();
setBill(p, partList);
System.out.println("do you want continue y/n?");
cont = sc.next();
} while (cont.equalsIgnoreCase("YES") || cont.startsWith("y"));
System.out.println("\n\nEnter Labour INFO: ");
do {
Labour l = new Labour();
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...