Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 3.29 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package problem.six;
  6.  
  7.  
  8. class Person
  9. {
  10.     private String manufactureName;
  11.     public Person(String manugactureName)
  12.     {
  13.         manufactureName = "Name to be entered here";
  14.     }
  15.    
  16.     public void nameDeclaration(String a)
  17.     {
  18.         manufactureName = a;
  19.     }
  20.    
  21.     public String returnName()
  22.     {
  23.         return manufactureName;
  24.     }
  25.    
  26.     public void display()
  27.     {
  28.         System.out.println("The name is " + manufactureName);
  29.     }
  30.    
  31.     public boolean nameEquals(Person secondName)
  32.     {
  33.         return this.manufactureName.equalsIgnoreCase(secondName.manufactureName);
  34.     }
  35. }
  36.  
  37. class Vehicle
  38. {
  39.     private String company;
  40.     private int cylinders;
  41.     private Person owner;
  42.  
  43.     public Vehicle(String newCompany, int sumCylinder, Person newOwner)
  44.     {
  45.         cylinders = sumCylinder;
  46.         company = newCompany;
  47.         owner = newOwner;
  48.     }
  49.    
  50.     public void companyName(String newName)
  51.     {
  52.         company = newName;
  53.     }
  54.    
  55.     public void numCylinders( int newCylinders)
  56.     {
  57.         cylinders = newCylinders;
  58.     }
  59.    
  60.     public void ownerName(Person newOwner)
  61.     {
  62.         owner = newOwner;
  63.     }
  64.    
  65.     public String getCompany()
  66.     {
  67.         return company;
  68.     }
  69.    
  70.     public int getCylinders()
  71.     {
  72.         return cylinders;
  73.     }
  74.    
  75.     public Person getOwner()
  76.     {
  77.         return owner;
  78.     }
  79.    
  80.     public void display()
  81.     {
  82.         System.out.println("Company name is " + company);
  83.         System.out.println("The owners name is " + owner.returnName());
  84.         System.out.println("There are a total number of " + cylinders + " cylinders.");
  85.     }
  86.    
  87.     public boolean equalsTo(Vehicle secondVehicle)
  88.     {
  89.         return this.company.equalsIgnoreCase(secondVehicle.company);
  90.     }
  91. }
  92.  
  93. class Truck extends Vehicle
  94. {
  95.     private double loadCapacity;
  96.     private double towCapacity;
  97.    
  98.     public Truck(String company, Person owner, int cylinders, double load, double tow)
  99.     {
  100.         super(company, cylinders, owner);
  101.         loadCapacity = load;
  102.         towCapacity = tow;
  103.     }
  104.    
  105.     public void newLoad(double load)
  106.     {
  107.         loadCapacity = load;
  108.     }
  109.    
  110.     public void newTow(double tow)
  111.     {
  112.         towCapacity = tow;
  113.     }
  114.    
  115.     public boolean equalTo(Truck second)
  116.     {
  117.         return super.equals(second) && this.loadCapacity == second.loadCapacity && this.towCapacity == second.towCapacity;
  118.     }
  119.  
  120.     public void display()
  121.     {
  122.         super.display();
  123.     }
  124.    
  125. }
  126. public class ProblemSix {
  127.        
  128.     public static void main(String[] args) {
  129.        
  130.         Person luke = new Person("Luke Robinson");
  131.         Truck chevy = new Truck("Chevy Hauls", luke, 5, 4.2, 2.2);
  132.         chevy.display();
  133.         System.out.println("This is truck two: ");
  134.         Person rashad = new Person("Sherrif Rashad");
  135.         Truck ford = new Truck("Crap Hauls", rashad, 1, 2, 1.3);
  136.         ford.display();
  137.         if (chevy.equals(ford))
  138.         {
  139.             System.out.println("The two trucks are equal.");
  140.         }
  141.         else
  142.             System.out.println("The two trucks are not equal.");            
  143.              
  144.     }
  145. }