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
Write code to define a function named mymath. The function has three arguments in the following order: Boolean, Integer, and Int
saveliy_v [14]

Answer:

public class Main

{

public static void main(String[] args) {

Main m=new Main();

System.out.println(m.mymath(true,5,2)); // calling the function mymath

}

public int mymath(boolean a,int b,int c) // mymath function definition

{

if(a==true)

{

int d=b+c;

return d;

}

else{int e=b-c;

return e;

}

}

}

7 0
2 years ago
Explain the relationship between society and the technologies of using Earth's resources?
julsineya [31]
Earth is natural and technology has a thing that can make u sick
5 0
3 years ago
In cell N2, enter a formula using the IF function and structured references as follows to determine which work tier Kay Colbert
sattari [20]

The IF Function based formula that can be entered into cell N2 that will return 2 if true, and 1 if false is =IF(M2 >=4, 2, 1).

<h3>How is the IF function used?</h3>

An IF function allows us to be able to sort through data by analyzing data to find out if it conforms to a certain characteristic that we are looking for.

If the data corresponds, the IF function will return a value that means True, but if it doesn't, the value returned would be false.

After typing in the IF function, the next thing to do is specify the cell where the data you want to analyze is. In this case that data is in cell M2. You immediately follow this up by the parameter being compared.

In this case, we want to know if the figure in cell M2 is greater or equal to 4 so the next entry is M2>=

The next entry is the return if the comparison is true. In this case, the number for true is 2 and the one for false is 1. The full formula becomes:

=IF(M2 >=4, 2, 1).

In conclusion, the function is =IF(M2 >=4, 2, 1).

Find out more on the spreadsheets at brainly.com/question/1429504.

#SPJ1

8 0
1 year ago
Your company has a team of remote workers that need to use Windows-based software to develop company applications, but your team
timofeeve [1]

Operating systems are the software that supports the basic functioning of the computer. Windows Virtual Desktop is an Azure compute service that will help solve the problem.

<h3>What is Windows Virtual Desktop?</h3>

Windows Virtual Desktop is an app virtualization service of Azure that operates on the cloud platform. It includes standard operating procedures that can be used by users with multiple OS.

Azure's Virtual Desktop supports different versions of window OS. This type of system is majorly used in remote work demands and specialized workloads.

Therefore, Windows Virtual Desktop is an Azure compute service.

Learn more about Azures service here:

brainly.com/question/13144160

#SPJ1

5 0
1 year ago
Three different numbers need to be placed in order from least to greatest. For example, if the numbers are ordered 9, 16, 4, the
Savatey [412]

Answer:

what are the three different numbers?

8 0
2 years ago
Other questions:
  • Write a full class definition for a class named Averager, and containing the following members:______An data member named sum of
    6·2 answers
  • _____ software can help a company manage security, enforce corporate strategies, and control downloads and content streaming fro
    11·1 answer
  • Name that red flag asigment
    15·2 answers
  • An enterprise system is a packaged software application that helps integrate various ___________ in a company.
    15·2 answers
  • 1.Customer service is assistance provided by a company to the people who buy or use its products or services.
    13·2 answers
  • Which of the following is not considered format?
    8·2 answers
  • Which can be used to decode a Unicode character encoding into text?
    13·1 answer
  • Impaired drivers are one of the many risks drivers face on the Highway Transportation System. List 3 signs that a driver could b
    10·2 answers
  • Who are the following furries?
    10·2 answers
  • Why do designers of smartphones hide computer processing details from
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!