1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dmitriy555 [2]
3 years ago
6

Write a method so that the main() code below can be replaced by the simpler code that calls method mphAndMinutesToMiles(). Origi

nal main():
public class CalcMiles {
public static void main(String [] args) {
double milesPerHour;
double minutesTraveled;
double hoursTraveled;
double milesTraveled;
milesPrHour = scnr.nextDouble();
minutesTraveled = scnr.nextDouble();
hoursTraveled = minutesTraveled / 60.0;
milesTraveled = hoursTraveled * milesPerHour;
System.out.println("Miles: " + milesTraveled);
}
}
import java.util.Scanner;
public class CalcMiles {
/* Your solution goes here */
public static void main(String [] args) {
Scanner scnr = new Scanner(System.in);
double milesPerHour;
double minutesTraveled;
milesPerHour = scnr.nextDouble();
minutesTraveled = scnr.nextDouble();
System.out.println("Miles: " + mphAndMinutesToMiles(milesPerHour, minutesTraveled));
}
}

Computers and Technology
2 answers:
Burka [1]3 years ago
8 0

Answer:

public static double mphAndMinutesToMiles(double m,double t){

return m*t/60;

}

Explanation:

defon3 years ago
5 0

ANSWER

The JAVA program after simplification is as below.

import java.util.Scanner;

public class CalcMiles {

   

   // variables declaration

   static double milesPerHour;

   static double minutesTraveled;      

   static double hoursTraveled;

   static double milesTraveled;

   

   // method declared static

   public static void mphAndMinutesToMiles(double speed, double mins)

   {

       // computations to calculate distance travelled

       hoursTraveled = mins / 60.0;

       milesTraveled = hoursTraveled * speed;

       

       // result displayed on the screen  

     System.out.println("Miles: " + milesTraveled);

   }

   

   // Scanner object created inside main()

   // user input taken inside main()

   public static void main(String [] args)

   {

       Scanner scnr = new Scanner(System.in);

       System.out.println("Enter miles travelled per hour ");

       milesPerHour = scnr.nextDouble();

       System.out.println("Enter minutes required to travel ");

       minutesTraveled = scnr.nextDouble();

       

       mphAndMinutesToMiles(milesPerHour, minutesTraveled);

       

   }

}

OUTPUT

Enter miles travelled per hour  

2.3

Enter minutes required to travel  

1234

Miles: 47.30333333333333

EXPLANATION

The program is simplified as explained below.

1. User input is taken using the object of Scanner class.

2. This object of Scanner class can only be created inside main() method hence, user input can only be taken inside main().

3. The code to calculate the result is separated in another method, mphAndMinutesToMiles(). This method is declared with return type void since no value is returned.

4. After user input is taken in main() for miles travelled per hour and minutes required to travel, these values are passed as parameters to the mphAndMinutesToMiles() method.

5. These parameters are used in calculation part. The total miles travelled in total hours (obtained from minutes), is calculated. The code to display the result is added to this method.

6. Inside the main method, only the code to create Scanner object, code to take user input for two variables and code to call the mphAndMinutesToMiles() is included.

7. The variables are declared as static and declared at class level.

8. No variable is declared inside any of the two methods.

You might be interested in
personalization allows customers to modify the standard offering, such as selecting a different home page to be displayed each t
shusha [124]
True, personalization is definitely part of this.
6 0
2 years ago
Heeeeeeelp :)<br><br> hwjkwdlfo;pk
Rasek [7]

Answer: C u use schoology too :D

Explanation:

7 0
3 years ago
Add code to this loop, to pick up all of the radios, with only seven blocks.
Goshia [24]

Answer:

umm

Explanation:

what do you mean by that

4 0
3 years ago
Endnotes are indicated by
V125BC [204]

Answer:

The answer is D because u have the uppercase letter bold

4 0
2 years ago
Read 2 more answers
3. This shows you the different things that all the tools can do, as you click on the tools
leva [86]
D that’s the answer I learn that in my old school
7 0
3 years ago
Other questions:
  • A ____ is a data network connection that makes use of the public telecommunications infrastructure but maintains privacy through
    13·1 answer
  • Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds.
    8·1 answer
  • In an AND truth table.
    7·1 answer
  • Sonic the Hedgehog (1991)
    14·1 answer
  • What does it mean to compact and repair your database? What is the difference between a single
    15·1 answer
  • Beth would like to run an nmap scan against all of the systems on her organization's private network. These include systems in t
    15·1 answer
  • An application's certificate indicates the application -
    5·1 answer
  • true or false hardware diagnostics let you run a quick check of system hardware and can verify that most systems components are
    5·1 answer
  • 2023 murano’s available intelligent awd adjusts the ________ to help maintain cornering control.
    11·1 answer
  • Does the source MAC address match your PC interface?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!