Click here to Skip to main content
16,005,181 members
Home / Discussions / Java
   

Java

 
GeneralRe: Green Field Java Pin
Nagy Vilmos7-Oct-11 2:51
professionalNagy Vilmos7-Oct-11 2:51 
AnswerRe: Green Field Java Pin
Nagy Vilmos7-Oct-11 2:57
professionalNagy Vilmos7-Oct-11 2:57 
AnswerRe: Green Field Java Pin
David Skelly7-Oct-11 3:13
David Skelly7-Oct-11 3:13 
GeneralRe: Green Field Java Pin
cjb1107-Oct-11 3:31
cjb1107-Oct-11 3:31 
GeneralRe: Green Field Java Pin
jschell7-Oct-11 8:49
jschell7-Oct-11 8:49 
GeneralRe: Green Field Java Pin
David Skelly9-Oct-11 22:13
David Skelly9-Oct-11 22:13 
AnswerRe: Green Field Java Pin
jschell7-Oct-11 8:59
jschell7-Oct-11 8:59 
Questionhelp: equals() method to compare the attributes Pin
mastdesi6-Oct-11 17:24
mastdesi6-Oct-11 17:24 
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
Java
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
Java
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:
Java
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:
Java
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 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		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));
		
	}

}

AnswerRe: help: equals() method to compare the attributes Pin
TorstenH.6-Oct-11 19:30
TorstenH.6-Oct-11 19:30 
GeneralRe: help: equals() method to compare the attributes Pin
David Skelly6-Oct-11 22:17
David Skelly6-Oct-11 22:17 
GeneralRe: help: equals() method to compare the attributes Pin
TorstenH.7-Oct-11 0:18
TorstenH.7-Oct-11 0:18 
GeneralRe: help: equals() method to compare the attributes Pin
mastdesi7-Oct-11 4:09
mastdesi7-Oct-11 4:09 
GeneralRe: help: equals() method to compare the attributes Pin
Nagy Vilmos7-Oct-11 4:36
professionalNagy Vilmos7-Oct-11 4:36 
GeneralRe: help: equals() method to compare the attributes Pin
mastdesi7-Oct-11 5:20
mastdesi7-Oct-11 5:20 
GeneralRe: help: equals() method to compare the attributes Pin
Nagy Vilmos7-Oct-11 7:12
professionalNagy Vilmos7-Oct-11 7:12 
GeneralRe: help: equals() method to compare the attributes Pin
mastdesi7-Oct-11 8:52
mastdesi7-Oct-11 8:52 
AnswerRe: help: equals() method to compare the attributes Pin
Nagy Vilmos6-Oct-11 22:43
professionalNagy Vilmos6-Oct-11 22:43 
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 

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.