Java Oriented Programming Code: I need help creating a java code that has a Calc
ID: 3796482 • Letter: J
Question
Java Oriented Programming Code: I need help creating a java code that has a Calculation.java and a Driver.java where the main method is a where you run the code. Code: I need a java code that calculate miles per hour to miles per minute, feet per mile and feet per minute. Constants that must be used FEET_PER_MINUTE & MINUTES_PER_SECOND. Above goes in Calculation.java. In the Driver.java. Allow user to enter miles per hour and display calculations for miles per minute, feet per mile and feet per minute. Lastly add a loop where output asks user if they would like to continue Y for loop and Q to exit.
Explanation / Answer
//Calculation.java
public class Calculation {
private int MINUTES_PER_HOUR = 60;
private int FEET_PER_MILE = 5280;
public double convertMPHToMPM(double milesPerHour)
{
return milesPerHour/MINUTES_PER_HOUR;
}
public double convertMileToFeet(double miles)
{
return miles*FEET_PER_MILE;
}
public double convertMPHToFPM(double milesPerHour)
{
return milesPerHour*FEET_PER_MILE/MINUTES_PER_HOUR;
}
}
// Driver.java
import java.util.Scanner;
public class Driver {
public static void main(String[] args)
{
Calculation c = new Calculation();
Scanner sc = new Scanner(System.in);
while(true)
{
System.out.print("Enter miles per hour: " );
double milesPerHour = Double.parseDouble(sc.nextLine());
System.out.println("Miles per hour: " + milesPerHour +
" Miles per minute : " + c.convertMPHToMPM(milesPerHour));
System.out.println("Miles : " + milesPerHour +
" Feets : " + c.convertMileToFeet(milesPerHour));
System.out.println("Miles per hour: " + milesPerHour +
" Feets per minute: " + c.convertMPHToFPM(milesPerHour));
System.out.print("Do you want to do more conversions: Y/Q: ");
String response = sc.nextLine();
if (response.equals("Q"))
break;
}
sc.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.