Car + MAX_Weight: double counter: int id: int weight: double mileage: long owner : Person + Car ( weight : double, mileage : long, owner : Person) + convertMeterIntoMile ( meter : double ): double + convertMileIntoMeter ( mile : double ): double + computeFuelEconomy():double + computeFuelEconomy ( consumptionRate: double):double + computeFuelEconomy( consumptionRate: double, errorRate: double): double + setWeight(weight:double):void + getWeight():double + setMileage ( mileage: long ): void + getMileage () :long

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question


1. Write a java code for the above class diagram for “Car”.
2. MAX_Weight must be a public class constant which is set to 6.4 
3. The data member “counter” must be a class member and initialized to zero
4. Use “counter” to assign a unique id for each class instance ( counter++ ) by the constructor
5. The constructor is used to initialize all the instance variables by receiving the values from the 
user. Don’t change the parameter’s names.
6. “convertMeterIntoMile” and “convertMileIntoMeter” are class methods:
a. convertMeterIntoMile: convert the reading into miles by dividing the receiving value 
by 1.62
b. convertMileIntoMeter: convert the reading into meter by multiplying the receiving 
value by 1.62
7. The method “computeFuelEconomy” must be overloaded and return a dummy calculation
8. In the main method:
a. Create an array of objects to hold five objects of class Car.
b. Add them to the array. Note that the code for class Person is included but you need to 
import it from package “people”
c. By using for-loop, check if any of the objects exceeds MAX_Weight or not, and print 
“heavy car” or light char”, accordingly.
d. Use both class methods to convert 100 km into miles and 200 miles into kilometers.
e. Using the first object in the array, call all of the computeFuelEconomy methods. 

Car
+ MAX_Weight: double
counter: int
id: int
weight: double
mileage: long
owner : Person
+ Car ( weight : double, mileage : long, owner
: Person )
+ convertMeterIntoMile ( meter : double ): double
+ convertMileIntoMeter ( mile : double ): double
+ computeFuelEconomy():double
+ computeFuelEconomy( consumptionRate: double):double
+ computeFuelEconomy( consumptionRate: double, errorRate: double):
double
+ setWeight(weight:double):void
getWeight():double
+ setMileage ( mileage: long ): void
+ getMileage () :long
+
Transcribed Image Text:Car + MAX_Weight: double counter: int id: int weight: double mileage: long owner : Person + Car ( weight : double, mileage : long, owner : Person ) + convertMeterIntoMile ( meter : double ): double + convertMileIntoMeter ( mile : double ): double + computeFuelEconomy():double + computeFuelEconomy( consumptionRate: double):double + computeFuelEconomy( consumptionRate: double, errorRate: double): double + setWeight(weight:double):void getWeight():double + setMileage ( mileage: long ): void + getMileage () :long +
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT