Question

In: Computer Science

1. Create 2 interfaces: BankInterface and PetInterface. BankInterface contains only 1 abstract method: accountType() which does...

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.

Solutions

Expert Solution

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.


Related Solutions

Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return...
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost. Derive a class BulkDiscount from DiscountPolicy. It should have a constructor that has two parameters minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more then minimum, the discount is percent percent.
2) Explain the “Abstract and Opinion” method?
2) Explain the “Abstract and Opinion” method?3) Explain what is meant by the term assumption of a mortgage?4) Under what circumstances would a buyer use seller financing?
Create a “Main” method that contains two 2-Dimensional arrays of characters. The first array, which we...
Create a “Main” method that contains two 2-Dimensional arrays of characters. The first array, which we will call our visible field, needs to be 5 by 5 and should initially hold the underscore character “_”.  This will be used in our game of minesweeper to represent the possible locations the player can check. The second array, which we will call our hidden field, should also be 5 by 5 but filled with the capital letter "S” which means safety. However, we...
Create an abstract class polygon that has a method getnoofsides() and getarea() and it has three...
Create an abstract class polygon that has a method getnoofsides() and getarea() and it has three subclasses triangle, rectangle and square each with its own two methods getnoofsides and getarea and their respective implementations accordingly. python
Create a cronjob which does the following tasks 1.) create a file named <yourname>.txt 2.) in...
Create a cronjob which does the following tasks 1.) create a file named <yourname>.txt 2.) in the 35th minute of the hour change the permission to 755 3.) Create a shell script named first.sh in which you print your name and redirect the output by 45th minute of the hour to the text file
Create an interface MessageEncoder that has a single abstract method encode(plainText) where the plainText is the...
Create an interface MessageEncoder that has a single abstract method encode(plainText) where the plainText is the message to be encoded. The method will return the encoded version of the message. Then create a class SubstitutionCipher that implements this interface. The constructor should have on parameter called shift. Define the method encode so that each letter is shifted by the value in shift. For example if shift is 3 a will be replaced by d, b will be replaced by e....
Create a Java method that does the following: 1) Ask the user for a dividend and...
Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Please see the videos for the explanation.
Java instructions: 1. Modify abstract superclass (Employee10A) so it comment out the abstract payPrint method and...
Java instructions: 1. Modify abstract superclass (Employee10A) so it comment out the abstract payPrint method and uses a toString method to print out it’s instance variables. Make sure toString method cannot be overridden.​​​​​​ Source code below: public abstract class Employee10A {    private String firstName, lastName; static int counter = 0;    public Employee10A(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; }    @Override public String toString() { return ("The employee's full name is " + firstName...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
On the following code that contains a method which returns a new matrix (2-d array) with...
On the following code that contains a method which returns a new matrix (2-d array) with same number of rows and columns as has its parameter (matrix). Each entry in the returned array should equal the result of multiplying the entry at the same row and column in matrix by the value of scalar. code: package edu.buffalo.cse116; /** * Class which contains a method which takes in a 2-dimensional array and a scalar value and returns their product. */ public...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT