Question

In: Computer Science

Note: Anwer this as mention in the Question and do it urgently ( just simple uml...

Note: Anwer this as mention in the Question and do it urgently ( just simple uml of dry run kindly please fo fast)

Q1: Test the follow code step by step from the main. Add enough detail to justify the use of OOP concepts in these examples. Also draw the UML diagram using all given code. Finally show the output of this code [Note: Only output will not acceptable]


public class Person
{
private String name;
public Person()
{
name = "none";
}
public Person(String theName)
{
name = theName;
}
public Person(Person theObject)
{
name = theObject.name;
}
public String getName()
{
return name;
}
public void setName(String theName)
{
name = theName;
}
public String toString()
{
return name;
}
public boolean equals(Object other)
{
return name.equals(((Person)other).name);
}
}
public class Vehicle
{
private String mf;
private int cd;
private Person own;
public Vehicle()
{
mf = "none";
cd = 1;
own = null;
}
public Vehicle(String themf, int numcd, Person theown)
{
mf = themf;
cd = numcd;
own = new Person(theown);
}
public Vehicle(Vehicle other)
{
mf = other.mf;
cd = other.cd;
own = new Person(other.own);
}
public void setmf(String newmf)
{
mf = newmf;
}
public void setcd(int newNum)
{
cd = newNum;
}
public void setown(Person newown)
{
own = new Person(newown);
}
public String getmf()
{
return mf;
}
public int getcd()
{
return cd;
}
public Person getown()
{
return own;
}
public String toString()
{
return mf + ", " + cd + " cd, owned by " + own;
}
public boolean equals(Vehicle other)
{
return mf.equals(other.mf) && cd == other.cd;
}
}
public class Truck extends Vehicle
{
private double load;
public int capacity;
public Truck()
{
super();
load = 0;
capacity = 0;
}
public Truck(String m, int c,
Person p, double loads,
int capc)
{
super(m, c, p);
load = loads;
capacity = capc;
}
public Truck(Truck oth)
{
super(oth);
load = oth.load;
capacity = oth.capacity;
}
public void setload(double newLoad)
{
load = newLoad;
}
public void setcapacity(int newCaps)
{
capacity = newCaps;
}
public double getload()
{
return load;
}
public int getcapacity()
{
return capacity;
}
public String toString()
{
return super.toString() + ", " + load + " lbs load, " + capacity + " tow";
}
public boolean equals(Truck oth)
{
return super.equals(oth) &&
load == oth.load &&
capacity == oth.capacity;
}
}
public class CompleteTest
{
public static void main(String args[])
{
Person owner1 = new Person("Nathan Roy");
Person owner2 = new Person("Peter England");
Vehicle aCar = new Vehicle("Honda", 5, owner2);
Truck aTruck = new Truck();
aTruck.setmf("Skoda");
aTruck.setcd(100);
aTruck.setown(owner1);
aTruck.setload(150.50);
aTruck.setcapacity(3200);
System.out.println("Truck Details: ");
System.out.println(aTruck.getmf());
System.out.println(aTruck.getcd());
System.out.println(aTruck.getown());
System.out.println(aTruck.getload());
System.out.println(aTruck.getcapacity());
System.out.println();
System.out.println("Details of Vehicle 1: ");
System.out.println(aCar);
System.out.println("Details of Vehicle 2: ");
System.out.println(aTruck);
}
}

Solutions

Expert Solution

Code

with commnetns

Person class


public class Person {
//instace varibale type String that stores the name of Person
private String name;
//default constructor that set name to none
public Person()
{
name = "none";
}
//parameterize constructor that set the name as give in parameter
public Person(String theName)
{
name = theName;
}
//copy constructor that assing the name of theObject to the this name
public Person(Person theObject)
{
name = theObject.name;
}
//getter method for name
public String getName()
{
return name;
}
//setter method for name taht set the name
public void setName(String theName)
{
name = theName;
}
//toString method that return the name of person
public String toString()
{
return name;
}
//equals method that check this and other object are same or name
public boolean equals(Object other)
{
return name.equals(((Person)other).name);
}
}

Vehicle class

public class Vehicle {
//properteis of Vehicle
private String mf;//
private int cd;
private Person own;
//default constructor for Vehicle that sets default value
public Vehicle()
{
mf = "none";
cd = 1;
own = null;
}
//patametrize constructor
public Vehicle(String themf, int numcd, Person theown)
{
mf = themf;
cd = numcd;
own = new Person(theown);
}
//copy constructor
public Vehicle(Vehicle other)
{
mf = other.mf;
cd = other.cd;
own = new Person(other.own);
}
//setter method
public void setmf(String newmf)
{
mf = newmf;
}
public void setcd(int newNum)
{
cd = newNum;
}
public void setown(Person newown)
{
own = new Person(newown);
}
//getter methods
public String getmf()
{
return mf;
}
public int getcd()
{
return cd;
}
public Person getown()
{
return own;
}
//toString method that return the string with properties of vehicle
public String toString()
{
return mf + ", " + cd + " cd, owned by " + own;
}
//equals method that check fo equality of vehicle
public boolean equals(Vehicle other)
{
return mf.equals(other.mf) && cd == other.cd;
}
}

Truck class


public class Truck extends Vehicle{
//instance varibales of Vehicle
private double load;
public int capacity;
//default constructor
public Truck()
{
super();
load = 0;
capacity = 0;
}
//parameterize constructor
public Truck(String m, int c,Person p, double loads,int capc)
{
super(m, c, p);
load = loads;
capacity = capc;
}
//copy constructor
public Truck(Truck oth)
{
super(oth);
load = oth.load;
capacity = oth.capacity;
}
//set methods for propertise of vehicle
public void setload(double newLoad)
{
load = newLoad;
}
public void setcapacity(int newCaps)
{
capacity = newCaps;
}
//get methods for propertise of vehicle
public double getload()
{
return load;
}
public int getcapacity()
{
return capacity;
}
//tostring method
public String toString()
{
return super.toString() + ", " + load + " lbs load, " + capacity + " tow";
}
//equal for checking equality
public boolean equals(Truck oth)
{
return super.equals(oth) &&
load == oth.load &&
capacity == oth.capacity;
}
}

CompelteTest


public class CompleteTest {

public static void main(String[] args) {
//creates the two object of the class person with parameterize constructor
Person owner1 = new Person("Nathan Roy");
Person owner2 = new Person("Peter England");
//creater a vehicle object with parameterize constructor
Vehicle aCar = new Vehicle("Honda", 5, owner2);
//crates a object of Truck object wirh default constructor
Truck aTruck = new Truck();
//sets all the properties of Truck using setters methods
aTruck.setmf("Skoda");
aTruck.setcd(100);
aTruck.setown(owner1);
aTruck.setload(150.50);
aTruck.setcapacity(3200);
  
System.out.println("Truck Details: ");
System.out.println(aTruck.getmf());
System.out.println(aTruck.getcd());
System.out.println(aTruck.getown());
System.out.println(aTruck.getload());
System.out.println(aTruck.getcapacity());
System.out.println();
System.out.println("Details of Vehicle 1: ");
System.out.println(aCar);
System.out.println("Details of Vehicle 2: ");
System.out.println(aTruck);
}
  
}

Output

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

Uml Diagram

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

From the book Life on the Edge by James Dobson, anwer this question please. 1. Of...
From the book Life on the Edge by James Dobson, anwer this question please. 1. Of the topics discussed, which ones do you see presenting the greatest challenge for you, and why?
I just want a simple example for each one of the following. But please DO NOT...
I just want a simple example for each one of the following. But please DO NOT copy from anywhere. 1. Ignoring Nonmonetary Costs 2. failing to Ignore Sunk Costs 3. Being Unrealistic about Future Behavior. Those are three common mistakes that behavioral economics says consumers often make. DO NOT COPY,
Kindly solve urgently. You have just been hired as a new management trainee by Earrings Unlimited,...
Kindly solve urgently. You have just been hired as a new management trainee by Earrings Unlimited, a distributer of earnings to various retail outlets located in shopping malls across the country. In the past, the company has done very little in the way of budgeting and at a certain times of the year has experienced a shortage of cash. Since you are well trained in budgeting, you have decided to prepare a comprehensive budgets for the upcoming second quarter in...
Question (5) [12 Marks] Note: Do not use R, do the calculations by hand. A very...
Question (5) [12 Marks] Note: Do not use R, do the calculations by hand. A very large (essentially infinite) number of butterflies is released in a large field. Assume the butterflies are scattered randomly, individually, and independently at a constant rate with an average of 6 butterflies on a tree. (a) [3 points] Find the probability a tree (X) has > 3 butterflies on it.   (b) [3 points] When 10 trees are picked at random, what is the probability 8...
1.24 Note this is a computational question. Note there are two parts in the question. Clearly...
1.24 Note this is a computational question. Note there are two parts in the question. Clearly type out your answers to each subpart of the question. Show your steps. Hong Kong Telecom asked you to assess its internal control system. After careful review, you believed that Hong Kong Telecom has serious flaws in their internal control system. You estimated that the impact associated with this problem is $20 million and that the likelihood is currently 9%. Three procedures can be...
NOTE:- you have to refer the 10k report to do this question (the link is given...
NOTE:- you have to refer the 10k report to do this question (the link is given below).. there is no separate data given. Part 1 Using the 10K report for the firm you are analyzing, calculate your estimate of the weighted average cost of capital for the firm. Please justify your response and document all calculations. 10K report link : go to: https://investor.textron.com/investors/investor-resources/annual-report-and-proxy-materials/default.aspx , scroll down and "select 2016 annual report PDF" direct link to the 10k report : https://s1.q4cdn.com/535492436/files/doc_financials/2016/Textron-AR2016-compiled.pdf...
Question 4 (Please note that you do NOT need to write a scientific answer to the...
Question 4 (Please note that you do NOT need to write a scientific answer to the question in bold below. Simply use the question to demonstrate your ability to break down a question into its key parts. Write your answers in the spaces indicated below) For the question below, identify the a) key topic word, b) the influencer words and c) the instruction words. Describe the major structural differences between Arachnids and Crustaceans and explain how their mouthparts work.
I just wanna ask a simple question, but i need some explanation about it. What is...
I just wanna ask a simple question, but i need some explanation about it. What is the Physical quantities (Probably Wavelength or something like that) that causes every people has their own unique sound? Not Frequency Right? Because if frequency, people can just adjust their sound to make their frequency same with other people sound.
You were offered the opportunity to purchase either a simple interest note or a simple discount...
You were offered the opportunity to purchase either a simple interest note or a simple discount note with the following terms: $37,172 at 10% for 6 months. a. Calculate the effective interest rate. (Do not round intermediate calculations. Round your final answer to the nearest tenth percent.) Effective interest rate             % b. Based on the effective interest rate, which would you choose? simple interest note simple discount note
You were offered the opportunity to purchase either a simple interest note or a simple discount...
You were offered the opportunity to purchase either a simple interest note or a simple discount note with the following terms: $38,485 at 7% for 36 months. a. Calculate the effective interest rate
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT