Question

In: Computer Science

This exercise requires designing a program which solves the problem described in the problem statement below....

This exercise requires designing a program which solves the problem described in the problem statement below. Provide comments in your pseudo-code and Java program as necessary.

Your solution must include these components:

  1. UML Class diagram
  2. Flowchart
  3. Pseudo-code
  4. Program Coded
  5. Program Output

Problem Statement

Design a class named Pet, which should have the following fields:

  • name: The name field holds the name of a pet.

  • type: The type field hold the type of animal that a pet is (for example, “dog”, “cat”, “bird”)

  • age: The age field holds the pet’s age.

The Pet class should also have the following methods:

  • setName: the setName method stores a value in the name field.

  • setType: the setType method stores a value in the type field

  • setAge: the setAge method stores a value in the age field.

  • getName: the getName method returns the value of the name field.

  • getType: The getType method returns the value of the type field.

  • getAge: the getAge method returns the value of the age field.

Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the object’s accessor methods to retrieve the pet’s name, type, and age and display this data on the screen.

Expected Output

Your results should be similar to the following:

Please enter the name of your pet: Maestro

Please enter the type of your pet: dog

Please enter the age of your pet: 8


The name of your pet is Maestro.

Maestro is a dog.

Maestro is 8 years old.

Submission

Submit your assignment as a Microsoft Word document (.docx) with all components in the one document. Once submitted, the answer will be revealed.

Grading

This practice problem is NOT graded. However, you must complete the practice problem and survey before your graded programming assignment problem will be revealed.

Solutions

Expert Solution

Solution:

Pseudocode:

  1. Begin
  2. call setName
  3. call setType
  4. call setAge
  5. call getName
  6. call getType
  7. call getAge
  8. end

code:

import java.util.Scanner;

public class Pet {
   private String name; //name of the pet
   private String type; //type of the pet
   private int age; //age of the pet

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getType() {
       return type;
   }

   public void setType(String type) {
       this.type = type;
   }

   public int getAge() {
       return age;
   }

   public void setAge(int age) {
       this.age = age;
   }

   public static void main(String[] args) {
       String name;
       String type;
       int age;
       Pet pt= new Pet(); //creating the object of the pet class
       Scanner sc= new Scanner(System.in);
       System.out.println("Please enter the name of your pet: "); //Taking the input from the user
       name= sc.nextLine();
       System.out.println("Please enter the type of your pet: ");
       type= sc.nextLine();
       System.out.println("Please enter the age of your pet: ");
       age= sc.nextInt();
       pt.setName(name); //calling setters to set the input
       pt.setType(type);
       pt.setAge(age);
       System.out.println("The name of your pet is: " + pt.getName()); //using the getter to show the output
       System.out.println(pt.getName() + " is a " + pt.getType());
       System.out.println(pt.getName()+" is " + pt.getAge() + " years old");

   }

}

5)

Output:

Please enter the name of your pet:
Maestro
Please enter the type of your pet:
dog
Please enter the age of your pet:
8
The name of your pet is: Maestro
Maestro is a dog
Maestro is 8 years old

Hit the thumbs up if you liked the answer. :)


Related Solutions

Write a program in C++ that solves this problem Calculate the area and volume of a...
Write a program in C++ that solves this problem Calculate the area and volume of a sphere problem. Inside a for loop, vary the radius from 10 to 40  with a step or increment of 5 and calculate the area and volume Your radius will be equal to your loop counter. All calculations should have 2 decimal places, but the radius should have zero decimal places and any number of 1,000 or more should have a comma. Print the radius, area,...
Write a program that solves the Knapsack problem. Code to the following standards. Your source of...
Write a program that solves the Knapsack problem. Code to the following standards. Your source of items to put into the knapsack should consist of five randomly generated integers in the range of 1 to 20. Your knapsack can hold 20 lbs.
A Java program that solves a real-world problem The remaining amount (balance) for a prepaid cellular...
A Java program that solves a real-world problem The remaining amount (balance) for a prepaid cellular phone, is computed by subtracting the cost of the phone usage from the original phone load. The phone usage is based only on the total cost of text messages and phone calls. The cost of text messages is determined from the number of text messages sent and the cost of phone calls is determined from the number of minutes of calls made. ● Based...
C programming problem I have to design an efficient algorithm which solves this problem. Also, it...
C programming problem I have to design an efficient algorithm which solves this problem. Also, it needs to include time and space complexities of this algorithm. There is a matrix (N times N) of integers which rows and columns are sorted in non-decreasing order. A sorted matrix and integer M will be given and we need to find the position(row,column) of M in this matrix. it's okay to report only one position if there are more than one answers. when...
An algorithm is classically defined as a finite series of steps which solves a problem. What...
An algorithm is classically defined as a finite series of steps which solves a problem. What are some types of instructions which occur in everyday life which would qualify as an algorithm? What are some everyday types of instruction which would NOT qualify as an algorithm
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in...
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in the 4th edition). Given are the equations for the moment, as a function of x, starting from the leftmost side of the beam with x=0 and ending at the other end of the beam with x=12. This piecewise function together makes up the moment equation for the beam given. 0 ≤ ? ≤ 3 ?(?) = 265? − 5.56?3 , 3 < ? ≤...
Write a program to implement problem statement below: provide the menu for input N and number...
Write a program to implement problem statement below: provide the menu for input N and number of experiment M to calculate average time on M runs. randomly generated list. State your estimate on the BigO number of your algorithm/program logic. (we discussed in the class) Measure the performance of your program by given different N with randomly generated list with multiple experiment of Ns against time to draw the BigO graph (using excel) we discussed during the lecture. Lab-08-BigBiggerBiggtest.png ***...
Write C++ program as described below. Call this programChill.cpp. In April 2018 the lowest and the...
Write C++ program as described below. Call this programChill.cpp. In April 2018 the lowest and the highest temperatures ever recorded in Ohio are 25F and 81F, respectively. The wind chill factor is the perceived temperature when taking temperature and wind into account. The standard formula for wind chill factor (from the US Weather Service) is: 0.0817 * (3.71 * sqrt(Wind) + 5.81 – 0.25 * sqrt(Wind)) * (Temp – 91.4) + 91.4 where ‘sqrt’ is the square root, Wind is...
C++ This assignment will have you designing a program which can test multiple combinations of the...
C++ This assignment will have you designing a program which can test multiple combinations of the Boolean variables A, B, and C, and determine which combinations of them will yield true values. However this time the statement is designed in the style of a Logical Circuit. You are asked to create three truth tables for the three problems. To achieve this, you should create SEVEN gate functions for your checkpoint. For each of the problem: First, convert the diagram to...
C++ This assignment will have you designing a program which can test multiple combinations of the...
C++ This assignment will have you designing a program which can test multiple combinations of the Boolean variables A, B, and C, and determine which combinations of them will yield true values. However the statement is designed in the style of a Logical Circuit.You are asked to create three truth tables for the three problems.First, convert the diagram to boolean algebra equations.Then evaluate their values step by step based on the values of A, B and C. Finally, print the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT