Click here to Skip to main content
15,895,709 members
Home / Discussions / Java
   

Java

 
GeneralRe: help: equals() method to compare the attributes Pin
mastdesi7-Oct-11 5:17
mastdesi7-Oct-11 5:17 
GeneralRe: help: equals() method to compare the attributes Pin
Nagy Vilmos7-Oct-11 7:14
professionalNagy Vilmos7-Oct-11 7:14 
QuestionPlease help with java assignment Pin
mastdesi6-Oct-11 4:43
mastdesi6-Oct-11 4:43 
AnswerRe: Please help with java assignment Pin
Nagy Vilmos6-Oct-11 5:46
professionalNagy Vilmos6-Oct-11 5:46 
GeneralRe: Please help with java assignment Pin
mastdesi6-Oct-11 6:19
mastdesi6-Oct-11 6:19 
GeneralRe: Please help with java assignment Pin
TorstenH.6-Oct-11 19:44
TorstenH.6-Oct-11 19:44 
GeneralRe: Please help with java assignment Pin
Nagy Vilmos6-Oct-11 23:31
professionalNagy Vilmos6-Oct-11 23:31 
GeneralRe: Please help with java assignment Pin
mastdesi6-Oct-11 6:33
mastdesi6-Oct-11 6:33 
Purpose: The purpose of this assignment is to allow you to practice enumerated types and inheritance. Some topics associated with inheritance are constructors, access rights, method overriding, and so on. You will also practice the creation and use of packages.

Part 1
The description of various moving vehicules is given as follows. A Vehicule class concerns itself with fuel type (String type) such as unleaded, diesel, hybrid, the consumption (double type) which is measured in liter/100km and the price (int type).
A Truck is a Vehicule that additionally concerns itself with the following: type of truck (enumeration type that can be: Flatbed, Box, Refrigerator,Tank).
A Car is a Vehicule that additionally concerns itself with the following: brand of car (String type) such as Toyota, Subaru, Ford etc., make of the car (String type) such as Tercel, Outback, etc. and year(int type).
A FamilyCar is a Car that additionally concerns itself with the following: type of family car (enumeration type that can be : Sedan, Van, SUV) and the maximum number of passengers it can hold(int type).
A SportsCar is a Car that additionally concerns itself with the following: whether it is convertible or not (Boolean type) and the maximum speed it can travel in km/hr (int type).
A Bus is a Vehicule that additionally concerns itself with the following: type of bus (enumeration type that can be: city, school, coach) and the maximum passenger capacity (int type).


You are required to:
1. Draw a UML representation for the above class hierarchy. Your representation must be accurate in terms of UML representation of the different entities and the relation between them. You are asked to use a software to draw the UML . For more information on UML refer to Section 12.1 of your textbook. No hand-writen or hand drawn diagrams accepted.
2. Write the implementation class of the above classes using inheritance and satisfying the following specifications.
a. You must have 4 different Java packages for the classes
 A package which includes the Vehicule class.
 A package which includes the Car, FamilyCar and SportsCar classes.
 A package which includes the Truck class.
 A package which includes the Bus class.
b. For each class you must have at least 2 constructors: the default constructor as well as a parametrized constructor which will accept enough parameters to initialize ALL the attributes of the created object. For example the parametrized constructor of FamilyCar class accepts 8 parameters to initialize the consumption, the fuel type, the price, the brand, make and year as well as the maximum number of passengers and the type of family car.
c. An object creation using the default constructor must trigger the default constructor of its ancestor classes. Similarly the parametrized constructor must trigger the parametrized constructors of its ancestors.
d. For each of the classes you must include at least the following methods: accessors, mutators, toString(), equals(). The last 2 methods are always being overrriden.
 The toString() method must display clear descriptions and complete information of the object. For example This Family Car is a hybrid, consumes 9.2 liters/100km and costs $25000. It is a 1998 Toyota Camry. It is a sedan which can accommodate 5 passengers.
 The equals() method returns true if all attributes of the compared objects are the same values; false otherwise.
