Following the examples of listing 9.8 and 9.9 in Section 9.9 in the textbook, write a program in Java to compute the following properties of automobiles: average gas mileage, lowest price, the lates

CS216 Assignment 1(Chapter 9)

Problem 1 (A) [5 points]:

Following the examples of listing 9.8 and 9.9 in Section 9.9 in the textbook, write a program in Java to compute the following properties of automobiles: average gas mileage, lowest price, the latest model. The program must have the following:

  • A class named Automobile,

  • One constructor function that initializes the model year only.

  • A method to set the gas mileage and price for the object variables.

  • Three separate methods to compute the results (average gas mileage, lowest price, latest model) and show the outputs.

  • The Main function will stay in another class from where the constructors and all other methods will be invoked through three objects named: sedan, minivan, and truck.

  • Inputs are to be taken inside the Main function from the keyboard. The program will show the outputs on the screen.

Sample Input (from keyboard):

Enter the model year for sedan: 2012

Enter the gas mileage for sedan: 35

Enter the price for sedan: 20000

Enter the model year for minivan: 2013

Enter the gas mileage for minivan: 26

Enter the price for minivan: 18000

Enter the model year for truck: 2010

Enter the gas mileage for truck: 21

Enter the price for truck: 17000


Sample Output (on screen):

Avg gas mileage: 27.33

Lowest price: 17000

Latest model: 2013

Problem 1 (B) [5 points]:

Following the example “Array of Objects” (attached to this assignment), modify the problem 1 (A) by creating an array of three objects. Rests of the functionalities, I/O, remain unchanged.

Problem 2:

Create a Person class

Following the examples of listing 9.8 and 9.9 in Section 9.9 in the textbook, create a Person class that has private name and age fields (member variables). Both fields should have associated getter methods and should be set by a constructor when the object is created.

Problem 2 (A) [5 points]:

Following the examples of listing 9.8 and 9.10 in Section 9.10 in the textbook, create a new method (not in the Person class) that takes a Person and an age and prints a message indicating whether the person is at least that old.

Sample Input:

Person p1 = new Person (“Alice”, 23);

checkage (p1, 17);


Person p2 = new Person (“Trudy”, 47);

checkage (p2, 50);


Person p3 = new Person (“Jonathan”, 35);

checkage (p3, 35);

Sample Output:

Alice is at least 17 years old!

Trudy is not yet 50 years old.

Jonathan is at least 35 years old!

Problem 2 (B) [5 points]:

Following the examples of listing 9.8 and 9.11 in Section 9.11 in the textbook, create a new method (NOT in the Person class) that searches through an array of Person objects and prints the name of the oldest one.

Sample Input (from keyboard):

Person [] people = new Person[] {

new Person(“Alice”, 23),

new Person(“Trudy”, 47),

new Person(“Jonathan”, 35),

};

printOldest(people);

Sample Output (on screen):

Trudy is the oldest.

Submission:

This assignment is to be submitted through Canvas (upload one zipped file in Canvas which will contain all the files (codes for problems 1 and 2 (A and B)) and a screenshot of the output for each problem).

Grading Rubric:

This is the standard grading rubric that will be followed. You do NOT need to worry about the code efficiency part of this rubric for this assignment, but please make sure your program runs correctly.Following the examples of listing 9.8 and 9.9 in Section 9.9 in the textbook, write a program in  Java to compute the following properties of automobiles: average gas mileage, lowest price, the  lates 1