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.
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
+](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F67f0ecc6-4dca-430f-982e-3dab6e601dcb%2F6d6efb9e-dde2-4df9-9cd3-701cecbec525%2Fpopcm9j_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)