1. Unit Converter: complete the attached file (Converter.java) by adding convers
ID: 3805372 • Letter: 1
Question
1. Unit Converter: complete the attached file (Converter.java) by adding conversion from kilometers to miles, from degrees Fahrenheit to Celsius and vice-versa, and from kilograms to pounds. Write a separate method for each conversion, and allow the user to enter separate values for each conversion.
2. Grade calculator: write a program that reads your midterm grade (between 1 and 100), your final exam grade (between 1 and 100), your assignments average (between 1 and 10), and then computes your final grade by averaging the three using the following weights: 30% midterm, 40% final, and 30% assignments.
3. Vending machine: write a program that takes as input two values: the first represents the cost of an item, and the second is the amount of money being paid for it. Your program prints on the screen the amount of change to be returned, and splits it in the number of dollar bills, quarters, dimes ($0.1), nickels ($0.05), and pennies ($0.01).
In java and please explain how to get the answer
Explanation / Answer
Converter.java
import java.util.Scanner;
public class Converter {
public double convertKmToMiles(double kilometers){
double miles;
miles = kilometers * 0.621;
return miles;
}
public double getDegreesFehrenToCelcius (double degrees)
{
double val = 5 * (degrees - 32) / 9;
return Math.round (val * 10.0) / 10.0;
}
public double getDegreesCelciusToFehren (double degrees)
{
double val = 9 * (degrees / 5) + 32;
return Math.round (val * 10.0) / 10.0;
}
public double getPoundsFromKg(double kgs){
double pounds = kgs / 0.454;
return pounds;
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Converter conv = new Converter();
System.out.print("Enter kms to be converted to miles : ");
double kms = input.nextDouble();
double miles = conv.convertKmToMiles(kms);
System.out.println("Equavalent Miles of kms entered are : "+miles);
System.out.print("Enter temperature in FehrenHeit : ");
double fehrenheit = input.nextDouble();
double celcius = conv.getDegreesFehrenToCelcius(fehrenheit);
System.out.println("Temperature is Celcius is : "+celcius);
System.out.print("Enter temperature in Celcius : ");
double cel = input.nextDouble();
double fehren = conv.getDegreesCelciusToFehren(cel);
System.out.println("Temperature is Fehrenheit is : "+fehren);
System.out.print("Enter weight in Kgs : ");
double kgs = input.nextDouble();
double pounds = conv.getPoundsFromKg(kgs);
System.out.println("Weight in pounds is : "+pounds);
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------
GradeCalculation.java
import java.util.Scanner;
public class GradeCalculation {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your midterm grade (between 1 and 100) : ");
int midTermGrade = input.nextInt();
System.out.print("Enter your final exam grade (between 1 and 100) : ");
int finalExamGrade = input.nextInt();
System.out.print("Enter your assignment average (between 1 and 100) : ");
int asignmentAverageGrade = input.nextInt();
double finalGrade;
finalGrade = 0.3 * midTermGrade + 0.4 * finalExamGrade + 0.3 * asignmentAverageGrade;
System.out.println("Final Grade is : "+finalGrade);
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------
VendingCalculator.java
import java.util.Scanner;
public class VendingCalculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the cost of the item : ");
double itemCost = input.nextDouble();
System.out.print("Enter the amount being paid : ");
double amountPaid = input.nextDouble();
double amountToReturn = amountPaid - itemCost;
/*That's all the data your program needs to collect, now let's calculate...
*firstly we want to make the amount you just collected a whole number so it is WAY easier to deal with.. */
amountToReturn = amountToReturn * 100; // multiply the two decimal place number by 100 to make it a whole number.. N.B - this assumes the user's input is not more than two decimal places.
// dollars calculation..
double dollars = Math.floor (amountToReturn / 100);
// note dividing by 100 not 1 because the amount was multiplied by 100, so the dollar is too. the "Math.floor()" ROUNDS the answer DOWN to the nearest whole number.
// now the remainder after we take out dollars..
double dollarRem = amountToReturn % 100; // the "%" means it divides two numbers and returns the remainder.
// quarters calculation..
double quarters = Math.floor (dollarRem / 25);
// now the remainder after we take out quarters..
double quarterRem = dollarRem % 25;
//See the pattern? we'll just run through the rest..
double dimes = Math.floor (quarterRem / 10);
double dimeRem = quarterRem % 10;
double nickels = Math.floor (dimeRem / 5);
double nickelRem = dimeRem % 5;
double pennies = nickelRem; //anything divided by 1 is the same number, so nickelRem is the amount of pennies.
//Now that all calculations are done.. time for output to the user...
System.out.println ("Here is the amount to each type of coin necesssary to make change for $" + (amountToReturn / 100) + " is: "
+ "Dollars: " + (int) dollars + " "
+ "Quarters: " + (int) quarters + " "
+ "Dimes: " + (int) dimes + " "
+ "Nickels: " + (int) nickels + " "
+ "Pennies: " + (int) pennies); // output to user.
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.