In: Computer Science
1. Create 2 interfaces: BankInterface and PetInterface. BankInterface contains only 1 abstract method: accountType() which does not return anything and takes 1 String argument: accType. PetInterface contains only 1 abstract method: petType() which does not return anything and takes 1 String argument petType.
2. Create an abstract class named Student. This class contains 2 instance variables, 1 constructor, and 2 abstract methods. a. Instance variables: stId and stName (Use must use appropriate data type.) b. A 2-argument constructor that will be called from its subclass (the concrete class) to load 2 instance variables of this level during the creation of an object in its subclass. c. 2 abstract methods: getStId and getStName.. Each of these methods, when sub classed into concrete ones, should return the respective values of the instance variables stId and stName. d. At this level you should do something to get the object state at this level.
3. Create a concrete class named CentennialStudent that makes use of the abstract class Student and the 2 interfaces: BankInterface and PetInterface. This class has two instance variables of its own, one constructor, and two methods of its own. a. Instance variables: stDept and stTuitionFees. (Use appropriate data types.) b. Constructor: one constructor that constructs a CentennialStudent object with all the centennialStudent information (stId, stName, stDept, and stTutionFees) supplied during the centennialStudent object creation. c. Take necessary action to make this class a concrete class. d. Take necessary action to get the complete string representation (i.e., the object state) of objects made from this class.
4. Create a driver class named TestXXX (replace XXX by three letters of your name) that would ask for student Id, name, department, and tuition fees from the user and creates an object with the information entered. You ask also about the type of bank account the CentennialStrudent uses and also ask about his/her pet animal type. Use the implemented interface methods accountTpe and petType to display the values you entered. In order to accomplish this, you need to create variables at appropriate place to store the data entered by the user and use them in the implemented interfaces .You may use JOptionPane input dialog to get the input from the user and messageDialogs display the output.
Find the java classes and interfaces below. Comments are provided for almost all lines. Read through the comments for a better understanding.
BankInterface
public interface BankInterface {
// 1 abstract method, with String argument
abstract void accountType(String accType);
}
PetInterface
public interface PetInterface {
// 1 abstract method, with String argument
abstract void petType(String petType);
}
Abstract class Student
public abstract class Student {
// 2 instance variables
public int stId;
public String stName;
// 2 argument constructor
public Student(int stId, String stName) {
this.stId = stId;
this.stName = stName;
}
// 2 abstract methods
abstract int getStId();
abstract String getStName();
// to display the current state
@Override
public String toString() {
return "Student Id: " + stId + ", Name: " + stName;
}
}
Concrete Class CentennialStudent
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class CentennialStudent extends Student implements BankInterface, PetInterface {
// 2 instance variables
private String stDept;
private Float stTuitionFees;
// another 2 instance variables to store acc type and pet type
// the value stored here will be printed
private String accType;
private String petType;
// constructor, as described
public CentennialStudent(int stId, String stName, String stDept, Float stTuitionFees) {
super(stId, stName);
this.stDept = stDept;
this.stTuitionFees = stTuitionFees;
}
// some concrete methods
public void setAccType(String accType) {
this.accType = accType;
}
public void setPetType(String petType) {
this.petType = petType;
}
public String getAccType() {
return accType;
}
public String getPetType() {
return petType;
}
// implementing the bank interface method
@Override
public void accountType(String accType) {
JFrame frame = new JFrame();
JOptionPane.showMessageDialog(frame, "Account type: " + accType);
}
// implementing the pet interface method
@Override
public void petType(String petType) {
JFrame frame = new JFrame();
JOptionPane.showMessageDialog(frame, "Pet Animal type: " + petType);
}
// implementing abstract class Student method
@Override
public int getStId() {
return this.stId;
}
// implementing abstract class Student method
@Override
public String getStName() {
return this.stName;
}
// to display the current state
// it make use of toString() method defined in the abstract class Student
@Override
public String toString() {
return super.toString() + ", Department: " + stDept + ", Tuition Fee: " + stTuitionFees;
}
}
Testing class TestXXX
import java.util.Scanner;
import javax.swing.*;
public class TestXXX {
public static void main(String[] args) {
// create new JFrame
JFrame f = new JFrame();
// read data to create centennial student object
int stId = Integer.parseInt(JOptionPane.showInputDialog(f, "Student Id:"));
String stName = JOptionPane.showInputDialog(f, "Name:");
String stDept = JOptionPane.showInputDialog(f, "Department:");
Float stTuitionFees = Float.parseFloat(JOptionPane.showInputDialog(f, "Tuition Fee:"));
// create centennial student object
CentennialStudent st = new CentennialStudent(stId, stName, stDept, stTuitionFees);
// read acount type
String accType = JOptionPane.showInputDialog(f, "Bank Account Type:");
// read pet animal type
String petType = JOptionPane.showInputDialog(f, "Pet Animal Type:");
// set account type and pet type to variables in centennial student object
st.setAccType(accType);
st.setPetType(petType);
// display centennial student details
// centennial student in turn calls student.toString()
JOptionPane.showMessageDialog(f, st.toString());
// show acc type and pet type from implemented interface methods
st.accountType(st.getAccType());
st.petType(st.getPetType());
}
}
Kindly upvote, if you are satisfied with the answer.