ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 29 May 2017 My Price 9.00

ProductQuantityLineCostTotalCost

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;

Answers

(11)
Status NEW Posted 29 May 2017 07:05 AM My Price 9.00

-----------

Not Rated(0)