Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2.

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 any values of your choice for name and age.

4. go back to 'Dog' class and implement the 'toString' method and then call this method from 'Driver' to print the dogs' info.

this is what I have so far:

for Dog

public class Dog { //instance variables private String name; private int age; //constructor, takes the instance variable and binds to constructor public Dog(String dogName, int dogAge) //has the same name as the class { name = dogName; //assigns the instance variables which has no value to the constructor parameters age = dogAge; } public String toString() { String Dog = ""; Dog += this.name + "\t"; Dog += this.age; return Dog; } }

and for Driver:

public class Driver { public static void main (String [] args) { Dog myDog = new Dog ("Gino", 6); Dog yourDog = new Dog ("Amie",7); System.out.println(Dog.name); System.out.println(Dog.age); } }

I'm not sure if I did this right. Can you explain?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

=+ (c) Show by example that f need not be constant.

Answered: 1 week ago