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

thanks ahead of time Write a Java program called Assignment2.java. The program i

ID: 3550009 • Letter: T

Question


thanks ahead of time

Write a Java program called Assignment2.java. The program is to display questions and read user inputs, then calculate and print out the requested value with a proper format. This program will follow a very simple process. Calculate the average value from input three integer values. Use two-decimal format (use only two digits) for printing the average value. It is OK to use Syszeir.. out .printf () method (Look at the page 50), though it is possible to complete this task without using the printf method. Calculate the total number of characters from input three String values. Check the difference between the next () (Look at the page 60) and nextLine () (Look at the JAVA API) methods of Scanner. Calculate the change in dollars, quarters, dimes, nickels, and pennies when a price and a payment amount are input. Use only the Java statements that have been covered in class to date. This means you CAN use declaration, assignment, input and output statements . DO NOT use any other statements (if-else, loop, etc.)

Explanation / Answer

please rate - thanks


didn't know what you learned, so used the bare minimum '

any changes needed let me know

import java.util.*;
public class Assignment2
{public static void main(String[] args)
{Scanner in=new Scanner(System.in);
int n1,n2,n3;
double average;
String first,middle,last;
int total;
double amount,pay;
int dollar,quarter,dime,nickel,change;
System.out.println("***TASK 1: Calculate the average of three inputs ***");
System.out.print("Please input the first integer: ");
n1=in.nextInt();
System.out.print("Please input the second integer: ");
n2=in.nextInt();
System.out.print("Please input the third integer: ");
n3=in.nextInt();
average=(n1+n2+n3)/3.;
System.out.printf("The average of three inputs is %.2f ",average);
System.out.println("***TASK 2: Calculate the number of characters ***");
in.nextLine();
System.out.print("What is your first name? ");
first=in.nextLine();
System.out.print("What is your middle name(If not, just type the RETURN key)? ");
middle=in.nextLine();
System.out.print("What is your last name? ");
last=in.nextLine();
total=first.length()+middle.length()+last.length();
System.out.println("The total number of characters is: "+total);
System.out.println(" *** TASK 3: Calculate the change ***");
System.out.print("How much is the item? ");
amount=in.nextDouble();
System.out.print("How much do you pay? ");
pay=in.nextDouble();
change=(int)((pay-amount)*100);
dollar=change/100;
change=change%100;
quarter=change/25;
change=change%25;
dime=change/10;
change=change%10;
nickel=change/5;
System.out.println("The change in");
System.out.println(" Dollar bills: "+dollar);
System.out.println(" Quarters: "+quarter);
System.out.println(" Dimes: "+dime);
System.out.println(" Nickels: "+nickel);
System.out.println(" Pennies: "+change);

}
}