assignment2

 avatar
chamanEiqbal
java
a year ago
4.0 kB
8
Indexable
Never
package assignment2;

import java.util.ArrayList;
import java.util.Scanner;

public class Bill {
    
    static int bItems = 0;
        static String name;
        static float price;
        static float quantity;
        static float discount;
        
        // arraylists? 
        
        static ArrayList<String> nameList = new ArrayList<>();
        static ArrayList<Float> priceList = new ArrayList<>();
        static ArrayList<Float> quantityList = new ArrayList<>();
        static ArrayList<Float> discountList = new ArrayList<>();
        
    public static void takeInputParts() {

                
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter part's name: ");
        name = sc.nextLine();
        System.out.println("Enter price of the part");
        price = sc.nextFloat();
        System.out.println("Enter quantity: ");
        quantity = sc.nextFloat();
        System.out.println("Enter discount if any");
        discount = sc.nextFloat();
        
         bItems++;
    }
    
    public static void setBill(Parts p) {  
        nameList.add(p.getName());
        priceList.add(p.getPrice());
        quantityList.add(p.getQuantity());
        discountList.add(p.getDiscount());
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String cont;
        do {
         takeInputParts();
          setBill(new Parts(name, price, quantity, discount));
            System.out.println("Continue?");
            cont = sc.next();
       }while(cont.equalsIgnoreCase("yes"));
        
        for(int i = 0; i < bItems; i++) {
            System.out.println(nameList.get(i));
        }
        
        float f = (float) 66.5;
        float f2 = (float) 666.5;
        
        System.out.printf("Price: %8.3f \n", f);
        System.out.printf("Price: %8.3f \n", f2);
    }
}

///////////////////////////////////////////////////////

package assignment2;

/**
 *
 * @author HP
 */
public class DescriptionDetails {
    private float price;
    private float quantity;
    private float discount;
    
    
    public DescriptionDetails(float price, float quantity, float discount) {
        this.price = price;
        this.quantity = quantity;
        this.discount = discount;
    }
    
    public void setPrice(float price) {this.price = price;}
    public void setQuantity(float quantity) {this.quantity = quantity;}
    public void setDiscount(float discount) {this.discount = discount;}
   
 private final float  total = (quantity * price) - discount;
 
 public float getPrice() {return price;}
 public float getQuantity(){return quantity;}
 public float getDiscount() {return discount;}
 public float getTotal() {return total;}
   
}

/////////////////////////////////////////////////

/*
 * 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(String name, float price, float quantity, float discount) {
        super(price, quantity, discount);
        this.name = name;
    }

    
    //setters getters
    
    public void setName(String name) {this.name = name;}
    public String getName() {return name;}
    
}

//////////////////////////////////////

package assignment2;

/**
 *
 * @author HP
 */
public class Parts extends DescriptionDetails {
    private String name;

    public Parts(String name, float price, float quantity, float discount) {
        super(price, quantity, discount);
        this.name = name;
    }
    
    // setters getters:
    
    public void setName(String name) {this.name = name;}
    public String getName() {return name;}
    
}