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,...
Problem: Write a C++ program that will implement and test the five functions described below that...
Problem: Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness. 1. minimum: takes an int array and the array's size as arguments. It should return the minimum value of the array elements. Do not use square brackets anywhere in the function, not even the parameter...
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.
You must program the game called MaDi which is described below. There is a board of...
You must program the game called MaDi which is described below. There is a board of NxN (the size N is defined by the user and must be a number greater than or equal to 2), where in each box there is an instruction. The first (the [0] [0]) and the last box (the [N-1] [N-1]) have no instruction. Possible instructions are: 1. Don't move 2. Advance 4 places 3. Jump to the next row 4. Go back 2 places...
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 ***...
c programing language This assignment, which introduces the use of loops, solves the following problem: given...
c programing language This assignment, which introduces the use of loops, solves the following problem: given a starting location in a city, how long does it take a “drunken sailor” who randomly chooses his direction at each intersection to reach the city’s border? You will read input values to set up the problem parameters, run several trials to determine an average number of steps for the sailor to reach the border, and output the results. This problem is an example...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT