In this exercise, you are going to use the Person and Student classes to create two…
- User
In this exercise, you are going to use the Person and Student classes to create two objects, then print out all of the available information from each object.
Your tasks Create a Person object with the following information: Name: Wolfgang Amadeus Mozart Birthday: January 27, 1756 Create a Student object with the following infromation: Name: Johann Nepomuk Hummel Birthday: November 14, 1778 Grade: 10 GPA: 4.0 You do not need to modify the Person or Student class. public class Person {
private String name; private String birthday; public Person (String name, String birthday) { this.name = name; this.birthday = birthday; } public String getBirthday(){ return birthday; } public String getName(){ return name; }} public class PersonRunner { public static void main(String[] args) { // Start here! } } public class Student extends Person {
private int grade; private double gpa; public Student(String name, String birthday, int grade, double gpa){ super(name, birthday); this.grade = grade; this.gpa = gpa; } public int getGrade(){ return grade; } public double getGpa(){ return gpa; }}
- Assistant
Certainly! To accomplish the tasks described, you would modify the
PersonRunnerclass to create aPersonandStudentobject with the specified information, then print out all the available information from each object. Here is how you can do it:public class PersonRunner { public static void main(String[] args) { // Creating a Person object with the specified information Person mozart = new Person("Wolfgang Amadeus Mozart", "January 27, 1756"); // Creating a Student object with the specified information Student hummel = new Student("Johann Nepomuk Hummel", "November 14, 1778", 10, 4.0); // Printing out the information for the Person object System.out.println("Person Information:"); System.out.println("Name: " + mozart.getName()); System.out.println("Birthday: " + mozart.getBirthday()); // Printing a line for better readability between Person and Student information System.out.println("\nStudent Information:"); // Printing out the information for the Student object System.out.println("Name: " + hummel.getName()); System.out.println("Birthday: " + hummel.getBirthday()); System.out.println("Grade: " + hummel.getGrade()); System.out.println("GPA: " + hummel.getGpa()); } } - User
- Assistant
To refactor the given code according to the task instructions, we need to identify the common attributes and methods in
EncyclopediaandMysteryclasses, and then move these to theBooksuperclass. By examining the and classes, it's evident that both classes share the attributes and , along with their respective getter and setter methods. These will be moved to the superclass. Here's how the refactored code will look: - User
For this exercise, you are going to design 3 classes:
Computer - Superclass Laptop - Subclass Desktop - Subclass You will design these classes to optimize the superclass/subclass relationship by creating instance variables and getter/setter methods.
Include the following instance variables:
int screenSize - Inches of monitor space int memory - GB of ram double batteryLife - Hours of battery life boolean monitor - Whether or not a monitor is included Each class should have at least one variable in it.
Once completed, the Tester class should execute without error.
public class Computer {
} public class ComputerTester { public static void main(String[] args) { Laptop macBook = new Laptop(); macBook.setBatteryLife(8.5); macBook.setMemory(4);
Desktop dell = new Desktop(); dell.setScreenSize(18); Computer surface = new Computer(); surface.setScreenSize(11); surface.setMemory(8); System.out.println(macBook.getBatteryLife()); System.out.println(macBook.getMemory()); System.out.println(dell.getScreenSize()); System.out.println(surface.getScreenSize()); System.out.println(surface.getMemory()); }}public class Desktop {
} public class Laptop {
}
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.