//java Create a NetBeans project named Coins After you have created your NetBean
ID: 3574754 • Letter: #
Question
//java
Create a NetBeans project named Coins
After you have created your NetBeans Project your application class should contain the following executable code:
package coins;
public class Coins {
public static void main(String[] args) {
}
}
Write the code for the main class as indicated below:
package coins;
/* Import the Scanner class and DecimalFormat class */
// Your code here
public class Coins{
public static void main( String [] args ){
/* Declare three variable identifiers of type int to represent nickels, dimes and quarters */
// Your code here
/* Instantiate an object of type Scanner (see example 3.9 in text) */
// Your code here
/* prompt the user for the number of nickels, dimes and quarters and input the values to your daclared variable idenifiers using the appropriate input method on the scanner class object (see example 3.9 in text) */
// Your code here
/* Enter formula(s) to calculate total dollar ammount of coins and assign the calculated value to a variable identifier of type double */
// Your code here
/* Use the DecimalFormat class to output your result in currency format */
// Your code here
} }
Explanation / Answer
Coins.java
import java.text.DecimalFormat;
import java.util.Scanner;
/* Import the Scanner class and DecimalFormat class */
//Your code here
public class Coins{
public static void main( String [] args ){
/* Declare three variable identifiers of type int to represent nickels, dimes and quarters */
int nickels, dimes, quarters;
//Your code here
/* Instantiate an object of type Scanner (see example 3.9 in text) */
//Your code here
Scanner scan = new Scanner(System.in);
/* prompt the user for the number of nickels, dimes and quarters and input the values to your daclared variable idenifiers using the appropriate input method on the scanner class object (see example 3.9 in text) */
//Your code here
System.out.println("Enter the number of nickels, dimes and quarters: ");
nickels = scan.nextInt();
dimes = scan.nextInt();
quarters = scan.nextInt();
/* Enter formula(s) to calculate total dollar ammount of coins and assign the calculated value to a variable identifier of type double */
//Your code here
double dollor = (nickels * 5 + dimes * 10 + quarters * 25)/100.0;
/* Use the DecimalFormat class to output your result in currency format */
//Your code here
DecimalFormat dfCurrency= new DecimalFormat("$#.00");
System.out.println("Dollor amount is "+dfCurrency.format(dollor));
} }
Output:
Enter the number of nickels, dimes and quarters:
5 6 7
Dollor amount is $2.60
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.