Java file
Name Dog Classes and Methods
Create a constructor that incorporates the type, breed, and name
variables (do not include topTrick).
Note: The type refers to what the breed typically does; for
example, a corgi would be a “cattle herding dog.” A Shiba Inu would
be a “hunting dog.”
Create the setTopTrick() mutator method
Dog is parent class
Corgi and Driver are subclasses
Complete the Corgi class:
Driver is subclass
then create the code:
className objectName = new className(input parameters) |
Sample output:
DOG DATA
Java is a Pembroke Welsh Corgi, a cattle herding dog.
The top trick is: ringing the bell to go outside.
The Corgi is 5 years old and weighs 38 pounds.
Dog |
type: string topTrick: string |
setTopTrick(trick:string) |
Corgi |
weight:int |
setWeight(pounds:int) |
Arrow pointing from table labeled Corgi to table labeled Dog
1st program : Parent Dog
public class Dog {
// instance variables
// constructor
// methods
// method used to print Dog information
public String toString() {
String temp = "\nDOG DATA\n" + name + " is a " + breed +
", a " + type + " dog. \nThe top trick is : " +
topTrick + ".";
return temp;
}
}
2nd program Corgi
public class Corgi extends Dog {
// additional instance variables
// constructor
public Corgi(String type, String breed, String name, int pounds, int years) {
// invoke Dog class (super class) constructor
super(type, breed, name);
weight = pounds;
age = years;
}
// mutator methods
// override toString() method to include additional dog information
@Override
public String toString() {
return (super.toString() + "\nThe Corgi is " + age +
" years old and weighs " + weight + " pounds.");
}
}
3rd program Driver (CockerSpaniel)
public class Driver extends Dog {
// additional instance variables
// constructor
public Driver(String type, String breed, String name, int pounds, int years) {
// invoke Dog class (super class) constructor
super(type, breed, name);
weight = pounds;
age = years;
}
// mutator methods
// override toString() method to include additional dog information
@Override
public String toString() {
return (super.toString() + "\nThe Cocker Spaniel is " + age +
" years old and weighs " + weight + " pounds.");
}
}
SOURCE CODE IN JAVA:
Dog.java
public class Dog
{
// instance variables
private String type, breed, name, topTrick;
// constructor
public Dog(String type, String breed, String name)
{
this.type=type;
this.breed=breed;
this.name=name;
}
// methods
void setTopTrick(String trick)
{
this.topTrick=trick;
}
// method used to print Dog information
public String toString() {
String temp = "\nDOG DATA\n" + name + " is a " + breed +", a " + type + " dog. \nThe top trick is : " +topTrick + ".";
return temp;
}
}
Corgi.java
public class Corgi extends Dog
{
// additional instance variables
private int weight, age;
// constructor
public Corgi(String type, String breed, String name, int pounds, int years)
{
// invoke Dog class (super class) constructor
super(type, breed, name);
weight = pounds;
age = years;
}
// mutator methods
public void setWeight(int pounds)
{
this.weight=pounds;
}
public void setAge(int years)
{
this.age=years;
}
// override toString() method to include additional dog information
@Override
public String toString()
{
return (super.toString() + "\nThe Corgi is " + age +" years old and weighs " + weight + " pounds.");
}
}
Driver.java
public class Driver extends Dog
{
// additional instance variables
private int weight, age;
// constructor
public Driver(String type, String breed, String name, int pounds, int years)
{
// invoke Dog class (super class) constructor
super(type, breed, name);
weight = pounds;
age = years;
}
// mutator methods
public void setWeight(int pounds)
{
this.weight=pounds;
}
public void setAge(int years)
{
this.age=years;
}
// override toString() method to include additional dog information
@Override
public String toString()
{
return (super.toString() + "\nThe Cocker Spaniel is " + age +" years old and weighs " + weight + " pounds.");
}
}
Main.java
class Main
{
public static void main(String[] args)
{
//testing the classes
Corgi c=new Corgi("cattle herding","Pembroke Welsh Corgi","Java",38,5);
c.setTopTrick("ringing the bell to go outside");
System.out.println(c);
}
}
OUTPUT:
Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...
Could someone help me out. I am not sure what I should be doing. Seeing it worked out will allow me to understand what I should be doing and then I can complete it on my own. Usando 2. Complete the Dog Class: a. Using the UML Class diagram to the right declare the instance variables. A text version is available: UML Class Diagram Text Version b. Create a constructor that incorporates the type, breed, and name variables (do not...
Java Create four classes: 1. An Animal class that acts as a superclass for Dog and Bird 2. A Bird class that is a descendant of Animal 3. A Dog class that is a descendant of Animal 4. A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: · one instance variable, a private String variable named name · a single constructor that takes one argument, a String, used to set...
In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...
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...
java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date { private String month; private String day; private String year; public Date(String month, String day, String year) { this.month = month; this.day = day; this.year = year; } public String getMonth() { return month; } public String getDay() { return day; } public String...
In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...
Create a super class called Store which will have below member variables, constructor, and methods Member variables: - a final variable - SALES_TAX_RATE = 0.06 - String name; /** * Constructor:<BR> * Allows client to set beginning value for name * This constructor takes one parameter<BR> * Calls mutator method setName to set the name of the store * @param name the name of the store */ /** getName method * @return a String, the name of the store */...
Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...
JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...