Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in Java that asks a user for the number of bags of chips they ar

ID: 670078 • Letter: W

Question

Write a program in Java that asks a user for the number of bags of chips they are buying and reads the answer.
It then asks how many pounds of spinach they are buying and reads that number. It should be able to handle a value like 0.45.

It then asks and reads how many dozen eggs they are buying.
Finally it should ask for the customer's name.

Use constants for the prices:

bag of chips: 3.49

pound of spinach: 2.99

dozen eggs: 1.89

The program should print a neat bill, greating the customer by name; for each item, print the unit price, how much was purchased, and the net price. Finally it should print the amount due.

Explanation / Answer

package mani;

import java.util.Scanner;

public class bill {
public static void main(String[] args){
   Scanner s=new Scanner(System.in);
   final double Chips=3.49;
   final double Sp=2.99;
   final double eg=3.49;
   System.out.println("Enter how many pounds of spinach: ");
   double sP=s.nextDouble();
   System.out.println("Enter how many dozens of eggs: ");
   double eP=s.nextDouble();
   System.out.println("Enter how many bag of chips: ");
   int sC=s.nextInt();
   System.out.println("Enter name of customer: ");
   String name=s.next();
   double tsP=sP*Sp;
   double teP=eg*eP;
   double tsC=sC*Chips;
   double netprice=sP+eP+sC;
   System.out.println("*******Total Bill*******");
   System.out.println("Customer Name: "+name);
   System.out.println("item Quantity cost");
   System.out.println("bag of Chips "+sC+" "+tsC);
   System.out.println("pound of Spinach "+sP+" "+tsP);
   System.out.println("dozen eggs "+eP+" "+teP);
   System.out.println("-------------------------------------");
   System.out.println("Total Bill amount: "+netprice);
}
  
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote