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

The following pseudocode describes how to extract the dollars and cents from a p

ID: 3793319 • Letter: T

Question

The following pseudocode describes how to extract the dollars and cents from a price given as a floating point value. For example, a price 2.95 yields values 2 and 95 for the dollars and cents. Assign the price to an integer variable dollars. Multiply the difference price dollars by 100 and add 0.5. Assign the result to an integer variable cents. Translate this pseudocode into a Java program. Read a price and print the dollars and cents. Test your program with inputs 2.95 and 4.35. Giving change. Implement a program that directs a cashier how to give change. The program has two inputs the amount due and the amount received from the customer. Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In order to avoid roundoff errors, the program user should supply both amounts in pennis, for example 274 instead of 2.74 An online bank wants you to create a program that shows prospective customers how their deposits will grow. Your program should read the initial balance and the annual interest rate. Interest is compounded monthly. Print out the balances after the first three months. Here is a sample run: Initial balance 1000 Annual interest rate in percent: 6.0 After first month 1005.00 After second month 1010.03 After third month 1015.08 A video club wants to reward its best members with a discount based on the member's number of movie rentals and the number of new members referred by the member. The discount is in percent and is equal to the sum of the rentals and the referrals, but it cannot exceed 75 percent. Write a program Discount calculator to calculate the value of the discount Here is a sample run:

Explanation / Answer

We cannot directly implicitly concert double to int.we initiate the Double instance and explicitly convert to int.

To display up to 2decimal points we use %.2f

1.

mport java.lang.Math; // headers MUST be above the first class
import java.util.Scanner;

// one class needs to have a main() method
class Convertions
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
    double price;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter Price value: ");
price = keyboard.nextDouble();  
    Double d = new Double(price);
int dollars = d.intValue();
double result=(price-dollars)*100+0.5;
Double res = new Double(result);
int cents = res.intValue();
    System.out.println("The price is equal to "+dollars+ " dollars"+cents+" cents");
}
}

2.

import java.lang.Math; // headers MUST be above the first class
import java.util.Scanner;
class Change
{
    public static void main(String[] args)
    {
Scanner keyboard = new Scanner(System.in);
        System.out.println("Amount Due in Dollars?");
        double amountd = keyboard.nextDouble();

        System.out.println("Amount Received in Dollars?");
        double amountr = keyboard.nextDouble();

        double difference = (amountr - amountd);

        //Convert to Pennies
        int balance = (int)(difference * 100);
        
        int dollars = balance / 100;
        balance = (balance - (100 * dollars));

        int quarters = balance / 25;
        balance = (balance - (25 * quarters));

        int dimes = balance / 10;
        balance = (balance - (10 * dimes));

        int nickels = balance / 5;
        balance = (balance - (5 * nickels));
    
        int pennies = balance / 1;
        balance = balance - (1 * pennies);

        System.out.println("The difference is " + dollars + " dollars, " + quarters + " quarters, "
                    + dimes + " dimes, " + nickels + " nickels, " + pennies + " pennies.");

        
    }
}

3.import java.util.Scanner;
class Prospective_Cust {
   public static void main(String[] args) {
   Scanner input = new Scanner(System.in);
   System.out.print("Initial balance: ");
   double balance = input.nextDouble();
   System.out.print("Annual intereset in percent: ");
    double annual_interest = input.nextDouble();
    input.close();
    double monthly_interest = annual_interest / 12 / 100;
    double first_month = balance + balance * monthly_interest;
   System.out.printf("After first month: %.2f ", first_month);
    double second_month = first_month + first_month * monthly_interest;
   System.out.printf("After second month: %.2f ", second_month);
    double third_month = second_month + second_month * monthly_interest;
    System.out.printf("After third month: %.2f", third_month);
    }
}
4.

import java.util.Scanner;
class Member_Discounts {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter the number of movie rentals: ");
        int rentals = keyboard.nextInt();
        System.out.println("Enter the number of members referred to thevideo club: ");
        int referrals = input.nextInt();
        double discount_val = 75.00;
        double discount = Math.min(rentals + referrals, discount_val);
        System.out.printf("The discount is equal to : %.2f percent.", discount);
    }
}