Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVA Write a program named ShowMeTheMoneyNoPrintfNoIF that prompts the user t

ID: 3729679 • Letter: I

Question

IN JAVA

Write a program named ShowMeTheMoneyNoPrintfNoIF that prompts the user to enter the price of an item (in cents) and the number of items purchased. The program prints the total cost in standard dollars-and-cents format. So, if the user types in 395 and 7 the output will be $27.65 The prompt should be exactly this: "Please type the item price in cents and then the number of items purchased. Then hit RETURN.". Here are several sample interactive sessions.

CONSTRAINT: Nowhere in the program is an if statement or a printf used.

REMINDER: the program's prompt and output are shown here in bold; the user's data entry is shown here in italics.

Sample Interactive Run 1:

Please type the item price in cents and then the number of items purchased. Then hit RETURN.
395 7
$27.65

Sample Interactive Run 2:

Please type the item price in cents and then the number of items purchased. Then hit RETURN.
1995 19
$379.05

Sample Interactive Run 3:

Please type the item price in cents and then the number of items purchased. Then hit RETURN.
1995 20
$379.00

Sample Interactive Run 4:

Please type the item price in cents and then the number of items purchased. Then hit RETURN.
540 3
$16.20

Explanation / Answer

below is the solution:

package chegg;

import java.util.*;

import java.text.DecimalFormat;

public class centToDollar {

public static void main(String[] args) {

int cent,items; //cent for input cent and item for input the no of items

Scanner input = new Scanner(System.in); //scanner object to take input from keyboard

System.out.println("Enter the amount in cent and items"); //input cent and items

cent = input.nextInt(); //input cents

items = input.nextInt(); //input cents

int cents = cent % 100; //

int dollars = (cent - cents) / 100;

String dollar1 = dollars+"."+cents; //Concatenate the dollar and cents

double d = Double.parseDouble(dollar1)*items; //convert the strings into double

DecimalFormat formatter = new DecimalFormat("#0.00"); //format the 2 decimal place

System.out.print("$"); //prints the amount with dollar

System.out.println(formatter.format(d));

}

}

output:

Please type the item price in cents and then the number of items purchased
395 7
$27.65

Please type the item price in cents and then the number of items purchased
1995 19
$379.05

Please type the item price in cents and then the number of items purchased
1995 20
$399.00

Please type the item price in cents and then the number of items purchased
540 3
$16.20