Person.java
public class Person {
private String name;
public Person()
{
name = "No name yet.";
}
public Person(String initialName)
{
name = initialName;
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void writeOutput()
{
System.out.println("Name: " +
name);
}
public boolean hasSameName(Person otherPerson)
{
return
(this.name.equalsIgnoreCase(otherPerson.getName()));
}
}
Vehicle.java
public class Vehicle {
private String manufacturerName;
private int numberOfCylinders;
private Person owner;
//default constructor
public Vehicle()
{
manufacturerName = "No name
yet.";
numberOfCylinders = 0;
owner = new Person();
}
//parameterized constructor
public Vehicle(String mName, int nCylinders, String
ownerName)
{
manufacturerName = mName;
numberOfCylinders =
nCylinders;
owner = new
Person(ownerName);
}
//accessors
//method that sets manufacturer's name
public void setManufacturerName(String mName)
{
manufacturerName = mName;
}
//method that sets number of cylinders
public void setNumberOfCylinders(int nCylinders)
{
numberOfCylinders =
nCylinders;
}
//method that sets owners name
public void setOwner(String name)
{
owner.setName(name);
}
//method that gets manufacturer's name
public String getManufacturerName()
{
return manufacturerName;
}
//method that gets number of cylinders
public int getNumberOfCylinders()
{
return numberOfCylinders;
}
//method that gets owners name
public String getOwner()
{
return owner.getName();
}
//equals method
public boolean equals(Vehicle otherVehicle)
{
if((this.manufacturerName.equalsIgnoreCase(otherVehicle.getManufacturerName()))
&& (this.numberOfCylinders ==
otherVehicle.getNumberOfCylinders()) &&
(this.getOwner().equalsIgnoreCase(otherVehicle.getOwner())))
return
true;
else
return
false;
}
//method that prints the Vehicle information
public void printVehicle()
{
System.out.println("Manufacturer's
Name: " + getManufacturerName());
System.out.println("Number of
cylinders in engine: " + getNumberOfCylinders());
System.out.println("Owner's Name: "
+ getOwner());
}
}
Truck.java
public class Truck extends Vehicle {
private double loadCapacity;
private double towingCapacity;
//default constructor
public Truck()
{
super();
loadCapacity = 0.0;
towingCapacity = 0.0;
}
//parameterized constructor
public Truck(String mName, int nCylinders, String
ownerName, double lCapacity, double tCapacity)
{
super(mName, nCylinders,
ownerName);
loadCapacity = lCapacity;
towingCapacity = tCapacity;
}
//method that sets load capacity
public void setLoadCapacity(double lCapacity)
{
loadCapacity = lCapacity;
}
//method that sets towing capacity
public void setTowingCapacity(double tCapacity)
{
towingCapacity = tCapacity;
}
//method that gets load capacity
public double getLoadCapacity()
{
return loadCapacity;
}
//method that gets towing capacity
public double getTowingCapacity()
{
return towingCapacity;
}
//method that display truck information
public void printTruck()
{
printVehicle();
System.out.println("Load Capacity:
" + loadCapacity);
System.out.println("Towing
Capacity: " + towingCapacity);
}
//equals method
public boolean equals(Truck otherTruck)
{
if(getManufacturerName().equalsIgnoreCase(otherTruck.getManufacturerName())
&&
(getNumberOfCylinders() == otherTruck.getNumberOfCylinders())
&&
(getOwner().equalsIgnoreCase(otherTruck.getOwner()))
&&
this.getLoadCapacity() == otherTruck.getLoadCapacity() &&
this.getTowingCapacity() == otherTruck.getTowingCapacity())
return
true;
else
return
false;
}
}
TestVehicle.java
public class TestVehicle {
public static void main(String[] args) {
//create two objects for vehicle
class
Vehicle v1 = new Vehicle("Ford", 2,
"Shreyas");
Vehicle v2 = new Vehicle("Ford", 2,
"Chandan");
//display the vehicle
information
System.out.println("Vehicle-1:");
v1.printVehicle();
System.out.println("Vehicle-2:");
v2.printVehicle();
//check if both the vehicles are
equal
if(v1.equals(v2))
System.out.println("Both vehicles are equal");
else
System.out.println("Both vehicles are not equal");
//create two objects for Truck
class
Truck t1 = new Truck ("Mahindra",
4, "Shreyas", 225, 125);
Truck t2 = new Truck ("Mahindra",
4, "Shreyas", 225, 125);
//display the Truck
information
System.out.println("\n\nTruck-1:");
t1.printVehicle();
System.out.println("Truck-2:");
t2.printVehicle();
//check if both the Trucks are
equal
if(t1.equals(t2))
System.out.println("Both trucks are equal");
else
System.out.println("Both trucks are not equal");
}
}
Output:
![= E Console X x | = EH EH = = = = = <terminated TestVehicle [Java Application] C:\Program Files Vava jre1.8.0_151\bin\javaw.e](http://img.homeworklib.com/questions/c232e210-b02e-11ea-905c-a3fd0c7237a3.png?x-oss-process=image/resize,w_560)
Code Screenshots:






![Person.java Vehicle.java Truck.java TestVehicle.java X 2 public class TestVehicle { public static void main(String[] args) {](http://img.homeworklib.com/questions/c4e959b0-b02e-11ea-8109-2f4eb0615089.png?x-oss-process=image/resize,w_560)
Required in Java. Thank you. 1. Create a base class called Vehicle that has the manufacturer's...
Java: Create a class called Vehicle with the following features: a. It has three private data members (instance variables): one is the manufacturer’s name (String manufacturer), the second is the number of cylinders in the engine (int cylinder), and the third is the owner (Person owner). The class Person is described above. b. It has three constructors, a no-argument constructor, a constructor with three parameters, and a copy constructor. The no-argument constructor will set the manufacturer to “None”, cylinder to...
In Java*
Please implement a class called "MyPet". It is designed as shown
in the following class diagram.
Four private instance variables: name (of the type String),
color (of the type String), gender (of the type char) and weight(of
the type double).
Three overloaded constructors:
a default constructor with no argument
a constructor which takes a string argument for name, and
a constructor with take two strings, a char and a double for
name, color, gender and weight respectively.
public...
Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...
In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...
I need the following code to keep the current output but also include somthing similar to this but with the correct details from the code. Truck Details: Skoda 100 Nathan Roy 150.5 3200 Details of Vehicle 1: Honda, 5 cd, owned by Peter England Details of Vehicle 2: Skoda, 100 cd, owned by Nathan Roy, 150.5 lbs load, 3200 tow --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- class Person { private String name; public Person() { name="None"; } ...
Implement the following class in Java: Class name: People Constructor Summary: public People (String name) Methods: public People(String name) public void setName(String name) public String getName() Class name: Truck Constructor Summary: public Truck (int licensePlate, int onBoard, People people) Initially, the truck does not contain any on board the vehicle. If the number of people on board the vehicle is a negative number, the value of onBoard should be stored as zero. Methods: public int getLicensePlate() Returns license plate of...
Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store { public final double SALES_TAX_RATE = 0.06; private String name; /** * Constructor to create a new store * @param newName */ public Store(String newName) { name = newName; } ...
// Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...
JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...
Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...