(JAVA) Write an abstract superclass encapsulating a
college
applicant: A college applicant has two
attributes:
the applicant’s name and the college the
applicant
is applying to. This class has two non-abstract
subclasses: one encapsulating an applicant for
undergraduate school, and the other
encapsulating
an applicant for graduate school. An applicant
for
undergraduate school has two attributes: a SAT
score
and a GPA. An applicant for graduate school has
one
additional attribute: the college of origin.
It also has a method that returns “from
insideâ€
if the college of origin is the same as the
college
applied to; otherwise, it returns “from
outsideâ€.
You also need to include a class to test two classes.
(JAVA)
Solution:
Please find the code below for the above problem:
// super class with 2 attributes
abstract class Applicant{
public String applicantsname;
public String appliedCollegename;
// class for undergraduate applicant
class underGrad extends Applicant{
double SATscore;
double gpa;
}
// class for graduation applicant
class Grad extends Applicant{
double SATscore;
double gpa;
String collegeOfOrigin;
String getCollegeName()
{
if(appliedCollegename == collegeOfOrigin)
return "from inside";
else
return "from outside";
}
String fromInsideOrOutside =
getCollegeName();
}
// class for testing
public class Test {
public void main(String[]
args) {
// TODO
Auto-generated method stub
Grad grad
= new Grad();
grad.applicantsname = "name of the applicant";
grad.appliedCollegename = "name of the college applied for";
grad.gpa =
9.4;
grad.SATscore =
85;
grad.collegeOfOrigin = "name of the college of origin";
}
}
}
Please find the attached screenshot for the same:
We had nothing much to do for the class UnderGrad, so I have just given values and tested the Class Grad.
You can easily do for UnderGrad by creating an instance for it and then give the values using the instance.
Thanks!
(JAVA) Write an abstract superclass encapsulating a college applicant: A college applicant has two attributes:...
Write an abstract superclass encapsulating a vehicle: A vehicle has two attributes: its owner's name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicycle, ant the other encapsulating a motorized vehicle. A motorized vehicle has the following additional attributes: its engine volume displacement, in liters; and a method computing and returning a measure of horsepower which is the number of liters times the number of wheels. You also need to include a client class...
Write an abstract superclass encapsulating a vehicle: A vehicle has two attributes: its owner's name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicycle, and the other encapsulating a motorized vehicle. A motorized vehicle has the following additional attributes: its engine volume displacement, in liters; and a method computing and returning a measure of horsepower which is the number of liters times the number of wheels. Write an application class utilizing these two classes.
I want to write a superclass with one private attribute and one method in JAVA The super class will later derive into 2 subclasses each with its own private attributes and each with a method that OVERRIDES the superclass method with each subclasses with one method ( that will do something) unique to that subclass. ALL classes must have constructors initializing its attributes and getter/setter methods. Then, in the main method, keep initializing objects of type superclasses based on user's...
PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes: (1) student ID: protected, an integer of 10 digits (2) student name: protected (3) student group code: protected, an integer (1 for undergraduates, 2 for graduate students) (4) student major: protected (e.g.: Business, Computer Sciences, Engineering) Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()). PART II: Create a Java class named...
Please write in Java Language Write an abstract class Shape with an attribute for the name of the shape (you'll use this later to identify a particular shape). Include a constructor to set the name of the shape and an abstract calculateArea method that has no parameters and returns the area of the shape. Optionally, include a constructor that returns the name of the shape and its area (by calling the calculateArea method). Write a Rectangle class that inherits from...
A Java Program Purpose: Work with Abstract classes. Purpose: Abstract classes are import because they ensure than any children which inherit from it must implement certain methods. This is done to enforce consistency across many different classes. Problem: Implement a class called Student. This class needs to be abstract and should contain a String for the name, and a String for the major (and they should be private). The class must have a constructor to set the name and major....
Use Java and please try and show how to do each section. You are creating a 'virtual pet' program. The pet object will have a number of attributes, representing the state of the pet. You will need to create some entity to represent attributes in general, and you will also need to create some specific attributes. You will then create a generic pet class (or interface) which has these specific attributes. Finally you will make at least one subclass of...
Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...
In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...