Untitled
chamanEiqbal
java
3 years ago
7.6 kB
9
Indexable
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment2;
/**
*
* @author HP
*/
public class Labour extends DescriptionDetails {
private String name;
public Labour() {
//default contsructor
}
public Labour(String name, float price, float quantity) {
super(price, quantity);
this.name = name;
}
//setters getters
public void setName(String name) {this.name = name;}
public String getName() {return name;}
}
// BILL CLASS::
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment2;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author HP
*/
public class Bill {
// Bill Items ArrayLists
static int bItems = 0;
static int LabourItems = 0;
static int PartsItems = 0;
static ArrayList<String> typeList = new ArrayList<>();
static ArrayList<String> nameList = new ArrayList<>();
static ArrayList<Float> priceList = new ArrayList<>();
static ArrayList<Float> quantityList = new ArrayList<>();
static ArrayList<Float> discountList = new ArrayList<>();
/*
------------------
Methods of Taking Information and Setting the information to Bill Item ArrayLists:
------------------*/
public static void takeInput(Parts p) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter part's name: ");
p.setName(sc.nextLine());
System.out.println("Enter price of the part");
p.setPrice(sc.nextFloat());
System.out.println("Enter quantity: ");
p.setQuantity(sc.nextFloat());
System.out.println("Enter discount if any");
p.setDiscount(sc.nextFloat());
bItems++;
PartsItems++;
}
public static void setBill(Parts p) {
typeList.add("Parts");
nameList.add(p.getName());
priceList.add(p.getPrice());
quantityList.add(p.getQuantity());
discountList.add(p.getDiscount());
}
public static void takeInput(Labour l) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Labour Description: ");
l.setName(sc.nextLine());
System.out.println("Enter price of the labour: ");
l.setPrice(Float.parseFloat(sc.nextLine()));
System.out.println("Enter quantity of labour: ");
l.setQuantity(Float.parseFloat(sc.nextLine()));
bItems++;
LabourItems++;
}
public static void setBill(Labour l) {
typeList.add("Labour");
nameList.add(l.getName());
priceList.add(l.getPrice());
quantityList.add(l.getQuantity());
}
public static void setCustomer(Customer c) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter name of customer:");
c.setName(sc.nextLine());
System.out.println("Enter contact No. of customer");
c.setContactNo(sc.nextLine());
}
public static void setVeh(Vehicle v) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Vehicle No.");
v.setVehNo(sc.nextLine());
System.out.println("Enter Model: ");
v.setModel(sc.nextLine());
}
public static void printReceipt(Customer customer, Vehicle vehicle) {
System.out.println("\n\n\n");
System.out.println("******************************************************************************************************************");
System.out.printf("%75s","KARACHI AUTOSERVICES PVT. LTD.\n");
System.out.println("******************************************************************************************************************");
System.out.printf("Customer Name: %-40s", customer.getName());
System.out.printf("%40s\n", "Vehicle No.: " + vehicle.getVehNo());
System.out.printf("Contact No.: %-40s", customer.getContactNo());
System.out.printf("%40s\n", "Vehicle Model: " + vehicle.getModel());
System.out.println("******************************************************************************************************************");
System.out.printf("%65s", "BILL DESCRIPTION: \n");
System.out.println("******************************************************************************************************************");
System.out.printf("%-20s%-40s%-20s%-20s%-20s\n", "Type", "Name", "Price", "Quantity", "Discount");
System.out.println("------------------------------------------------------------------------------------------------------------------");
float totalAmount = 0.0f;
float totalPartsAmount = 0.0f;
float totalLabourAmount = 0.0f;
for(int i = 0; i < PartsItems; i++) {
float partsTotal = (priceList.get(i) * quantityList.get(i) - discountList.get(i));
totalPartsAmount += partsTotal;
}
for(int i = PartsItems; i < bItems; i++) {
float labourTotal = priceList.get(i) * quantityList.get(i);
totalLabourAmount += labourTotal;
}
for(int i=0;i<bItems;i++) {
if(typeList.get(i).equalsIgnoreCase("Labour")) {
System.out.printf("%-20s%-40s%15.2f%15.2f%15.2s\n", typeList.get(i), nameList.get(i), priceList.get(i), quantityList.get(i), "-");
}
else {
System.out.printf("%-20s%-40s%15.2f%15.2f%15.2f\n", typeList.get(i), nameList.get(i), priceList.get(i), quantityList.get(i), discountList.get(i));
}
}
totalAmount = totalPartsAmount + totalLabourAmount;
System.out.println("------------------------------------------------------------------------------------------------------------------");
System.out.printf("%-80s%20.2f\n", "Parts Total:", totalPartsAmount);
System.out.printf("%-80s%20.2f\n", "Service Tax (5%):", totalPartsAmount * 0.05);
System.out.printf("%-80s%20.2f\n", "Labour Total:", totalLabourAmount);
System.out.printf("%-80s%20.2f\n", "Grand Total:", totalAmount - (totalPartsAmount * 0.05));
System.out.println("******************************************************************************************************************");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String cont;
Customer customer = new Customer();
Vehicle veh = new Vehicle();
Parts parts = new Parts();
Labour labour = new Labour();
//setting customer and vehicle info
setCustomer(customer);
setVeh(veh);
customer.hasTheVeh(veh);
// taking parts input:
do {
takeInput(parts);
setBill(parts);
System.out.println("Continue?");
cont = sc.next();
}while(cont.equalsIgnoreCase("yes"));
// taking labour input:
do {
takeInput(labour);
setBill(labour);
System.out.println("Continue?");
cont = sc.next();
}while(cont.equalsIgnoreCase("yes"));
printReceipt(customer,veh);
}
}
Editor is loading...