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

A. Write a Java class that declares a named constant that holds the number of fe

ID: 3662622 • Letter: A

Question

A. Write a Java class that declares a named constant that holds the number of feet in a mile : 5,280 . Also declare a variable to represent the distance in miles between your house and your uncle's house. Assign an appropriate value to the variable for example, 8.5. Compute and display the distance to your uncle's house in both miles and feet . Display explanatory text with the values for example . -The distastance to my uncle's house is 8.5 miles or 44880.0 feet. Save the class as MilesToFeet.Java.

B. Convert the MilesToFeet class to an interactive application. Instead of assigning a value to the distance, accet the value from the user as input . Save the revised class MilesToFeetInteractive.java.

Explanation / Answer

/**
*
*/

/**
* @author Srinivas Palli
*
*/
public class MilesToFeet {

   static final int numberOfFeetPerMile = 5280;
   float distanceInMiles;

   /**
   * @return the distanceInMiles
   */
   public float getDistanceInMiles() {
       return distanceInMiles;
   }

   /**
   * @param distanceInMiles
   * the distanceInMiles to set
   */
   public void setDistanceInMiles(float distanceInMiles) {
       this.distanceInMiles = distanceInMiles;
   }

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       MilesToFeet milesToFeet = new MilesToFeet();
       milesToFeet.setDistanceInMiles(8.5f);
       System.out.println("The distastance to my uncle's house is "
               + milesToFeet.getDistanceInMiles() + " miles or "
               + milesToFeet.getDistanceInMiles()
               * MilesToFeet.numberOfFeetPerMile + " feet");

   }

}
/*OUTPUT:
   The distastance to my uncle's house is 8.5 miles or 44880.0 feet
*/

import java.util.Scanner;

/**
*
*/

/**
* @author Srinivas Palli
*
*/
public class MilesToFeetInteractive {

   static final int numberOfFeetPerMile = 5280;
   float distanceInMiles;

   /**
   * @return the distanceInMiles
   */
   public float getDistanceInMiles() {
       return distanceInMiles;
   }

   /**
   * @param distanceInMiles
   * the distanceInMiles to set
   */
   public void setDistanceInMiles(float distanceInMiles) {
       this.distanceInMiles = distanceInMiles;
   }

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub

       Scanner scanner = new Scanner(System.in);

       System.out
               .print("Enter the Distance in miles between your house and your uncle's house:");
       float distance = scanner.nextFloat();
       MilesToFeet milesToFeet = new MilesToFeet();
       milesToFeet.setDistanceInMiles(distance);
       System.out.println("The distastance to my uncle's house is "
               + milesToFeet.getDistanceInMiles() + " miles or "
               + milesToFeet.getDistanceInMiles()
               * MilesToFeet.numberOfFeetPerMile + " feet");

   }

}

/*OUTPUT:
Enter the Distance in miles between your house and your uncle's house:8.5
The distastance to my uncle's house is 8.5 miles or 44880.0 feet
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote