Untitled

mail@pastecode.io avatar
unknown
java
a year ago
12 kB
4
Indexable
Never
package oopassignment2;
import java.util.Scanner;
import java.util.ArrayList;
public class Bill 
{
    private Customer customer;
    public Bill(Customer customer) {
        this.customer = customer;
    }
    
    public static void main(String[] args){
        Parts part=new Parts();
        Labour labour=new Labour();
        Scanner sc=new Scanner(System.in);
        Customer customer=null;
        
        boolean end=false;
        System.out.print("------------------------------------------KARACHI AUTO SERVICES PVT. LTD.-----------------------------------------");
        System.out.print("\nEnter Customer Name: ");
        String CustomerName=sc.nextLine();
        System.out.print("Enter Customer contact: ");
        String CustomerContact=sc.nextLine();
        System.out.print("Enter Vehicle Number: ");
        String VehicleNumber=sc.nextLine();
        System.out.print("Enter Vehicle Model: ");
        String VehicleModel=sc.nextLine();
        Vehicle vehicle=new Vehicle(VehicleNumber,VehicleModel);
        customer=new Customer(CustomerName,CustomerContact,vehicle);
        
        Bill bill=new Bill(customer);
        
        while (!end) {
            System.out.print("Enter 1 To Add Parts");
            System.out.print("\t\tEnter 2 To Add Labor");
            System.out.print("\t\tEnter 3 To Print Reciept");
            System.out.println();
            int choice=sc.nextInt();
            switch (choice) {
                case 1:
                    {
                        System.out.print("---------------------------------------------Inserting Parts Details----------------------------------------------");
                        System.out.print("\nEnter Parts Description:");
                        String description=sc.nextLine();
                        //String description="Fuel";
                        sc.nextLine();
                        System.out.print("\nEnter Parts Quantity:");
                        double quantity=sc.nextDouble();
                        System.out.print("Enter Parts Unit Price:");
                        double unitPrice=sc.nextDouble();
                        System.out.print("Enter Parts Discount if any:");
                        double discount=sc.nextDouble();
                        double total=(quantity*unitPrice)-discount;
                        String type="Parts";
                        Parts part1=new Parts();
                        part1.setUnitPrice(unitPrice);
                        part1.setDiscount(discount);
                        part1.setDescription(description);
                        part1.setQuantity(quantity);
                        part1.setType(type);
                        part1.setTotal(total);
                        part.addParts(part1);
                        break;
                    }
                case 2:
                    {
                        System.out.print("---------------------------------------------Inserting Labour Details----------------------------------------------");
                        System.out.print("\nEnter Labour Description:");
                        String description=sc.nextLine();
                        //String description="Advice Service";
                        sc.nextLine();
                        System.out.print("\nEnter Labour Quantity:");
                        double quantity=sc.nextDouble();
                        System.out.print("Enter Labour Unit Price:");
                        double unitPrice=sc.nextDouble();
                        double total=(quantity*unitPrice);
                        String type="Labour";
                        Labour labour1=new Labour();
                        labour1.setDescription(description);
                        labour1.setQuantity(quantity);
                        labour1.setTotal(total);
                        labour1.setType(type);
                        labour1.setUnitPrice(unitPrice);
                        labour.addLabour(labour1);
                        break;
                    }
                case 3:
                    System.out.print("Add Additional Repairs(if any): ");
                    double additionalRepair=sc.nextDouble();
                    double ptotal=0;
                    for (Parts p: part.partList) {
                        ptotal +=p.getTotal();
                    }
                    double ltotal=0;
                    for (Labour l:labour.labourList) {
                        ltotal += l.getTotal();
                    }
                    double serviceTax = 0.05 * (ptotal);
                    double grandTotal = ltotal+ ptotal +additionalRepair + serviceTax;
                    System.out.println("-------------------------------------------KARACHI AUTO SERVICES PVT. LTD.-------------------------------------------");
                    System.out.println("\n--------------------------------------------------Customer Details-------------------------------------------------");
                    
                    System.out.println("\n\tCustomer Name:"+customer.getCname()+"\t\t\t\t\t\tCustomer Contact:"+customer.getCcontact());
                    System.out.println("\n---------------------------------------------------Vehicle Details-------------------------------------------------");
                    System.out.println("\n\tVehicle Number:"+customer.vehicle.getVnumber()+"\t\t\t\t\t\tVehicle Model:"+customer.vehicle.getVmodel());
                    System.out.println("\n--------------------------------------------------Bill Description-------------------------------------------------");
                    System.out.println("\nType\t\tDescription\t\tQuantity\t\tUnit Price\t\tDiscount\t\tTotal");
                    for(Parts p: part.partList)
                    {
                        
                        System.out.println("\n"+p.getType()+"\t\t"+p.getDescription()+"\t\t\t"+p.getQuantity()+
                                "\t\t\t"+p.getUnitPrice()+"\t\t\t"+p.getDiscount()+"\t\t\t"+p.getTotal());
//                        System.out.println("Description:"+p.getDescription());
//                        System.out.println("Quantity:"+p.getQuantity());
//                        System.out.println("Unit Price:"+p.getUnitPrice());
//                        System.out.println("Discount:"+p.getDiscount());
//                        System.out.println("Total:"+p.getTotal());
                    }
                    for(Labour l:labour.labourList)
                    {
                        System.out.println("\n"+l.getType()+"\t\t"+l.getDescription()+"\t\t"+l.getQuantity()+
                                "\t\t\t"+l.getUnitPrice()+"\t\t\t--"+"\t\t\t"+l.getTotal());
//                        System.out.println("Type:"+l.getType());
//                        System.out.println("Description:"+l.getDescription());
//                        System.out.println("Quantity:"+l.getQuantity());
//                        System.out.println("Unit Price:"+l.getUnitPrice());
//                        System.out.println("Total:"+l.getTotal());
                    }  
                    System.out.println("\n-------------------------------------------------------------------------------------------------------------------");
//                  
                    System.out.println("Parts Total"+"\t\t\t\t"+"\t\t\t\t\t\t\t"+ptotal);
                    System.out.println("Service Tax (5%):"+"\t\t\t\t"+"\t\t\t\t\t\t"+serviceTax);
                    System.out.println("Labour Total:"+"\t\t\t\t"+"\t\t\t\t\t\t\t"+ltotal);
                    System.out.println("Additional Repair:"+"\t\t\t\t"+"\t\t\t\t\t\t"+additionalRepair);
                    System.out.println("Grand Total:"+"\t\t\t"+"\t\t\t\t\t\t\t\t"+grandTotal);
                    System.out.println("\n-------------------------------------------------------------------------------------------------------------------");
//                    bill.print(customer);
                    end=true;
                    break;
                default:
                    System.out.println("Invalid Input");
                    break;           
            }
//class 
package oopassignment2;

public class DescriptionDetail {
    private double total;
    private double unitPrice;
    private double quantity;
    private String type;
    private String description;


    public void setTotal(double total) {
        this.total = total;
    }

    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
    }

    public void setQuantity(double quantity) {
        this.quantity = quantity;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    
    public double getTotal() {
        return total;
    }

    public double getUnitPrice() {
        return unitPrice;
    }

    public double getQuantity() {
        return quantity;
    }

    public String getType() {
        return type;
    }

    public String getDescription() {
        return description;
    }
    
}
    

//class customer 
package oopassignment2;
import java.util.ArrayList;
public class Customer {
    Vehicle vehicle;
    private String Cname;
    private String Ccontact;

    public Customer(String Cname, String Ccontact,Vehicle vehicle) {
        this.Cname = Cname;
        this.Ccontact = Ccontact;
        this.vehicle=vehicle;
    }    
    
    public String getCname() 
    {
        return Cname;
    }

    public String getCcontact() 
    {
        return Ccontact;
    }
//    
//    public void addDetails(Customer c,Vehicle v){
//        
//    }
    public void Display()
    {
        System.out.println("---------------Customer Details---------------");
        System.out.println("Customer Name:"+Cname);
        System.out.println("Customer Contact:"+Ccontact);
        System.out.println("---------------Vehicle Details---------------");
        System.out.println("Vehicle Number:"+vehicle.getVnumber());
        System.out.println("Vehicle Model:"+vehicle.getVmodel());
        
    }
    
}
//class parts
package oopassignment2;
import java.util.ArrayList;
public class Parts extends DescriptionDetail
{
    ArrayList<Parts> partList;
    public Parts() {
         this.partList=new ArrayList<Parts>();
    }
    private double discount=0.0;
    public double getDiscount() {
        return discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }
    
    public void addParts(Parts abc){
        partList.add(abc);
    }
}
//class labour
package oopassignment2;
import java.util.ArrayList;
public class Labour extends DescriptionDetail{

    ArrayList<Labour>labourList;
    public Labour() {
        this.labourList=new ArrayList<Labour>();
    }
   public void addLabour(Labour abc) {
       labourList.add(abc);
    }

}
//vehicle
package oopassignment2;

public class Vehicle {
    private String Vnumber;
    private String Vmodel;
    public Vehicle(String Vnumber, String Vmodel) 
    {
        this.Vnumber = Vnumber;
        this.Vmodel = Vmodel;
    }

    public String getVnumber() 
    {
        return Vnumber;
    }

    public String getVmodel() 
    {
        return Vmodel;
    }
    
}

        }
    }
}