****Please read the following requirements and use java language w/ comments****
****Can make this a multi part question if needed****
Project requires a base class, a derived subclass, and an interactive driver (class with a main) that allows the user to utilize and manipulate the classes created. You may select one super class from the following:
Superclass Example subclasses
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;
}
// Getters and setters for private member variables
public int getAge() {
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 isCarnivorous() {
return isCarnivorous;
}
public void setCarnivorous(boolean isCarnivorous) {
this.isCarnivorous = isCarnivorous;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAgeExpectency() {
return ageExpectency;
}
public void setAgeExpectency(int ageExpectency) {
this.ageExpectency = ageExpectency;
}
public boolean isPawed() {
return isPawed;
}
public void setPawed(boolean isPawed) {
this.isPawed = isPawed;
}
public boolean isDomestic() {
return isDomestic;
}
public void setDomestic(boolean isDomestic) {
this.isDomestic = isDomestic;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
// class utilities
public void eat() {
System.out.println("Eating..");
}
public void sleep() {
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 isSame(Animal a, Animal b) {
return a.equals(b);
}
}
class Dog extends Animal {
private String species;
private String petName;
// default constructor
Dog() {
// System.out.println("Dog class constructor");
}
// parameterized constructors
Dog(int age) {
super(age); // super keyword invokes super class constructor
}
Dog(int age, String species) {
super(age);
this.species = species;
}
// getter and setters for sub class properties
public String getSpecies() {
return species;
}
public void setSpecies(String species) {
this.species = species;
}
public String getPetName() {
return petName;
}
public void setPetName(String petName) {
this.petName = petName;
}
// utility methods of sub class
public void bark() {
System.out.println("Barking..");
}
// over riding 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 type sub class - Dog
Dog puppy = new Dog();
while(true) {
System.out.print("\nChoose an option:\n1. Create a Dog\n2. Set pet name\n3. Delete the object"
+ "\n4. Set basic details\n5. Print the object\n6. Exit\n>>>");
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 dog object
// in other words, 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 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 exception
}
case 3:
puppy = null;
continue;
case 4:
// this block will throw NullPointerException if invoked immediately after deleting dog object
// in other words, 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 exception
}
case 5:
puppy.print();
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");
}
}
}
}
****Please read the following requirements and use java language w/ comments**** ****Can make this a multi...
In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...
write java program and for the following (you can add more classes as you see necessary) as follows: a class called Coursewith courseCode, courseName,and creditHours; a superclass called FacultyMemberwith FacultyID, firstName, lastName, academicRank, and academicSpecialization; a course Convener subclass inherits from the FacultyMember class with specific member variables representing the coursesand members (Lecturers andTAs) whom he/she is responsible of; Lecturers andTAsare also subclasses that inherit from FacultyMemberclass with some specific member variables (i.e., maximumNumberOfCourses, quotaOfCreditHoursthey can take, and assignedCourses). Create...
JAVA Problem: Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...
***Please give the java code for the below and add comments for different areas for a dummy to understand*** This java program will combine the techniques of handling arrays, decision control statements, and loops. Your program should accomplish the following: Build an array that holds characters (size 35) Load the array with random capital letters (use random generator) Your program should present a menu to the user allowing for the following “actions”. To “search” for a target letter of the...
Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...
Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...
Can someone please help with this in JAVA? Write one application program by using the following requirements: 1) Exception handling 2) Inheritance a) At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods b) At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods c) At least one interface: this interface needs to have at least two abstract methods d) At least one method...
JAVA Problem: Coffee Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...
Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...
Must be in Java.
Please show step by step process with proper explanation and
comments.
Please maintain proper indentation.
CODE PROVIDED:
Doctor.java
HospitalDoctor.java
Q1Runner.java
import java.util.Scanner;
public class Q1Runner {
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
// Do your work here
}
}
You are asked to create the starting point of a system to represent several types of medical doctors. You decided to implement two classes: a superclass...