The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
rahulbansal,
Yesterday you helped me with a java programming issue. Initially, when I compiled and ran the code everything looked great. However, what I noticed after I accepted your response I was missing the summary totals after each entry. The final calculation display is perfect, but what I need is for a summary output following each entry before exiting, which gives the final total.
What I should see is a running summary after entering each product # and quantity, like below:
Enter Product No. (1-5) -1 to Quit:
Product   Quantity  LineCost  TotalCost
1Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2.98Â Â Â Â Â Â Â Â Â 2.98
2Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2Â Â Â Â Â Â Â Â Â Â Â Â Â Â 9.0Â Â Â Â Â Â Â Â Â Â Â 11.98
Â
This is perfect at the end so this should stay the same:
Product   Quantity  LineCost  TotalCost
1Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2.98Â Â Â Â Â Â Â Â Â 2.98
2Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 9.0Â Â Â Â Â Â Â Â Â Â 11.98
3Â Â Â Â Â Â Â Â Â Â Â Â Â Â 3Â Â Â Â Â Â Â Â Â Â Â Â Â Â 29.94Â Â Â Â Â Â Â 41.92
4Â Â Â Â Â Â Â Â Â Â Â Â Â Â 4Â Â Â Â Â Â Â Â Â Â Â Â Â Â 17.96Â Â Â Â Â Â 59.88
5Â Â Â Â Â Â Â Â Â Â Â Â Â Â 5Â Â Â Â Â Â Â Â Â Â Â Â Â Â 34.35Â Â Â Â Â Â 94.23
Total price of items is $94.23
My question is can you add the missing summary total? If so, will there be a charge? Thank you.
Mike
Â
/** 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 program4;import java.util.Scanner;//import the scanner class/**** @author*/public class Program4{public static void main(String[] args) {//declare productNo and quantity variablesint prodNo;int quantity;double total = 0;//set up a String for your output via the Scanner classScanner outString = new Scanner("ProductQuantityLineCostTotalCost\n");Scanner input = new Scanner(System.in);StringBuilder str = new StringBuilder();//begin loopdo {//if (prodNo >= 1 && prodNo <= 5)System.out.print("Enter Product No. (1-5) -1 to Quit: ");prodNo = input.nextInt();if(prodNo == -1) //Break out of loop if -1 enteredbreak;str.append(prodNo+"\t\t\t");System.out.print("Enter Quantity or -1 to Quit: ");quantity = input.nextInt();str.append(quantity+"\t\t\t");switch(prodNo){case 1:total += quantity * 2.98;str.append(quantity*2.98+"\t\t\t");break;case 2:total += quantity * 4.50;str.append(quantity*4.50+"\t\t\t");break;case 3:total += quantity * 9.98;