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
Which of the following statements are true?
grin007 [14]

Answer:

I think the answer are two which are B and C

7 0
3 years ago
How many bytes make up a megabyte? One hundred One thousand One million One billion
Phoenix [80]
One million is the answer.
4 0
3 years ago
Michael a programmer, is writing an algorithm to solve programming problems, Guide him to write an algorithm
Nadusha1986 [10]

Answer:

Algorithms need to be simple, factual, and explained in simple but relevant vocabulary, and must be step by step, and none of the step should be missing.

Hence, first you need to understand the requirement, which can be yours or your clients.

Then consider each module of the problem, and separate each of them from the others. Now, understand the relationship between each module. And then you need to understand how you can combine them in one algorithm.

Also remember, the modules are functions. and various functions combine together to form an algorithm. We can have separate algorithms for each module as well, and then you can combine them together in right continuity to form the one single program.

Also, a project can have a loads of programs with other parts like images and various other assets and technologies.

However, everything starts with algorithms. And if are good at explaining, and a sound vocabulary, plus can explain the process well, you can explain the process well, and write a good algorithm definitely. Learn languages like Python, C, and C++  to start with, and then continue with Java, R etc. Remember we still uses functional programming as well like through Haskell etc.

The below is an example of sample algorithm. John wants to check what Ana has brought for him.

Step 1: Ana arrives with meat, which can be of goat or chicken

Step 2: John: Hi Ana

Step3: Yes John

Step 4 What meat is that Ana

Step 5: Goat

Step 7: Thanks Ana for Bringng Goat Meat

Step 8: Stop

In the above algorithm John confirms that what meat Ana has brought for him. And he comes to know She has bought Goat meat. This is the simplest of algorithm with no loop. And the complexity can be increased to any level.

Explanation:

The Answer is self explanatory, and has all that is required.

7 0
3 years ago
Read 2 more answers
Which Windows utilities are used to create previous versions of files that can be recovered from the file properties dialog box?
pochemuha

Answer:

File History utility and System Protection utility for windows 8;

And then Backup and Restore utility and System Protection utility for windows 7.

6 0
3 years ago
The physical parts of a computer are called application software.
zlopas [31]
Ok so what was the question
3 0
2 years ago
Read 2 more answers
Other questions:
  • You have received several trouble tickets from the employees in the warehouse for the stand-alone computers used to control vari
    14·1 answer
  • How do you ask someone for help?
    6·1 answer
  • ____ is high-quality encryption software that has become quite popular for creating secure e-mail messages and encrypting other
    9·1 answer
  • Bitnet, one of the predecessors of the internet was launched in 1981. what does bitnet stand for?
    12·1 answer
  • The variable grade can have any real number value from 0 to 100. Ask the user to enter a grade in numerical form. Write an if-el
    9·1 answer
  • Which sentence uses a pair of synonyms? Because there was so much shouting, many of the protestors began screaming in order to b
    6·2 answers
  • What is the difference between i++ and ++ii?
    6·1 answer
  • Have all of my coins because i will delete acount there will be part 2, 3 , 4 ,5,6,7,8
    15·2 answers
  • Ian kno da answer tell me
    7·2 answers
  • How can I use HTML to express a personal value
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!