Question

In: Computer Science

1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money...

1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money from 0 to 99 cents. The program then calculates and displays the number of coins from each denomination: quarters (25 cents), dimes (10 cents), nickels (5 cents), and cents. For example, if the user enters 93, your program should display There are 3 quarters, 1 dimes, 1 nickels, and 3 cents in 93 cents Note: You must use integer division and modular division to find the digits.

Solutions

Expert Solution

import java.util.Scanner;

public class Change{
        public static void main(String[] args) {
                int amount=0,d=0,q=0,n=0,p=0,di=0;
                  System.out.printf("Enter amount: ");
                  Scanner sc = new Scanner(System.in);
                  amount=sc.nextInt();
                  if(amount==0){
                    System.out.printf("no change");
                    return;
                  }
                  //finding dollors
                  if(amount>=100){
                    d=amount/100;
                    amount=amount%100;
                  }
                  //finding quarters
                  if(amount>=25){
                    q=amount/25;
                    amount=amount%25;
                  }
                  //findigng dimes
                  if(amount>=10){
                    di=amount/10;
                    amount=amount%10;
                  }
                  //finding nickels
                  if(amount>=5){
                    n=amount/5;
                    amount=amount%5;
                  }
                  p=amount;
                  if(d==1)
                    System.out.printf("%d dollor\n",d);
                  else if(d!=0)
                    System.out.printf("%d dollors\n",d);

                  if(q==1)
                    System.out.printf("%d quarter\n",q);
                  else if (q!=0)
                    System.out.printf("%d quarters\n",q);
                  if(di==1)
                    System.out.printf("%d dime\n",di);
                  else if (di!=0)
                    System.out.printf("%d dimes\n",di);
                  if(n==1)
                    System.out.printf("%d nickel\n",n);
                  else if (n!=0)
                    System.out.printf("%d nickels\n",n);
                  if(p==1)
                    System.out.printf("%d penny\n",p);
                  else if (p!=0)
                    System.out.printf("%d pennies\n",p);
                  

                }
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter...
---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter 5 test scores. The program will display a letter grade for each test score and an average grade for the test scores entered. The program will write the student name and average test score to a text file (“studentgrades.txt”). Three functions are needed for this program. def letter_grade( test_score) Test Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
write a program that: 1) asks the user to enter grades, a negative number is the...
write a program that: 1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list) after the while loop to enter grades is finished: 2) use a for loop on the list to calculate the average of all numbers in the list 3) use a for loop on the list to find the largest number in the...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a javascript program that asks the user to enter up to 10 golf scores, which...
Write a javascript program that asks the user to enter up to 10 golf scores, which are to be stored in an array. You should provide a means for the user to terminate input prior to entering 10 scores. The program should display all the scores on one line and report the average score. Handle input, display, and the average calculation with three separate array processing functions.
Question : Write a C program that asks the user to enter an integer between 1...
Question : Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’. and give me an output please use printf and scanf #include...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT