Dana Upload Assignment Pets x Chegg Study Guided Sc x C Secure https:// blackboa
ID: 3827966 • Letter: D
Question
Dana Upload Assignment Pets x Chegg Study Guided Sc x C Secure https:// blackboard.com/webapps/assignment/uploadAssignment?content id 330217 1&course; id 213764. 18kgroup id: &mode; view E pps Bookmark LG myCampus secure Lo Yahoo M D Java: An Introductio LOGIN Dr Data Structur Pdf L Blackboard Learn Step-by-step calculat g SGRHO Home Page Cancel Save Draft Subm Information Discussions Groups 1. Assignment Information Tools Help Due Date Points Possible Assignments Friday, March 17, 2017 50 11:59 PM Example Codes Design a class named Pet, which should have the following fields/ attributes name. The name field holds the name of the pet. type. The type field holds the typed of the animal that a pet is. Ex: Dog, Cat, Blrd. age. The age field holds the pets 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 set Age method stores a value in the age field. getName. The getName method ret the value of the name field. getType. The getType method returns the value of the type field. geyAge ThegetAge method returns thevalu the age field. eof 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. Use the objects accessor methods to retrieve the pet's name, type, and age and display this data to the screen. DUE DATE: MARCH 17, 2017 NO FLOWCHART NO GRADE!!! 50PTS 2. Assignment Submission & A 8:18 PM 4/2TI2017Explanation / Answer
PetTest.java
import java.util.Scanner;
public class PetTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the per name: ");
String name = scan.next();
System.out.println("Enter the pet type: ");
String type = scan.next();
System.out.println("Enter the pet age: ");
int age = scan.nextInt();
Pet p = new Pet();
p.setAge(age);
p.setName(name);
p.setType(type);
System.out.println("Pet Name: "+p.getName());
System.out.println("Pet Type: "+p.getType());
System.out.println("Pet Age: "+p.getAge());
}
}
Pet.java
public class Pet {
private String type, name;
private int age;
public Pet() {
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Output:
Enter the per name:
Honey
Enter the pet type:
Dog
Enter the pet age:
8
Pet Name: Honey
Pet Type: Dog
Pet Age: 8
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.