1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
qaws [65]
3 years ago
10

Write a program that implements a class called Dog that contains instance data that represent the dog's name and age. • define t

he Dog constructor to accept and initialize instance data. • create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age). • Include a toString method that returns a one-line description of the dog • Write a driver class called Kennel, whose main method instantiated and updates several Dog objects
Computers and Technology
1 answer:
g100num [7]3 years ago
7 0

Answer:

<u>Dog.java:</u>

Dog{

   //Declare instance variables

   private String name;

   private int age;

   

   //Create the constructor with two parameters, and initialize the instance variables

   public Dog(String name, int age){

       this.name = name;

       this.age = age;

   }

   

   //get methods

   public String getName(){

       return name;

   }

   

   public int getAge(){

       return age;

   }

   

   //set methods

   public void setName(String name){

       this.name = name;

   }

   

   public void setAge(int age){

       this.age = age;

   }

   

   //calculateAgeInPersonYears() method to calculate the age in person years by multiplying the age by 7

   public int calculateAgeInPersonYears(){

       return 7 * getAge();

   }

   

   //toString method to return the description of the dog

   public String toString(){

       return "Name: " + getName() + ", Age: " + getAge() + ", Age in Person Years: " + calculateAgeInPersonYears();

   }

}

<u>Kennel.java:</u>

public class Kennel

{

public static void main(String[] args) {

          //Create two dog objects using the constructor

          Dog dog1 = new Dog("Dog1", 2);

          Dog dog2 = new Dog("Dog2", 5);

          //Print their information using the toString method

          System.out.println(dog1.toString());

          System.out.println(dog2.toString());

          //Update the first dog's name using setName method

          dog1.setName("Doggy");

          System.out.println(dog1.toString());

          //Update the second dog's age using setAge method

          dog2.setAge(1);

          System.out.println(dog2.toString());

}

}

Explanation:

*The code is in Java.

You may see the explanations as comments in the code

You might be interested in
____ that allow individuals to perform specific tasks are launched via the operating system, such as by using the windows start
schepotkina [342]
Programs that allow individuals to perform specific tasks are launched via the operating system, such as by using the windows start menu on windows computers. Programm is a set of instructions written for a computer.<span>The Start menu contains icons for all installed programs and data collections, usually for programs.</span>
3 0
3 years ago
What is it about Pinterest that makes it a good platform for ecommerce sites?
Inga [223]
With the large variance of items on the site it is easy to invest in an idea
5 0
3 years ago
Read 2 more answers
Write a program that encrypts and decrypts a string of characters. Use a char array for this, not the string class. The maximum
dem82 [27]

Answer:

C++ code for encryption is given below

Explanation:

#include <iostream>

using namespace std;

//functions to encrypt and decrypt

void encrypt(char str[]);

void decrypt(char str[]);

int main(){

char str[200];

bool done = false;

while(!done){

cout << "Enter a string (enter * to stop): ";

cin.getline(str, 200);

if(str[0] == '*' && str[1] == '\0')

done = true;

else{

encrypt(str);

cout << "Encrypted: " << str << endl;

decrypt(str);

cout << "Decrypted: " << str << endl;

}

cout << endl;

}

}

void encrypt(char str[]){

int i = 1;

for(int j = 0; str[j] != '\0'; j++){

str[j] += i;

i++;

if(i == 11)

i = 1;

}

}

void decrypt(char str[]){

int i = 1;

for(int j = 0; str[j] != '\0'; j++){

str[j] -= i;

i++;

if(i == 11)

i = 1;

}

}

3 0
3 years ago
you want to discard your old computer and want to securely erase the data from your hard drive. what can you use to do this and
maksim [4K]
Hard drive reset i think
5 0
3 years ago
What was the han dynasty and the roman empire known for?
BigorU [14]
The largest Chinese <span>historiographic work, known as the “Records of the Grand Historian”, was written during the Han Dynasty by Sima Qian, who is referred to as the father of </span>Chinese<span> historiography.
hope you got the answer.</span>
7 0
3 years ago
Other questions:
  • Convert A4B from hexadecimal to binary. Show your work.
    11·1 answer
  • Emily wants to search online for cakes containing nuts. However, she wants to skip cakes that have raisins in them. Which option
    9·1 answer
  • To make sound decisions about information security, management must be informed about the various threats facing the organizatio
    10·1 answer
  • The software maintains and manages information related to employees, rooms, committees, and committee meetings of a company. The
    9·1 answer
  • What are the differences betweenCONS, LIST, and APPEND?
    5·1 answer
  • Place Letter or word in correct section where it says labels bellow
    14·2 answers
  • Hi I'm new to Brainly anyone wanna be my frnd​
    15·1 answer
  • Draw the final structure that will house the electronic system​
    15·1 answer
  • content from other sources can be embedded into it linked to a photoshop document from another source
    14·1 answer
  • Tools used to build a bridge<br>​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!