The simpler code for the given main ( ) function is shown below. For this, calculate the hours and miles before the main function and store them in the separate variables and after this, use these variables in main ( ) code. The below complete code is written in Java which reduce the given main ( ) code and also make it simple.
Further Explaination:
The simple code in Java to calculate the miles traveled is shown below:
Code: Simple.java
import java.util.Scanner;
public class CalcMiles
{
//Define the method calcMilesTraveled().
Public double calcMilesTraveled (double mph, double minutesTravelled)
{
//Declare required variables.
Double hoursTravelled = 0.0;
Double milesTravelled = 0.0;
//Calculate the hours travelled and miles travelled.
hoursTravelled = minutesTravelled / 60.0;
milesTravelled = hoursTravelled * mph;
//The total miles travelled in return.
Return milesTravelled;
}
public static void main(String [] args)
{
double milesPerHour = 70.0;
double minsTravelled = 100.0;
CalcMiles tripCalculator = new CalcMiles();
System.out.println("Miles: " + tripCalculator.calcMilesTraveled (milesPerHour, minsTraveled));
}
}
Output:
Run the program, the output will be look like as below:
Miles: 116.66666666666667
Learn more:
1. A company that allows you to license software monthly to use online is an example of ? brainly.com/question/10410011
2. How does coding work on computers? brainly.com/question/2257971
Answer details:
Grade: College Engineering
Subject: Computer Science and Engineering
Chapter: Java Programming
Keyword:
Java, input, output, programming, statements, class, double, int, miles, hours, milesPerHour, hoursTraveled, printf, return