Question

Java programming Who could help me to solve that, couldn't figure it out. Thanks in advance.The shop sell 5 things w...

Java programming

Who could help me to solve that, couldn't figure it out. Thanks in advance.The shop sell 5 things with the price below:

1.6$

2.8$

3.12$

4.3$

5.9$

Input the order number and count the sum of products. if print -1 stop the execution.Ex: Input 1 2 4 5 -1 Output 26. Need to use switch

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class SumOfProducts {

      public static void main(String[] args) {

            // TODO Auto-generated method stub

            //Scanner function to get the input from keyboard

            Scanner scan = new Scanner(System.in);

            //Asking the user to input order number

            System.out.print("Enter the order #: ");

            int total=0;

            int order=scan.nextInt();

            //Total is calculated if and only if the order is not -1

            while(order!=-1){

                  //Using Switch as per your requirement

                  switch (order){

                  //Calculating the Sum of products as per the input given by user

                  case 1: total = total+6; break;

                  case 2: total = total+8; break;

                  case 3: total = total+12; break;

                  case 4: total = total+3; break;

                  case 5: total = total+9; break;

                  // If User gives any number other than 1,2,3,4,5,-1 It is considered as invalid

                  default: System.out.println("Invald entry give again"); break;

                  }

                  System.out.print("Enter the order: ");

                  order = scan.nextInt();

            }

            //Printing the Sum of Products

            System.out.println("Sum of Products: "+total+"$");

      }

}

Output:

<terminated> SumOfProducts [Java Enter the order: Enter the order: Enter the order: 4 Enter the order: 5 Enter the order: -1

Add a comment
Know the answer?
Add Answer to:
Java programming Who could help me to solve that, couldn't figure it out. Thanks in advance.The shop sell 5 things w...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Programming: Who could help me to solve that, couldn't figure it out. Thnx in advance.The shop sell 5 things with...

    C Programming: Who could help me to solve that, couldn't figure it out. Thnx in advance.The shop sell 5 things with the price below: 1.6$ 2.8$ 3.12$ 4.3$ 5.9$ Input the order number and count the sum of products. if print -1 stop the execution.Ex: Input 1 2 4 5 -1 Output 26. Need to use switch

  • Java programming help My program wont run. could someone tell me why. everything seems correct to...

    Java programming help My program wont run. could someone tell me why. everything seems correct to me... giving me the error: Exception in thread "main" java.lang.NumberFormatException: For input string: "Stud" at java.base/java.lang.NumberFormatException.forInputString(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at Util.readFile(Util.java:35) at Driver.main(Driver.java:8) _________________________________________________________________________________________________________________________ Program Prompt: Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit...

  • Can some help me with my code I'm not sure why its not working. Thanks In...

    Can some help me with my code I'm not sure why its not working. Thanks In this exercise, you are to modify the Classify Numbers programming example in this chapter. As written, the program inputs the data from the standard input device (keyboard) and outputs the results on the standard output device (screen). The program can process only 20 numbers. Rewrite the program to incorporate the following requirements: a. Data to the program is input from a file of an...

  • Please help me to answer the 5 programming questions and give some specific explanations, thanks a...

    Please help me to answer the 5 programming questions and give some specific explanations, thanks a lot !!! Question Consider a class hierarchy that includes a class called Creature, with subclasses called Unicorn and Dragon. The Creature class has a method called feelsLike, Not yet answered which is overridden in the Unicorn and Dragon class. Marked out of The feelsLike method of the Creature class returns "smooth", while the feelsLike method is overridden in the Unicorn class to return "fluffy"...

  • Please help me code the following in: JAVA Please create the code in as basic way...

    Please help me code the following in: JAVA Please create the code in as basic way as possible, so I can understand it better :) Full points will be awarded, thanks in advance! Program Description Write a program that demonstrates the skills we've learned throughout this quarter. This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can...

  • Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in...

    Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1)        a.) [1, 2, 2, 2]        b.) [1, 1, 1, 2]        c.) [1, 2, 1, 2]        d.) [1,...

  • This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static...

    This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in);    TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice;    do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT