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

Need help writing this program 1-Input the number of quarters, dimes, nickels, a

ID: 440145 • Letter: N

Question

Need help writing this program 1-Input the number of quarters, dimes, nickels, and pennies from the user. Print out the number of coins and total value in dollars. 2-Input the number of cents from the user. Determine and print out the number of quarters, dimes, nickels, and pennies to add up to that number of cents. No, you can't use all pennies For the second method, we can use integer division and the mod operator to make change. Suppose the user enters 99 as the number of cents. The sequence of calculations should be as follows. The integer division 99 / 25 can be used to determine the number of quarters (3). Using the mod operator 99 % 25 determines the remaining number of cents to be converted into change (24). Integer division 24 / 10 can be used again to determine the number of dimes (2). The mod operator 24 % 10 can be used again to determine the remaining amount (4). Next, for nickels, integer division 4 / 5 for the number of nickels (0) and a mod operation 4 % 5 for the remaining amount (4). Whatever is left is the number of pennies (4). Of course the values that were calculated (3, 24, 2, 4, 0, 4) would be different if the user enters something different from 99. This means we should have variables to store all of these values. For example, we might have a variable named cents to hold the value that the user entered, a variable named remainingAfterQuarters for the remaining amount after the quarters are determined, which could be assigned by: int remainingAfterQuarters = cents % 25;

Explanation / Answer

import java.util.Scanner ;
class coins {
       int quarters, dimes, nickels, pennies ,cents ;

public void change (int quart,int dime,int nick, int penn ){
          int dollar ;
                          dollar = 0.25 * quart + .10*dime + .5 * nick + .01 *penn ;
                         System.out.println("dollar +"+dollar);
                 }

        public void cent_(int cents){
                           int quart, dime, nick, penn ;
                          quart = cent /25 ;
                          System.out.println(quart +"number of quarters");
                           quart = cent % 25 ;
                         dime = quart /10 ;
                         System.out.println(dime +"number of dimes");
                    dime =dime%10;
                      nick = dime / 5 ;
                       System.out.println(nick +"number of nickels");
                        penn = nick % 5;
                       System.out.println(penn +"number of pennies");
                 }

       public static void main (String arg[]){
                    Scanner input = new Scanner (System.in) ;

                     int quarters, dimes, nickels, pennies ,cents ;
   System.out.println( "number of quarters");
   quarters = input.nextInt();

                      System.out.println("number of dimes");

                  dimes = input.nextInt();

                  System.out.println("number of nickels");

   nickels = input.nextInt();

                System.out.println("number of pennies");
pennies = input.nextInt();

                 change (quarters, dimes, nickels, pennies );

                  System.out.println("number of cents");

cents = input.nextInt();

               cent_(cents) ;

     }


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote