- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package problem.six;
- class Person
- {
- private String manufactureName;
- public Person(String manugactureName)
- {
- manufactureName = "Name to be entered here";
- }
- public void nameDeclaration(String a)
- {
- manufactureName = a;
- }
- public String returnName()
- {
- return manufactureName;
- }
- public void display()
- {
- System.out.println("The name is " + manufactureName);
- }
- public boolean nameEquals(Person secondName)
- {
- return this.manufactureName.equalsIgnoreCase(secondName.manufactureName);
- }
- }
- class Vehicle
- {
- private String company;
- private int cylinders;
- private Person owner;
- public Vehicle(String newCompany, int sumCylinder, Person newOwner)
- {
- cylinders = sumCylinder;
- company = newCompany;
- owner = newOwner;
- }
- public void companyName(String newName)
- {
- company = newName;
- }
- public void numCylinders( int newCylinders)
- {
- cylinders = newCylinders;
- }
- public void ownerName(Person newOwner)
- {
- owner = newOwner;
- }
- public String getCompany()
- {
- return company;
- }
- public int getCylinders()
- {
- return cylinders;
- }
- public Person getOwner()
- {
- return owner;
- }
- public void display()
- {
- System.out.println("Company name is " + company);
- System.out.println("The owners name is " + owner.returnName());
- System.out.println("There are a total number of " + cylinders + " cylinders.");
- }
- public boolean equalsTo(Vehicle secondVehicle)
- {
- return this.company.equalsIgnoreCase(secondVehicle.company);
- }
- }
- class Truck extends Vehicle
- {
- private double loadCapacity;
- private double towCapacity;
- public Truck(String company, Person owner, int cylinders, double load, double tow)
- {
- super(company, cylinders, owner);
- loadCapacity = load;
- towCapacity = tow;
- }
- public void newLoad(double load)
- {
- loadCapacity = load;
- }
- public void newTow(double tow)
- {
- towCapacity = tow;
- }
- public boolean equalTo(Truck second)
- {
- return super.equals(second) && this.loadCapacity == second.loadCapacity && this.towCapacity == second.towCapacity;
- }
- public void display()
- {
- super.display();
- }
- }
- public class ProblemSix {
- public static void main(String[] args) {
- Person luke = new Person("Luke Robinson");
- Truck chevy = new Truck("Chevy Hauls", luke, 5, 4.2, 2.2);
- chevy.display();
- System.out.println("This is truck two: ");
- Person rashad = new Person("Sherrif Rashad");
- Truck ford = new Truck("Crap Hauls", rashad, 1, 2, 1.3);
- ford.display();
- if (chevy.equals(ford))
- {
- System.out.println("The two trucks are equal.");
- }
- else
- System.out.println("The two trucks are not equal.");
- }
- }