Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*****Need help with adding in below requirement to the code below using Java: ***** Create a graphical interface for the user. Taking the classes developed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

*****Need help with adding in below requirement to the code below using Java: ***** Create a graphical interface for the user. Taking the classes developed in the code below, and creating a new interface and driver. Specifications are: 1. Create a purely graphical interface so that the user can interact with your class definition in a manner similar to the code below: a. Your program should allow the creation and manipulation of an object of your subclass type. b. The program should allow the user to "graphically to interact with your class. Essentially, you will be replacing the menu that you created in project #1, to a graphical one in project #2 - the layout, style, and nodes to do so are up to you. With that said, please select nodes that make sense - text boxes when it is appropriate, radio buttons, perhaps combo boxes, labels, etc. Try to use different node types when it is appropriate (i.e. don't just use text fields for everything) c. Your interface should allow the user to load/change (constructors/sets), delete, interrogate (retrieve data from gets]), and print your subclass object. Obviously, you would use the subclass member methods (constructors/sets/gets/utilities) to accomplish the above requirements. Don't have more than 10 options total d. Your menu should also include a "quit" selection similar to what you had in project #1 - as you can hopefully already imagine, the "looping portion is not a large worry using GUIs since you are working with "event" driven programming. import java.io.IOException; import java.lang.NullPointerException; import java.util.Scanner; class Animal { // class properties private int age; private double height; private double weight; private String color; private boolean isCarnivorous; private String sex; private int ageExpectency private boolean isPawed; private boolean isDomestic; private double speed; // default constructor public Animal) { // System.out.println("Animal class constructor"); // parameterized constructors // two of which are checking for valid ages public Animal/int age) { // "Constructing animal object with given age if greater than 0" if(age>0){ this.age = age; } else { throw new Error("Age cannot be less than zero"); public Animal(int age, double height, double weight) { if(age>0){ this.age = age; this.height = height; this.weight = weight; } else { throw new Error("Age cannot be less than zero"); public Animal(int age, double height, double weight, String color) { this.age = age; this.height = height; this.weight = weight; this.color = color; // Get and set for private member variables public int getAgel) { return age; public void setAge(int age) { this.age = age; public double getHeight() { return height; public void setHeight(double height) { this.height = height; public double getWeight() { return weight; public void setWeight(double weight) { this.weight = weight; public String getColor() { return color; public void setColor(String color) { this.color = color; public boolean isCarnivorousl) { return isCarnivorous; public void setCarnivorous boolean isCarnivorous) { this.isCarnivorous = isCarnivorous, public String getSexl) { return sex; public void setSex(String sex) { this.sex = sex; public int getAgeExpectencyl) { return ageExpectency; public void setAgeExpectency(int ageExpectency) { this.ageExpectency= ageExpectency public boolean isPawedl) { return is Pawed; } public void setPawed(boolean isPawed) { this.isPawed = isPawed; public boolean isDomesticl) { return isDomestic; public void setDomestic boolean isDomestic) { this.isDomestic = isDomestic; public double getSpeedl) { return speed; public void setSpeed(double speed) { this.speed = speed; // class utilities public void eat() { System.out.println("Eating.."); public void sleepl) { System.out.println("Sleeping.."); public void print() { System.out.println("Height:" + this.getHeight()); System.out.println("Weight:" + this.getWeight(); System.out.println("Sex: " + this.getSex()); // static method public static boolean isSamel Animal a, Animal b) { return a.equals(b); class Dog extends Animal { private String species; private String RetName; // default constructor Dog() { // System.out.println("Dog class constructor"); // parameterized constructors Dog(int age) { super(age); // super keyword invokes the super class constructor Dog(int age, String species) { super(age); this species = species; // get and set for the sub class properties public String getSpecies() { return species; public void setSpecies(String species) { this species = species; public String getPetNamel) { return petName; public void setpetName(String petName) { this.petName = petName; // utility methods of the sub class public void bark() { System.out.println("Barking.."); // overriding the super class method @Override public void print() { System.out.println("Details about Dog"); System.out.println("Age: " + this.getAge()); System.out.println("Species: " + this.getSpecies(); System.out.println("Pet name:" + this.getPetName()); super.print(); // invoke super class print() method public class Main { public static void main(String[] args) throws IOException, NullPointerException { Scanner in = new Scanner(System.in); // an object of the type sub class - Dog Dog puppy = new Dog(); while(true) { System.out.print(" Choose an option: 1. Create a Dog 2. Set pet name 3. Delete the object" + " 4. Set basic details 5. Print the object 6. Exit >>>"); int option = in.nextInt(); switch(option) { case 1: puppy = new Dog(12, "Labrador"); continue; case 2: // this block will throw NullPointerException if invoked immediately after deleting the dog object // you need a dog first to set it's details try { in.nextLine(); System.out.print("Enter the pet name for your dog: "); String name= in.nextLine(); //reads the name puppy.setPetName(name); continue; } catch(Exception e) { System.out.println(e); System.out.println("Create an object first"); continue; // we want the program to continue even after the exception happens case 3: puppy = null; continue; case 4: // this block will throw NullPointerException if invoked immediately after deleting the dog object // you need a dog first to set it's details try { System.out.print("Enter age: "); puppy.setAge(in.nextInt()); System.out.print("Enter height: "); puppy.setHeight(in.nextDouble(); System.out.print("Enter weight: "); puppy.setWeight(in.nextDouble(); in.nextLine(); System.out.print("Enter Sex: "); puppy.setSex(in.nextLine()); continue; } catch(Exception e) { System.out.println(e); System.out.println("Create an object first"); continue; // we want the program to continue even after the exception case 5: puppy.printl); continue; case 6: in.close(); // close the stream reader System.out.println("Programs exits successfully"); return; default: System.out.println("Invalid input. Choose from menu"); *****Need help with adding in below requirement to the code below using Java: ***** Create a graphical interface for the user. Taking the classes developed in the code below, and creating a new interface and driver. Specifications are: 1. Create a purely graphical interface so that the user can interact with your class definition in a manner similar to the code below: a. Your program should allow the creation and manipulation of an object of your subclass type. b. The program should allow the user to "graphically to interact with your class. Essentially, you will be replacing the menu that you created in project #1, to a graphical one in project #2 - the layout, style, and nodes to do so are up to you. With that said, please select nodes that make sense - text boxes when it is appropriate, radio buttons, perhaps combo boxes, labels, etc. Try to use different node types when it is appropriate (i.e. don't just use text fields for everything) c. Your interface should allow the user to load/change (constructors/sets), delete, interrogate (retrieve data from gets]), and print your subclass object. Obviously, you would use the subclass member methods (constructors/sets/gets/utilities) to accomplish the above requirements. Don't have more than 10 options total d. Your menu should also include a "quit" selection similar to what you had in project #1 - as you can hopefully already imagine, the "looping portion is not a large worry using GUIs since you are working with "event" driven programming. import java.io.IOException; import java.lang.NullPointerException; import java.util.Scanner; class Animal { // class properties private int age; private double height; private double weight; private String color; private boolean isCarnivorous; private String sex; private int ageExpectency private boolean isPawed; private boolean isDomestic; private double speed; // default constructor public Animal) { // System.out.println("Animal class constructor"); // parameterized constructors // two of which are checking for valid ages public Animal/int age) { // "Constructing animal object with given age if greater than 0" if(age>0){ this.age = age; } else { throw new Error("Age cannot be less than zero"); public Animal(int age, double height, double weight) { if(age>0){ this.age = age; this.height = height; this.weight = weight; } else { throw new Error("Age cannot be less than zero"); public Animal(int age, double height, double weight, String color) { this.age = age; this.height = height; this.weight = weight; this.color = color; // Get and set for private member variables public int getAgel) { return age; public void setAge(int age) { this.age = age; public double getHeight() { return height; public void setHeight(double height) { this.height = height; public double getWeight() { return weight; public void setWeight(double weight) { this.weight = weight; public String getColor() { return color; public void setColor(String color) { this.color = color; public boolean isCarnivorousl) { return isCarnivorous; public void setCarnivorous boolean isCarnivorous) { this.isCarnivorous = isCarnivorous, public String getSexl) { return sex; public void setSex(String sex) { this.sex = sex; public int getAgeExpectencyl) { return ageExpectency; public void setAgeExpectency(int ageExpectency) { this.ageExpectency= ageExpectency public boolean isPawedl) { return is Pawed; } public void setPawed(boolean isPawed) { this.isPawed = isPawed; public boolean isDomesticl) { return isDomestic; public void setDomestic boolean isDomestic) { this.isDomestic = isDomestic; public double getSpeedl) { return speed; public void setSpeed(double speed) { this.speed = speed; // class utilities public void eat() { System.out.println("Eating.."); public void sleepl) { System.out.println("Sleeping.."); public void print() { System.out.println("Height:" + this.getHeight()); System.out.println("Weight:" + this.getWeight(); System.out.println("Sex: " + this.getSex()); // static method public static boolean isSamel Animal a, Animal b) { return a.equals(b); class Dog extends Animal { private String species; private String RetName; // default constructor Dog() { // System.out.println("Dog class constructor"); // parameterized constructors Dog(int age) { super(age); // super keyword invokes the super class constructor Dog(int age, String species) { super(age); this species = species; // get and set for the sub class properties public String getSpecies() { return species; public void setSpecies(String species) { this species = species; public String getPetNamel) { return petName; public void setpetName(String petName) { this.petName = petName; // utility methods of the sub class public void bark() { System.out.println("Barking.."); // overriding the super class method @Override public void print() { System.out.println("Details about Dog"); System.out.println("Age: " + this.getAge()); System.out.println("Species: " + this.getSpecies(); System.out.println("Pet name:" + this.getPetName()); super.print(); // invoke super class print() method public class Main { public static void main(String[] args) throws IOException, NullPointerException { Scanner in = new Scanner(System.in); // an object of the type sub class - Dog Dog puppy = new Dog(); while(true) { System.out.print(" Choose an option: 1. Create a Dog 2. Set pet name 3. Delete the object" + " 4. Set basic details 5. Print the object 6. Exit >>>"); int option = in.nextInt(); switch(option) { case 1: puppy = new Dog(12, "Labrador"); continue; case 2: // this block will throw NullPointerException if invoked immediately after deleting the dog object // you need a dog first to set it's details try { in.nextLine(); System.out.print("Enter the pet name for your dog: "); String name= in.nextLine(); //reads the name puppy.setPetName(name); continue; } catch(Exception e) { System.out.println(e); System.out.println("Create an object first"); continue; // we want the program to continue even after the exception happens case 3: puppy = null; continue; case 4: // this block will throw NullPointerException if invoked immediately after deleting the dog object // you need a dog first to set it's details try { System.out.print("Enter age: "); puppy.setAge(in.nextInt()); System.out.print("Enter height: "); puppy.setHeight(in.nextDouble(); System.out.print("Enter weight: "); puppy.setWeight(in.nextDouble(); in.nextLine(); System.out.print("Enter Sex: "); puppy.setSex(in.nextLine()); continue; } catch(Exception e) { System.out.println(e); System.out.println("Create an object first"); continue; // we want the program to continue even after the exception case 5: puppy.printl); continue; case 6: in.close(); // close the stream reader System.out.println("Programs exits successfully"); return; default: System.out.println("Invalid input. Choose from menu")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

What are three disadvantages of a civil service system?

Answered: 1 week ago

Question

What are three advantages of a civil service system?

Answered: 1 week ago