-2

I'm unsure what needs to be done so the output from the "Purchase Summary" would show the "Petrol Type". Any help is appreciated.

Update: Full code. The "String type = input.nextLine();" for Petrol Type does not seem to register in the Purchase Summary when being ran through. I'm not sure what's the issue in it.


class PetrolPurchase  
{
    private String station;
    private double quant;
    private String type;
    private double price;
    private int discount;
    
    public String getstation () {return station;}
    public double getquant () {return quant;}
    public String gettype () {return type;}
    public double getprice () {return price;}
    public int getdiscount () {return discount;}
    
    public void setstation (String otherstation) {station = otherstation;}
    public void setquant (double otherquant) {quant = otherquant;}
    public void settype (String othertype) {type = othertype;}
    public void setprice (double otherprice) {price = otherprice;}
    public void setdiscount (int otherdiscount) {discount = otherdiscount;}
    
        
}

class PurchaseSummary 
{ public static void main (String [ ] args)
    {       
Scanner input = new Scanner (System.in); 

        PetrolPurchase pp = new PetrolPurchase  ();
        
        System.out.printf ("Enter Station:");
        String station = input.nextLine();
        pp.setstation (station);
        
        System.out.printf("Enter Quantity (Liter):");
        double quant = input.nextDouble();
        pp.setquant (quant);
        
        System.out.printf ("Enter Petrol Type:");
        String type = input.nextLine();
        pp.settype (type);
        input.nextLine();
        
        System.out.printf ("Enter the Petrol Price:");
        double price = input.nextDouble();
        pp.setprice (price);
        
        System.out.printf("Enter the discount (no decimal):");
        int discount = input.nextInt();
        pp.setdiscount (discount); 
        
        double truecost = quant * price;
        double dcost = discount*0.01*truecost;
        double pay = truecost - dcost;
        
        
        System.out.printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%n");
        System.out.printf("Purchase Summary:%n");
        System.out.printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%n");
        System.out.printf ("Station: %s%n", station);
        System.out.printf ("Total Petrol Liter: %s%n", pp.getquant ());
        System.out.printf ("Petrol Type: %s%n", pp.gettype());
        System.out.printf ("Price Per Liter: = %.2f%n", pp.getprice ());
        System.out.printf ("Actual Cost = %.2f%n", truecost);
        System.out.printf ("Discounted Amount %s", discount);
        System.out.printf ("%% is: %-8.5s", dcost);
        System.out.printf ("%nAmount for Payment = %.2f%n", pay);

Output

Max
  • 23
  • 4

1 Answers1

0

Try putting the input.nextLine(); before type=input.nextLine();