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

I have to turn an ouput of an amount of money, $4.07 and spell it out like; 4 do

ID: 3793873 • Letter: I

Question

I have to turn an ouput of an amount of money, $4.07 and spell it out like; 4 dollars and 7 cents. my code I have already is

import java.util.Scanner;

import javax.swing.JOptionPane;

public class Hoops {

   public static void main(String[] args) {

      

       Scanner scan = new Scanner(System.in);

       System.out.println( "Welcome to Hoopla Hula Hoops." );

       System.out.println( "Please enter your purchase requirements." );

       System.out.print( "Diameter of hula hoop (ft) : ");

       double hoop = scan.nextDouble();

       System.out.println("------------------------------");

       System.out.print( "Circumference of hula hoop (in): ");

      

      

       double circum = (int) (Math.PI*hoop*12);

       System.out.println(circum);

       System.out.print( "Cost required for hula hoop :" );

       double cost = ((circum* .11));

System.out.println(cost + " dollars and " + cost + " cents " );

       System.out.print("------------------------------");

       System.out.print( "Customer has paid the amount $ :");

I know the 3rd last line is wrong but I do not know how to fix it, any ideas?

Explanation / Answer

Hi

I have modified the code and highlighted the code changes below,

Hoops.java

import java.util.Scanner;

import javax.swing.JOptionPane;


public class Hoops {

public static void main(String[] args) {
  
Scanner scan = new Scanner(System.in);
System.out.println( "Welcome to Hoopla Hula Hoops." );
System.out.println( "Please enter your purchase requirements." );
System.out.print( "Diameter of hula hoop (ft) : ");
double hoop = scan.nextDouble();
System.out.println("------------------------------");
System.out.print( "Circumference of hula hoop (in): ");
  
  
double circum = (int) (Math.PI*hoop*12);
System.out.println(circum);
System.out.print( "Cost required for hula hoop :" );
double cost = ((circum* .11));
  
System.out.println((int)cost + " dollars and " + (int)(cost*100)%100 + " cents " );
System.out.print("------------------------------");
System.out.print( "Customer has paid the amount $ :");
}
}

Output:

Welcome to Hoopla Hula Hoops.
Please enter your purchase requirements.
Diameter of hula hoop (ft) : 8
------------------------------
Circumference of hula hoop (in): 301.0
Cost required for hula hoop :33 dollars and 11 cents
------------------------------Customer has paid the amount $ :