e. For all classes other than the Vehicule class you are required to use either private or package access right. For the Vehicule class you are required to use protected access right.
f. When accessing attributes from a base class, you must take full advantage of the permitted rights. For instance, if you can directly access an attribute by name from a base class, then you must do so instead of using a public method from that base class to access the attribute.

3. Write a driver program (where the main() method is) that would utilize all of your classes. The driver class can be in a separate package or in any of the already existing four packages. In the main() method you must:
a. Create various objects from the 6 classes, and display all their information using the toString() method;
b. Test the equality of some to the created objects using the equals() method;
c. Create an array of 10 Vehicule objects and fill that array with various objects from the 6 classes (each class must have at least one entry in that array);
d. Trace that array to find the object that has the cheapest price. Display all information of that object along with its location (index) in the array.

Part 2
In this part you will be modifying your implementation from Part 1 as follows:
1. All classes must have the most restrictive (secure/protective) access rights to their attributes. Adjust your implementation from Part 1 accordingly.
2. Modify the equals() method of the classes so that the method would first check if the passed object (to compare to) is both not null and that it is of the same type of the calling object. The method would clearly return false if any of these conditions is true; otherwise all attributes of the compared objects are the same values.
3. In the driver program, you must add sufficient code to test your additions/changes.
GeneralRe: Please help with java assignment Pin
Nagy Vilmos6-Oct-11 23:58
professionalNagy Vilmos6-Oct-11 23:58 
AnswerRe: Please help with java assignment Pin
I.explore.code12-Oct-11 4:31
I.explore.code12-Oct-11 4:31 
QuestionMultilevelqueue Pin
jhencer1111085-Oct-11 12:40
jhencer1111085-Oct-11 12:40 
AnswerRe: Multilevelqueue Pin
Richard MacCutchan5-Oct-11 21:49
mveRichard MacCutchan5-Oct-11 21:49 
AnswerRe: Multilevelqueue Pin
Nagy Vilmos5-Oct-11 22:35
professionalNagy Vilmos5-Oct-11 22:35 
QuestionTroubble with "new" Pin
Tor Danielsen4-Oct-11 11:00
Tor Danielsen4-Oct-11 11:00 
AnswerRe: Troubble with "new" Pin
DaveAuld4-Oct-11 12:03
professionalDaveAuld4-Oct-11 12:03 
GeneralRe: Troubble with "new" Pin
Tor Danielsen4-Oct-11 12:28
Tor Danielsen4-Oct-11 12:28 
GeneralRe: Troubble with "new" Pin
DaveAuld4-Oct-11 13:37
professionalDaveAuld4-Oct-11 13:37 
AnswerRe: Troubble with "new" Pin
Luc Pattyn4-Oct-11 13:40
sitebuilderLuc Pattyn4-Oct-11 13:40 
AnswerRe: Troubble with "new" Pin
Nagy Vilmos4-Oct-11 21:47
professionalNagy Vilmos4-Oct-11 21:47 
AnswerRe: Troubble with "new" Pin
Richard MacCutchan4-Oct-11 21:50
mveRichard MacCutchan4-Oct-11 21:50 
AnswerRe: Troubble with "new" Pin
TorstenH.4-Oct-11 23:57
TorstenH.4-Oct-11 23:57 
GeneralRe: Troubble with "new" Pin
Nagy Vilmos5-Oct-11 0:12
professionalNagy Vilmos5-Oct-11 0:12 
GeneralRe: Troubble with "new" Pin
Richard MacCutchan5-Oct-11 0:20
mveRichard MacCutchan5-Oct-11 0:20 
GeneralRe: Troubble with "new" Pin
TorstenH.5-Oct-11 4:08
TorstenH.5-Oct-11 4:08 
GeneralRe: Troubble with "new" Pin
Richard MacCutchan5-Oct-11 4:37
mveRichard MacCutchan5-Oct-11 4:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.