Question

In: Computer Science

BEFORE YOU START MAKE SURE TO SEND AS A TEXT FILE NOT PDF OR PICTURES. WRITE...

BEFORE YOU START MAKE SURE TO SEND AS A TEXT FILE NOT PDF OR PICTURES. WRITE IN A NEXT FILE IN JAVA ECLIPSE FORMAT. WILL BE POSTING THE CODE ON JAVA ECLIPSE. ALSO WILL GIVE THUMBS UP

Write a class called Dog that contains instance data that represents the dog’s name and age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in “person years” (seven times the dog’s age). Include a toString method that returns a one-line description of the dog. Create a driver class called Kennel, whose main method instantiates and updates several Dog objects.

Solutions

Expert Solution

/* Dog.java */


public class Dog
{
private int age;
private String name;
public Dog(int age,String name)
{
this.age = age;
this.name = name;
}

public String setDogName(String name)
{
this.name = name;
return name;
}

public int getDogName()
{
return age;
}

public int setDogAge(int age)
{
this.age = age;
return age;
}

public int getDogAge()
{
return age;
}

public int computeDogAge()
{
this.age = age*7;
return age;
}

public String toString()
{
String dogsname= "Dog's name: ";
String dogsage= "Dog's age: ";
return dogsname + name + "\t" +
dogsage + age ;
}
}

/* Kennel.java */


public class Kennel {
public static void main (String[] args)
{
Dog dog1 = new Dog(1,"Lucky");
Dog dog2 = new Dog(2,"Starc");
Dog dog3 = new Dog(5,"Lutchy");

dog1.setDogAge(9);
System.out.println(dog1);

dog2.setDogName("Azzam");
System.out.println(dog2);

System.out.println(dog3);

System.out.println();
System.out.println("Dog's ages in person years: ");
System.out.println(dog1.computeDogAge());
System.out.println(dog2.computeDogAge());
System.out.println(dog3.computeDogAge());
}
}

/* OUTPUT */


Related Solutions

Assignment: Operations Make sure you have completed the Learning Activity in this unit before you start...
Assignment: Operations Make sure you have completed the Learning Activity in this unit before you start this Assignment. Using the graphic below, please discuss the inputs, processes, and outputs that pertain to your operations of the business you chose, whether it is a service or a product oriented business. Using these three steps as a reference, how will you satisfy your customers? What core competencies will you have that will set you apart from your competitors? Pick at least two...
Write a program that prompts the user for a file name, make sure the file exists...
Write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try again (hint:...
Write a program that prompts the user for a file name, make sure the file exists...
Write a program that prompts the user for a file name, make sure the file exists and then reads through the file, counts the number of times each word appears and outputs the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try again (hint: use the try/except...
In Python write a program that prompts the user for a file name, make sure the...
In Python write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try...
You are given a text file containing a short text. Write a program that 1. Reads...
You are given a text file containing a short text. Write a program that 1. Reads a given text file : shortText.txt 2. Display the text as it is 3. Prints the number of lines 4. Prints the occurences of each letter that appears in the text. [uppercase and lowercase letter is treated the same]. 5. Prints the total number of special characters appear in the text. 6. Thedisplayofstep3,4and5aboveshouldbesaveinanoutputfile:occurencesText.txt write it in C++ programing Language
In this assignment you will write a program that encrypts a text file.  You will use the...
In this assignment you will write a program that encrypts a text file.  You will use the following encryption scheme. Ask the user for the name of the original file. Ask the user for the name of the output file. Ask the user for the encryption key, n. Read n2 characters from the file into the n rows and n columns of a 2-dimensional array. Transpose the array.  (Exchange the rows and columns.) Write the characters from the array to an output...
Write a simple text-formating.cpp file that reads (asks for then reads) a text file and produces...
Write a simple text-formating.cpp file that reads (asks for then reads) a text file and produces another text file in Which blank lines are removed, multiple blanks are replaced with a single blank, and no lines are longer than some given length (let say 80). Put as many words as possible on the same line (as close as possible to 80 characters). You will have to break some lines of the given file, but do not break any words or...
X ∼ exp(λ). Determine PDF of Y for the following cases. Make sure that you specify...
X ∼ exp(λ). Determine PDF of Y for the following cases. Make sure that you specify the range for Y values. Be extra cautious with many-to-one mappings. (a) Y = X − X2 (b)  Y = 16 − X4 (b) Y = cos(X).
Write a Python Client/Server Socket Program that will allow you to send text messages between the...
Write a Python Client/Server Socket Program that will allow you to send text messages between the server and client, terminating when the exit is typed on the client. Build the program on your 2-VM’s and get it working. Cut and paste your code below along with screen shots of your program working.
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT