Instructions:  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.  9. Add your code to a package, called “assignment1” 10. Include a clear screenshot of your code and the output.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Instructions:
 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.
 9. Add your code to a package, called “assignment1”
10. Include a clear screenshot of your code and the output.
package people;
public class Person{ private String name; private int age;
public Person() { name = "no name"; age = -1;
}
public Person(String name, int age) { this.name = name;
 this.age = age; }
public String getName() { return name;
}
public void setName(String n) {
name = n; }
public void setAge(int a) { age = a;
}
public int getAge() { return age;
} }

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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY