|
Read the post. OP doesn't, management does.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Are you in a position to question this choice? If you are a Microsoft house, it may be better to stay that way unless there is good reason. Jumping from VB6 is a good start anyway. Whatever the new language used, a complete re-write is a better choice. That way you can work around bad decisions, there always are, made in the original system.
As for Java IDE's, it really is your choice. The two most popular are Netbeans and Eclipse, and I'd choose one of them. My personal recomendation is Netbeans but that is because I use it and am familiar with the way it works.
Have a look at the Java tutorials on oracle.com. Then buy some books and put them on expenses.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
I have to say that moving from VB6 to Java seems like an unusual choice, VB.NET or C# seems like a more natural progression, but I guess there is a reason in there somewhere. Maybe the idea is to make the server-side platform independent?
"Less organised" could also be read as "more choice" and I think that is your problem: you will find yourself overwhelmed with choice. I can list the leading frameworks in the various areas, but I can't recommend any in particular because I have no idea what sort of application you are building or what your requirements are. So I'm not going to say that any one is better than the others.
For the web front end you could either look at something like GWT or ZK, or something like SpringMVC or Wicket. There are other frameworks like Seam or Grails that may get you started quicker, but I'm not sure how widely used they are in the real world. JSF might seem a little complicated for someone new to the Java world, but it is part of the JEE standard so should be on the list to consider. And of course, you could always just roll your own with JSPs and servlets.
For the data access layer, you could look at EJB, JPA (without EJB), Hibernate, MyBatis, or straight JDBC (lots of people still do this despite the fact that ORMs get so much press).
Spring is very popular in the Java world (although a significant minority are against it for various reasons). I would at least consider it, and look beyond the Dependency Injection features to see what else it might give you. If you want DI but don't like Spring, take a look at Guice.
In terms of IDEs, the big three are Eclipse, NetBeans and IntelliJ. Various people will argue strongly for their own personal favourite, but the truth is that they're all pretty much on a level these days and it's just a matter of taste as to which you prefer.
Test frameworks: JUnit is almost universal and could be considered a de facto standard in the Java world. Some people use NGTest (which does have some nicer features than JUnit) but is less common so I would stick with JUnit simply because every Java programmer you ever hire will have heard of it.
Then there are some build tools that you should at least look at: Maven vs. Ant, Hudson/Jenkins vs. Continuum.
|
|
|
|
|
Thanks for all these replies they are helpful.
We were going down the .NET route, for the extact reasons pointed out, its new but its more familiar as well And we are questioning this decision, we're a satellite office and pretty self contained, so not following the main mass isn't that usual...we have seperate dev and test domains, they dont for example.
We currently support a large number of Access 97 databases run across teams! And afaik Java (like .NET) has no equivelent (SQL Compact is local install only, and everything else needs servers) The VB6 progs are a little easier, mainly they are front-ends to SQL Server databases.
|
|
|
|
|
cjb110 wrote: We currently support a large number of Access 97 databases run across teams!
Meaning multiple users (multiple applications) accessing a single database?
I have seen reports that this isn't a good idea. I haven't seen anyone suggest that language choice mattered with that either.
cjb110 wrote: And afaik Java (like .NET) has no equivelent (SQL Compact is local install only, and everything else needs servers)
Huh? No equivalent to what exactly? You can use MS Access from java if that is what you are asking.
And you can certainly use SQL Server as well. The type of SQL Server has nothing to do with it. Although if you wanted a single user embedded database then you could use Derby.
|
|
|
|
|
cjb110 wrote: And afaik Java (like .NET) has no equivelent (SQL Compact is local install only, and everything else needs servers)
I have absolutely no idea what that means. Java can use local (embedded) databases, or it can talk to databases located on a central server. Is that what you mean?
|
|
|
|
|
cjb110 wrote: From previous research it seems that Java is little less organised, there being a number of IDE's/UI widgets/test
Choice/options != "less organized".
Far as I can tell frameworks are also better. There is a reason things like nant, log4net, nunit, nHibernate and Spring.net exist. Because they all existed in java first. (And far as I am concerned there are no good logging options in .Net because log4net does not have a large participant base or maybe even no participant base.)
And I certainly haven't seen anything that I would say is comparable to the JEE servers in .Net land. IIS just doesn't seem comparable.
|
|
|
|
|
Question asks:
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.
These are a few of my 6 classes and a driver. I don't get it how to check the attributes. I can check one but i am not sure how to check it the way it is required by the question.
Vehicule class
package Package1;
public class Vehicule {
protected String fuelT;
protected double consum;
protected int price;
public Vehicule ()
{
fuelT = "";
consum = 0.0;
price = 0;
}
public Vehicule(String f, double c, int p)
{
this.fuelT = f;
this.consum = c;
this.price = p;
}
public String toString()
{
return "This Vehicule is a " + fuelT
+ ", consumes " + consum + "liters/100km and costs $"
+ price + ".";
}
public String getfuel()
{
return fuelT;
}
public boolean equals(Vehicule e)
{
boolean ans;
if(this.fuelT == e.fuelT )
ans = true;
else
ans = false;
return ans;
}
}
Car Class
package Package2;
import Package1.Vehicule;
public class Car extends Vehicule {
protected String carBrand;
protected String carMake;
protected int year;
public Car()
{
super();
carBrand = "";
carMake = "";
year = 0;
}
public Car(String b, String m, int y, String f, double c, int p)
{
super (f,c,p);
this.carBrand = b;
this.carMake = m;
this.year = y;
}
public String toString()
{
return "This Car is a " + fuelT
+ ", consumes " + consum + "liters/100km and costs $"
+ price + ". It is a " + year + " " + carBrand
+ " " + carMake + ".";
}
}
FamilyCar:
package Package2;
public class FamilyCar extends Car{
public enum CarType {Sedan, Van, Suv};
private int maxPass;
private CarType value;
public FamilyCar ()
{
super();
maxPass = 0;
value = null;
}
public FamilyCar (int mp, CarType value, String b,
String m, int y, String f, double c, int p)
{
super(b,m,y,f,c,p);
this.maxPass = mp;
this.value = value;
}
public String toString()
{
return "This Family Car is a " + fuelT
+ ", consumes " + consum + "liters/100km and costs $"
+ price + ". It is a " + year + " " + carBrand
+ " " + carMake + ". It is a " + value + " which can accommodate "
+ maxPass + " passengers.";
}
}
Driver Class:
import Package1.Vehicule;
import Package2.Car;
import Package2.FamilyCar;
import Package2.FamilyCar.CarType;
import Package2.SportsCar;
import Package3.Truck;
import Package3.Truck.TruckType;
import Package4.Bus;
import Package4.Bus.BusType;
public class Driver {
public static void main(String[] args) {
CarType ct = null;
TruckType tt = null;
BusType bt = null;
Vehicule vTest = new Vehicule("Hybrid", 1.9, 12000);
System.out.println(vTest);
Car cTest = new Car("Honda", "Civic", 2009, "Unleaded", 2.8, 13000);
System.out.println(cTest);
FamilyCar fTest = new FamilyCar(7, ct.Sedan, "Honda", "Odessey",
2009, "Unleaded", 2.8, 13000);
System.out.println(fTest);
SportsCar sTest = new SportsCar(false, 250, "Mazda", "Rx8", 2004,
"Unleaded", 1.5, 15000);
System.out.println(sTest);
Truck tTest = new Truck(tt.Tank, "Diesel", 1.2, 10000);
System.out.println(tTest);
Bus bTest = new Bus(bt.city, "Hybrid", 4.0, 25000);
System.out.println(bTest);
System.out.println(vTest.equals(fTest));
}
}
|
|
|
|
|
equals() does compare the objects and returns true if so.
You've done it right in the class Vehicule. You just need to compare also the rest of the fields:
EDIT: I added super.equals(object) to get also the fields of the extended object compared.
public boolean equals(Vehicule e) {
boolean ans;
if(true == super.equals(e) &&
this.fuelT == e.fuelT &&
this.consum == e.consum &&
this.price == e.price ){
return true;
}
return ans;
}
You should implement it in a similar way into the other classes.
Also are accessors and mutators missing as they are demanded. Would be nice if you use them in the equals() methods.
AND: Vehicle is written without U - but that's just a style thingy.
regards Torsten
I never finish anyth...
|
|
|
|
|
TorstenH. wrote: this.fuelT == e.fuelT
Fail. Stay after class and write out 100 times, "I will not compare Strings by reference".
|
|
|
|
|
*args* I knew it wouldn't be a good day - but that bad?
regards Torsten
I never finish anyth...
|
|
|
|
|
how can i use the accessors and mutators. I think i am wrong with this but can you please check.
public String getfuel()
{
return this.fuelT;
}
public double getconsum()
{
return this.consum;
}
public int getprice()
{
return this.price;
}
public String setfuel()
{
return this.fuelT;
}
|
|
|
|
|
The accessor method returns the member variable value and mutator [never heard it called that] sets the value.
As a guide the structure is always the same and they [usually] exist in pairs. If a variable is immutable then it must be initialised via the constructor and no setter [mutator] method exists.
class Foo {
private Bar bar;
public Bar getBar() {
return this.bar;
}
public void setBar(Bar nar) {
this.bar = bar;
}
}
You will need something like:
public String getFuelType() {
return this.fuelType;
}
public double getConsumption() {
return this.consumption;
}
public int getPrice() {
return this.price;
}
public void setFuelType(String fuelType) {
this.fuelType = fuelType;
}
public void setConsumption(double consumption) {
this.consumption = consumption;
}
public void setPrice(int price) {
this.price = price;
}
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
I really don't get the point on how this will help us in the equals. Sorry i am really lost and panicking so can't even think right since this assignment is due in 12 hours from now and i am hardly done.
|
|
|
|
|
The getters aren't there for the other methods but are there for external classes.
I would encourage the use of getters and setters over direct member variable access as it is a safer approach in most cases.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
can yo give me a little part of the equals using the accessor and mutator., i don't understand please .
|
|
|
|
|
There is a simple style for equals you should learn, for Vehicule it should be:
public boolean equals(Object obj) {
if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
final Vehicule other = (Vehicule) obj;
return this.fuelT.equals(other.fuelT) &&
this.consum == other.consum &&
this.price == other.price;
}
If you override equals , you should always override hashcode , use the same attributes as are compared in equals :
public int hashCode() {
int hash = 7;
hash = 47 * hash + (this.fuelT != null ? fuelT.hashcode() : 0);
hash = 47 * hash + (Double)this.consum.hashCode();
hash = 47 * hash + this.price;
return hash;
}
The methods must match so that if they are equal, they should have the same hash code, but the same hash code does not mean two objects are equal.
Similarly if you need to implement Comparable, then the compareTo method must match equals so that if two objects are equal then compareTo returns 0 and if comapreTo is non-zero then the objects are not equal.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
we haven't learned hash yet.
|
|
|
|
|
Equals and hashCode should be taught together.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
I really need help with my assignment for java. Please give me a little push start with this assignment. I am really bad with getting the concept of the arrays. Please give me the starting part for a couple of classes and the driver class. Once i get started i am sure i can figure it out.
Please check this assignment file and I would appreciate whatever help you guys give me.
Assignment pdf file can be downloaded here : http://www.2shared.com/document/pKqvuo_K/A2help.html
This is the assignment explanation in screen shots of the pdf:
http://imageshack.us/photo/my-images/525/screenshot20111006at112.png/
http://imageshack.us/photo/my-images/13/screenshot20111006at112.png/
http://imageshack.us/photo/my-images/441/screenshot20111006at112.png/
I tried to start this but i am not sure if i need to use arrays in the classes and how to use them.
Vehicule class:
package Package1;
public class Vehicule {
String fuelT;
double consum;
int price;
public Vehicule ()
{
fuelT = "";
consum = 0.0;
price = 0;
}
public Vehicule(String f, double c, int p)
{
this.fuelT = f;
this.consum = c;
this.price = p;
}
}
Car class:
package Package2;
import Package1.Vehicule;
public class Car extends Vehicule {
private String carBrand;
private String carMake;
private int year;
public Car()
{
carBrand = "";
carMake = "";
year = 0;
}
public Car(String b, String m, int y, String f, double c, int p)
{
this.carBrand = b;
this.carMake = m;
this.year = y;
}
}
modified 6-Oct-11 11:29am.
|
|
|
|
|
First off, I'm not going to download an .exe to read your assignment, I don't think many others will either.
Secondly, you haven't saud what the problem is you are having.
Thirdly, a piece of style advice.
When you overload a method, try to make sure that the repeated functions are all in one place. For your constructors in Vehicule:
public Vehicule () {
this("", 0.0, 0);
}
Simples!
Then in Car:
public Car() {
this("","", 0, "", 0.0, 0);
}
public Car(String b, String m, int y, String f, double c, int p)
{
super(f, c, p);
this.carBrand = b;
this.carMake = m;
this.year = y;
}
Now, if you need to change something in the real constructors, you don't need to faff around in four places.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
the file is a pdf. sorry about the posting everywhere. its due tomorrow and i am off today so i can work on it. but i can't start off. the teacher says its like the last assignment with arrays used. Now i don't understand is how can i use this array concept with this inheritance. since every extended class has different parameters.
I did this last assignment with your help and others here.
last assignment:
public class Polynomial
{
private int[] coeff = new int[5];
public Polynomial()
{
coeff[0] = 0;
coeff[1] = 0;
coeff[2] = 0;
coeff[3] = 0;
coeff[4] = 0;
}
public Polynomial(int c0, int c1, int c2, int c3, int c4)
{
this.coeff[0] = c4;
this.coeff[1] = c3;
this.coeff[2] = c2;
this.coeff[3] = c1;
this.coeff[4] = c0;
}
public Polynomial(Polynomial p)
{
coeff = (int[])p.coeff.clone();
}
public int getCoeff(int i)
{
return this.coeff[i];
}
public boolean setCoeff(int pos, int num)
{
if (pos <= 4 || pos >= 0 )
{
coeff[pos] = num;
return true;
}
else
return false;
}
public String toString()
{
String s = "";
for (int c = 4; c >=0; c--)
{
if (coeff[c] !=0)
if (c != 0)
{
if (coeff[c] < 0 && c!=4)
s = s + coeff[c] + "X^" + c + " ";
if (coeff[c] > 0 && c!=4)
s = s + "+ " + coeff[c] + "X^" + c + " ";
if (c == 4)
s = s + coeff[c] + "X^" + c + " ";
}
else
{
if (coeff[c] > 0)
s = s + "+ " + coeff[c];
else
s = s + coeff[c];
}
}
return s;
}
public boolean equals(Polynomial p)
{
if ((p.coeff[4] != coeff[4]) ||(p.coeff[3] != coeff[3]) ||(p.coeff[2] != coeff[2]) ||(p.coeff[1] != coeff[1]) ||(p.coeff[0] != coeff[0]) )
return false;
return true;
}
public Polynomial add(Polynomial p)
{
return (new Polynomial(p.coeff[4]+coeff[4],p.coeff[3]+coeff[3],p.coeff[2]+coeff[2],p.coeff[1]+coeff[1],p.coeff[0]+coeff[0]));
}
public Polynomial derive()
{
return (new Polynomial(0,coeff[4]*4,coeff[3]*3,coeff[2]*2,coeff[1]));
}
public double evaluate(double x)
{
return (coeff[4] * x*x*x*x) +
(coeff[3] * x*x*x) +
(coeff[2] * x*x) +
(coeff[1] * x) +
coeff[0];
}
public int numberOfTerms()
{
int n = 0;
if (coeff[4] != 0)
n +=1;
if (coeff[3] != 0)
n +=1;
if (coeff[2] != 0)
n +=1;
if (coeff[1] != 0)
n +=1;
if (coeff[0] != 0)
n +=1;
return n;
}
}
The driver of pervious assignment
import java.util.*;
public class Driver
{
public static void main(String[] args)
{
System.out.println("*~*~*~*Program writen by *~*~*~*");
Scanner input = new Scanner(System.in);
Polynomial[] poly = new Polynomial[8];
int[] tmp = new int[5];
System.out.println("Enter a polynomial");
for(int i=0; i<5;i++)
{
System.out.print("Coefficient for X^" + i + ": ");
int coeff = input.nextInt();
tmp[i] = coeff;
}
poly[0] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
System.out.println("Enter a polynomial");
for(int i=0; i<5;i++)
{
System.out.print("Coefficient for X^" + i + ": ");
int coeff = input.nextInt();
tmp[i] = coeff;
}
poly[1] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
Random obj= new Random();
for(int i=0; i<5;i++)
{
int coeff = obj.nextInt(100);
tmp[i] = coeff;
}
poly[2] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
for(int i=0; i<5;i++)
{
int coeff = obj.nextInt(100);
tmp[i] = coeff;
}
poly[3] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
for(int i=0; i<5;i++)
{
int coeff = obj.nextInt(100);
tmp[i] = coeff;
}
poly[4] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
poly[5] = new Polynomial(poly[0].add(poly[2]));
poly[6] = new Polynomial(poly[1]);
for (int i = 0; i <= 4; i++)
{
int m = poly[6].getCoeff(i);
m *=3;
boolean b = poly[6].setCoeff(i,m);
}
poly[7] = new Polynomial(poly[4].derive());
System.out.print("Enter a double value for X: ");
double x = input.nextDouble();
for (int p = 0; p < 8; p++)
{
System.out.println("Polynomial " + p + " : " + poly[p] +
" has " + poly[p].numberOfTerms() +
" terms and evaluates to " + poly[p].evaluate(x) +
" for x = " + x);
}
for (int p = 1; p < 8; p++)
{
if ( poly[0].equals(poly[p]) )
System.out.println("Polynomial 0 and Polynomial " + p + " are equal.");
else
System.out.println("Polynomial 0 and Polynomial " + p + " are not equal.");
}
poly[5] = new Polynomial(poly[1]);
if ( poly[5].equals(poly[1]) )
System.out.println("Polynomial 5 and Polynomial 1 are now equal after the change.");
}
}
|
|
|
|
|
what a mess - where to start?
poly[0] = new Polynomial(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
that's evil. Please use:
poly[0] = new Polynomial(tmp);
and create a constructor
public Polynomial(int[] values) {
this.coeff = values;
}
than there is a neat chance for a loop as your code does several times the same thing:
8System.out.println("Enter a polynomial");
for(int i=0; i<5;i++)
{
System.out.print("Coefficient for X^" + i + ": ");
int coeff = input.nextInt();
tmp[i] = coeff;
}
poly[0] = new Polynomial(tmp);
This looks much better when done in a loop:
for(int iCount=0; iCount<=poly.length; iCount++){
for(int i=0; i<5;i++) {
System.out.print("Coefficient for X" + i + ":");
int coeff = input.nextInt();
tmp[i] = coeff;
}
poly[iCount] = new Polynomial(tmp);
}
regards Torsten
I never finish anyth...
|
|
|
|
|
I went through all this with him before. Nothing sunk in.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
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.
|
|
|
|
|