Question: 7.3: The Price is Right Write a program that reads in a price as a String, and then outputs the price in dollars and cents.

7.3: The Price is Right

  • Write a program that reads in a price as a String, and then outputs the price in dollars and cents.
  • Name your project PriceRight and create a class called PriceRight.java
  • For this program, you can assume that the user will enter in a price in either 10s or 100s of dollars. The price will never go above 999.99 or below 10.00.
  • Hint: read in the price as a String
  • Hint 2: Use the String methods (length and charAt) to calculate the length of the String and then break the String into dollars and cents.
  • Hint 3: You will need one if and one else statement to solve this problem
  • Your program should work identically to the example below:
Enter the price: 12.95 12 dollars and 95 cents. 
  • Alternately:
Enter the price: 174.35 174 dollars and 35 cents. 
  • When your program gives the same output as above (except the user may give different input).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!