Change Calculator: 50points + 5 ex.cr. 2016 This programwill ask the user for th
ID: 3579334 • Letter: C
Question
Change Calculator: 50points + 5 ex.cr. 2016 This programwill ask the user for the number of quarters, dimes, nickels, and pennies s/he has and then compute the total value. Thetotal value of the change should be shown as the number of dollars (i.e., a whole number) and then a separate number of cents (also as a whole number). The assignment parameters are: a) Develop the money calculating program discussed below using a command line interface, where the class file includes a “main” method to launch the program, imports for required external packages, uses global and local variables where appropriate, and has additional method callsfor processing. b) The program should use at least one method beyond main: to obtain and validate the input values for each coin type (specifically, the coin counts must be non-negative values) c) Include a loop in the process so that the user may enter different sets of coins (i.e., be able to run the calculation multiple times) Asample run might look as follows: Welcome to the Change Calculator! Do you have change (Y/N)? Y How many quarters do you have? -1 You must enter a non-negative integer. Please try again. How many quarters do you have? 3 How many dimes do you have? 2 How many nickels do you have? 2 How many pennies do you have? 4 You have a total of 109 cents, which is 1 dollar(s) and 9 cent(s). Do you have more change (Y/N)? N Thanks for using the Change Calculator! Develop the program inside the Netbeans IDE, calling your program CalcChange.java. When finished, zip the entire Netbeans project (from top-level folder down) and submit the zip file through the blackboard assignment link (steps will be demonstrated in class). Part B: Add half-dollars to the process. In other words, an additional question ‘How many half-dollars do you have?’ should be asked during each run and then included in the total value calculation. Extra Credit (5 points): Code according to posted pseudo-code using coinTotal() method. This varies from the way we built the program in the class (and on the recording).
Explanation / Answer
package calcchange;
import java.util.Scanner;
/**
*
*/
public class CalcChange {
/**
*/
public static void main(String[] args) {
// TODO code application logic here
int totaldollar;
int totalcents;
int totalvalue;
System.out.println("Welcome to the Change Calculator. Do you have any change? (Y?N)");
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
if ((input.equals("Y")) || (input.equals("y"))) {
System.out.println("How many Quarters do yo have?");
Scanner in = new Scanner(System.in);
int num = in.nextInt();
totalvalue = num*25;
System.out.println("How many Dimes do yo have?");
num = in.nextInt();
totalvalue = totalvalue + (num*10);
System.out.println("How many Nickles do yo have?");
num = in.nextInt();
totalvalue = totalvalue + (num*5);
System.out.println("How many Pennies do yo have?");
num = in.nextInt();
totalvalue = totalvalue + (num);
totaldollar = (int) (totalvalue/100);
totalcents = totalvalue - (totaldollar * 100);
System.out.println("you have a total of "+ totalvalue + " Cents");
System.out.println("Which is "+ totaldollar + " dollars");
System.out.println("And "+ totalcents + " Cents");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.