Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Java Programming) so this the program I wrote last week public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println(What type of gas?);

(Java Programming)

so this the program I wrote last week

public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println("What type of gas?"); System.out.println("(R)egular: $2.19"); System.out.println("(P)lus: $2.49"); System.out.println("(S)uper: $2.71"); System.out.println("(U)ltra: $2.99"); char option = keyboard.next().charAt(0); double rate ; if (option == 'R') rate =2.19; else if (option == 'P') rate = 2.49; else if (option == 'S') rate = 2.71; else rate = 2.99; System.out.println("How many gallons?"); double gallons = keyboard.nextDouble(); System.out.println("You owe :" + rate*gallons); } }

Now i just want to replace the if statement with switch statement

Modify the program you wrote last week by removing the if statement and replacing it with a switch statement. The execution of the program will be the same, the only change will be the decision structure.

If your program had the user entering numbers, you can switch based on numbers. If your program had the user entering letters, you can switch on characters. You can decide whether to let the user enter either upper-case and lower-case letters or require them to enter only upper-case or only lower-case. Although Java now allows it, please dont switch based on strings.

Format the dollar amounts properly using printf. The dollar amounts should have two numbers after the decimal point.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 11th International Symposium Sstd 2009 Aalborg Denmark July 8 10 2009 Proceedings Lncs 5644

Authors: Nikos Mamoulis ,Thomas Seidl ,Kristian Torp ,Ira Assent

2009th Edition

3642029817, 978-3642029813

More Books

Students also viewed these Databases questions