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

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

ID: 665279 • Letter: 1

Question

1. 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 distance to my uncle's house is 8.5 miles or 44880.0 feet. Save the class as MilesToFeet.java. Convert the MilesToFeet class to an interactive application. Instead of assigning a value to the distance, accept the value from the user as input. Save the revised class as MilesToFeetInteractive.java.

2. The Happy Yappy Kennel boards dogs at a cost of 50 cents per pound per day. Write a class that accepts a dog’s weight and number of days to be boarded and displays the total price for boarding. Save the class as DogBoarding.java.

3. Write a program that accepts a temperature in Fahrenheit from a user and converts it to Celsius by subtracting 32 from the Fahrenheit value and multiplying the result by 5/9. Display both values. Save the class as FahrenheitToCelsius.java.

4. Create a class named Student. A Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point average field by dividing points by credit hours earned. Write methods to display the values in each Student field. Save this class as Student.java.

5. Create an abstract class called GeometricFigure. Each figure includes a height, a width, a figure type, and an area. Include an abstract method to determine the area of the figure. Create two subclasses called Square and Triangle. Create an application that demonstrates creating objects of both subclasses, and store them in an array. Save the files as GeometricFigure.java, Square.java, Triangle.java, and UseGeometric.java.

Explanation / Answer

1.public class MilesToFeet
   {
       public static void main(String[] args)
           {
               int mile = 5280;
               int distance = 202;
               int feet = mile * distance;
               System.out.println("It is " + distance + " miles to my uncles house. This is exactly " + feet + " feet.");
           }
   }

2.

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{

public static double calculateCost(double pounds, int days){
return (.5*pounds)*days;

}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner in = new Scanner(System.in);
int days;
double pounds;
double cost;

System.out.println("Enter pounds:");
pounds = in.nextDouble();

System.out.println("Enter number of days:");
days = in.nextInt();

cost = calculateCost(pounds, days);

System.out.println("Total is : " + cost);
}
}

3.

public class FahrenheitToCelsius
   {
       public static void main(String[] args)
           {
               double tempFahrenheit;
               String temps;
               temps = JOptionPane.showInputDialog(null, "Please enter the patients temperature in fahrenheit?",
               "PATIENTS TEMPERATURE", JOptionPane.QUESTION_MESSAGE);
               tempFahrenheit = Double.parseDouble(temps);
               double tempCelsius = (tempFahrenheit - 32) / 1.8;
               JOptionPane.showMessageDialog(null, "The patients temperature in celsius is " + tempCelsius + ".",
               "CELSIUS TEMPERATURE", JOptionPane.PLAIN_MESSAGE);
           }
   }

4.

public class ShowStudent {
public static void main(String[] args) {
Student[] students = new Student[5];

// Generate/build a list of dummy student objects for testing
students[0] = new Student(101, 3, 12);
students[1] = new Student(102, 3, 9);
students[2] = new Student(103, 3, 6);
students[3] = new Student(104, 3, 3);
students[4] = new Student(105, 3, 0);

display(students);
System.exit(0);
}

/*
* Display students GPA result
* @param students a list of student objects
*/
private static void display(Student[] students) {
System.out.printf("ID GPA %n");
for (int i = 0; i < students.length; i++) {
System.out.printf("%s GPA=%,.2f%n", students[i].getIdNumber(), students[i].getGradePointAverage());
}
}
}

/**
* Student represents student object
*/
class Student {
private int idNumber;
private int numberOfCreditHour;
private int numberOfPoint;

public Student(int idNumber, int numberOfCreditHour, int numberOfPoint) {
setIdNumber(idNumber);
setNumberOfCreditHour(numberOfCreditH...
setNumberOfPoint(numberOfPoint);
}

public int getIdNumber() {
return idNumber;
}

public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}

public int getNumberOfCreditHour() {
return numberOfCreditHour;
}

public void setNumberOfCreditHour(int numberOfCreditHour) {
this.numberOfCreditHour = numberOfCreditHour;
}

public int getNumberOfPoint() {
return numberOfPoint;
}

public void setNumberOfPoint(int numberOfPoint) {
this.numberOfPoint = numberOfPoint;
}

/**
* Calculate grade point average, based on number of credit hour and number of point earned.
* @return double grade point average
*/
public double getGradePointAverage() {
if (numberOfPoint == 0 || numberOfCreditHour == 0)
return 0;
return (double) numberOfPoint / numberOfCreditHour;
}
}

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