Java Oriented Programming Code I need another way of rewriti

Java Oriented Programming Code: I need another way of rewriting the following code. The constants must be the same and must have the same loop.

Driver:

import java.util.Scanner; //Needed for Scanner class.
/**
*
*/

public class Driver
{

public static void main(String[] args)
{
  
double MilesPer;

double loop =1;

//Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);

while(true)
{

Miles m = new Miles();
//Get the miles per hour .
System.out.println(\"Enter Miles per Hour: \");
MilesPer = keyboard.nextDouble();
m.setMilesPer(MilesPer);
//Setting Miles Per Hour


System.out.println( \"Miles per min. :\" + m.getMPHtoMPM());
System.out.println( \"Feet per mile: \" + m.getMPHtoMPF());
System.out.println( \"Feet per min. : \"+ m.getMPHtoFPM());


System.out.println(\"\ If you would like to run again Enter Y to continue Enter Q to quit: \");//Display message for user to keep running the program.
String answer = keyboard.next();
if (answer.equals(\"Q\"))
break;
}
System.out.println(\"Have a good one! \");//Goodbye message
}
}

Miles:

import java.util.Scanner;
/**
*
*
*
*/


public class Miles
{
double MilesPer;
private int MINUTES_PER_HOUR = 60;
private int FEET_PER_MILE = 5280;

public Miles()
{

int MINUTES_PER_HOUR = 60;
int FEET_PER_MILE = 5280;
}

public void setMilesPer(double milesPer)
{
if (milesPer > 0)
MilesPer = milesPer;
}

public double getMilesPer()
{
return MilesPer;
}

public double getMPHtoMPM()
{ return MilesPer/MINUTES_PER_HOUR;
}

public double getMPHtoMPF()
{ return MilesPer*FEET_PER_MILE;
}


public double getMPHtoFPM()
{
return MilesPer*FEET_PER_MILE/MINUTES_PER_HOUR;
}

}

Solution

Driver.java


import java.util.Scanner; //Needed for Scanner class.
/**
*
*/

public class Driver
{

public static void main(String[] args)
{
  
double MilesPer;
double loop =1;
//Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
Miles m = new Miles();
String answer= \"\";
while(!answer.equals(\"Q\"))
{

//Get the miles per hour .
System.out.println(\"Enter Miles per Hour: \");
MilesPer = keyboard.nextDouble();
m.setMilesPer(MilesPer);
//Setting Miles Per Hour


System.out.println( \"Miles per min. :\" + m.getMPHtoMPM());
System.out.println( \"Feet per mile: \" + m.getMPHtoMPF());
System.out.println( \"Feet per min. : \"+ m.getMPHtoFPM());
System.out.println(\"\ If you would like to run again Enter Y to continue Enter Q to quit: \");//Display message for user to keep running the program.
answer = keyboard.next();

System.out.println(\"Have a good one! \");//Goodbye message
}
}
}

Miles.java
public class Miles
{
double MilesPer;
private int MINUTES_PER_HOUR = 60;
private int FEET_PER_MILE = 5280;
public Miles()
{

int MINUTES_PER_HOUR = 60;
int FEET_PER_MILE = 5280;
}
public void setMilesPer(double milesPer)
{
if (milesPer > 0)
MilesPer = milesPer;
}

public double getMilesPer()
{
return MilesPer;
}

public double getMPHtoMPM()
{ return MilesPer/MINUTES_PER_HOUR;
}

public double getMPHtoMPF()
{ return MilesPer*FEET_PER_MILE;
}


public double getMPHtoFPM()
{
return MilesPer*FEET_PER_MILE/MINUTES_PER_HOUR;
}

}

Output:

Enter Miles per Hour:
4
Miles per min. :0.06666666666666667
Feet per mile: 21120.0
Feet per min. : 352.0

If you would like to run again Enter Y to continue Enter Q to quit:
y
Have a good one!
Enter Miles per Hour:
7
Miles per min. :0.11666666666666667
Feet per mile: 36960.0
Feet per min. : 616.0

If you would like to run again Enter Y to continue Enter Q to quit:

Q
Have a good one!

Java Oriented Programming Code: I need another way of rewriting the following code. The constants must be the same and must have the same loop. Driver: import j
Java Oriented Programming Code: I need another way of rewriting the following code. The constants must be the same and must have the same loop. Driver: import j
Java Oriented Programming Code: I need another way of rewriting the following code. The constants must be the same and must have the same loop. Driver: import j
Java Oriented Programming Code: I need another way of rewriting the following code. The constants must be the same and must have the same loop. Driver: import j

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site