Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USE Java. The following program will compile and run, but it uses poor programmi

ID: 673629 • Letter: U

Question

USE Java.

The following program will compile and run, but it uses poor programming style. In an
appropriately named class, modify the program so that it uses the spelling conventions,
constant naming conventions, and formatting style recommended in class and in your
textbook (Section 1.4).
public class messy {
public static double MoneyOwed (double x) {return x*1.6;}
public static void main(String[] args)
{
double TIME; double PACE;
System.out.println("This program calculates your pace given a time and distance
traveled.");
TIME=35.5; /* 35 minutes and 30 seconds */
PACE=TIME/distance;
System.out.println("Your pace is "+PACE+" miles per hour.");
}
public static final double distance=6.21;
}

Explanation / Answer

public class messy
{
public static double moneyOwed (double x)
{
return x*1.6;
}
public static final double distance=6.21;

public static void main(String[] args)
{
   double time, pace;
   System.out.println("This program calculates your pace given a time and distance traveled.");
   time=35.5; /* 35 minutes and 30 seconds */
   pace=time/distance;
   System.out.println("Your pace is "+pace+" miles per hour.");
}
}