make a University app to have a simple system to keep track of all the students (graduate and undergrads).To do that the following classes are needed for this object-oriented database.
Student
- StudentID : Integer
- stdFirstName: String
- stdLastName: String
- stdMarks : Double []
- stdAddress: Address
** Class Student should have set/get
properties, constructor and have following methods:
Average() - that returns the average
grade for students
toString() method that returns the
above information as a String
- A class called Address which can be that can be added
into the class student
Address
- streetInfo: String
- city: String
- postalCode: String
- province: String
- country: String
** Class Address should have set/get
properties, constructor and following method:
toString() method that returns the
above information as a String
- A class called UndergraduateStudent that inherits
from Student and has the following members:
Undergrad Student
- subject: String
- yearOfEntry :Integer
***Class Student should have set/get
properties, constructor and following method:
Graduate() - Boolean that
returns true if the Student is eligible to graduate when the average of
their marks is greater than 50.
toString() method that returns the
above information as a String
- A class called GraduateStudent that inherits
from Student and has the following members:
Graduate Student
- subject : String
- yearOfEntry :Integer
- thesisTopic: String
Class Student should have set/get
properties, constructor and following method:
Graduate() - Boolean that
returns true if the Student is eligible to graduate when the average of
their marks is greater than 70.
toString() method that returns the
above information as a String
Summary of Operations
System Menu:
- Add undergraduate student
- Add graduate student
- View all the students
- View only eligible students for graduation
- exit
Overview:
- You may use array or ArrayList to store all your
students(graduate and undergrad) into one array of objects.
- If you use an Array, you may assume the user does not
enter more than ten students in total into the system
1 -Add undergraduate Students: this
menu should accept all the necessary parameters for undergraduate
students and create an instance from undergraduate class and store it
into students array.
2 -Add graduate student:
this menu should accept all the necessary parameters for graduate
students. It should create an instance from the graduate class and store
it in the students' array.
3- View all the students: view
all the relevant information of students (graduate and undergraduate) from
students array
4- View only eligible students
for graduation: view all the relevant information (graduate and
undergraduate) from the students' array only if they are eligible to graduate.
5 - Exit: exit the running
menu (program)
Answer
import
java.util.Arrays;
import
java.util.Scanner;
public
class Address {
String streetInfo;
String city;
String
postalCode;
String
province;
String
country;
//constructor
public
Address(String streetInfo , String city ,String postalCode,String province,
String country ) {
this.streetInfo = streetInfo;
this.city = city;
this.postalCode = postalCode;
this.province = province;
this.country = country;
}
//
getter methods
public
String getstreetInfo (){
return
streetInfo;
}
public
String getcity(){
return
city;
}
public
String getpostalCode(){
return
postalCode;
}
public
String getprovince (){
return
province;
}
public
String getcountry (){
return
country;
}
//
setter methods
public
void setstreetInfo (String s){
streetInfo
= s;
}
public
void setcity( String f){
city =
f;
}
public
void setpostalCode(String s){
postalCode
= s;
}
public void setprovince (String m){
province
= m;
}
public
void setcountry (String c){
country
=c ;
}
public
String toString() {
return "streetInfo: "+
streetInfo+"\ncity: "+city+"\npostalCode:
"+postalCode+"\nprovince:
"+province+"\ncountry"+country;
}
}
import
java.util.Arrays;
import
java.util.Scanner;
public
class GraduateStudent extends Student {
String
subject;
int
yearOfEntry;
String
thesisTopic;
public
GraduateStudent( int StudentID , String stdFirstName ,String stdLastName,double
[] stdMarks , Address stdAddress,
String
subject , int yearOfEntry , String thesisTopic){
super(StudentID
,stdFirstName ,stdLastName,stdMarks,stdAddress);
this.subject
= subject;
this.yearOfEntry
= yearOfEntry;
this.thesisTopic
= thesisTopic ;
}
//
getter methods
public
String getsubject (){
return subject;
}
public
int getyearOfEntry(){
return yearOfEntry;
}
public
String getthesisTopic(){
return thesisTopic;
}
//
setter methods
public
void setsubject (String s){
subject = s ;
}
public
void setyearOfEntry(int y){
yearOfEntry = y ;
}
public
void setthesisTopic(String t){
thesisTopic = t;
}
public
String toString() {
return
super.toString()+"\nsubject: "+subject+"\nyear Of Entry:
"+yearOfEntry+"\nthesisTopic: "+thesisTopic;
}
public
boolean Graduate(){
if(
super.Average() > 70 )
return
true;
return
false;
}
}
import
java.util.Arrays;
import
java.util.*;
public
class Maindriver {
public
static void main(String[] args) {
Scanner
input = new Scanner(System.in);
int
StudentID;
String
stdFirstName;
String
stdLastName;
Address
stdAddress;
String
subject;
int
yearOfEntry;
String
thesisTopic ;
//
instance class
UndergraduateStudent
Undergraduate =null;
//
instance class
GraduateStudent Graduate =null;
//
student array
Student[]
studentsarray = new Student[10];
int
index = 0;
//
while loop
while(true){
menu
();
int
option = input.nextInt();
switch(option){
case 1:
System.out.println(
"StudentID: ");
StudentID
= input.nextInt();
System.out.println(
"FirstName :");
stdFirstName=
input.next();
System.out.println(
"LastName :");
stdLastName
= input.next();
System.out.println(
"Enter Marks with space between them : ");
input.nextLine();
String
mark [] = input.nextLine().split(" ");
double
stdMarks[] = new double[mark.length ];
//
convert string to double
for(int
i = 0 ; i < mark.length ; i++ )
stdMarks[i] = Double.valueOf(mark[i]) ;
System.out.println(
"Address: ");
System.out.println(
"streetInfo: ");
String streetInfo = input.next();
System.out.println( "city:
");
String city= input.next();
System.out.println(
"postalCode: ");
String postalCode= input.next();
System.out.println(
"province: ");
String province= input.next();
System.out.println(
"country: ");
String country= input.next();
stdAddress
= new Address( streetInfo ,city , postalCode, province,country );
System.out.println(
"subject: ");
subject=
input.next();
System.out.println(
"year Of Entry: ");
yearOfEntry = input.nextInt();
Undergraduate
= new UndergraduateStudent( StudentID ,
stdFirstName , stdLastName, stdMarks ,
stdAddress,
subject , yearOfEntry);
studentsarray[index]
= Undergraduate;
index++;
break;
case 2:
System.out.println(
"StudentID: ");
StudentID
= input.nextInt();
System.out.println(
"FirstName :");
stdFirstName=
input.next();
System.out.println(
"LastName :");
stdLastName
= input.next();
System.out.println(
"Enter Marks with space between them : ");
input.nextLine();
String
mark2 [] = input.nextLine().split(" ");
double
stdMarks2[] = new double[mark2.length ];
//
convert string to double
for(int
i = 0 ; i < mark2.length ; i++ )
stdMarks2[i] = Double.valueOf(mark2[i]) ;
System.out.println(
"Address: ");
System.out.println(
"streetInfo: ");
streetInfo = input.next();
System.out.println( "city:
");
city= input.next();
System.out.println(
"postalCode: ");
postalCode= input.next();
System.out.println(
"province: ");
province= input.next();
System.out.println(
"country: ");
country= input.next();
stdAddress
= new Address( streetInfo ,city , postalCode, province,country );
System.out.println(
"subject: ");
subject=
input.next();
System.out.println(
"year Of Entry: ");
yearOfEntry = input.nextInt();
System.out.println(
"the Topic: ");
thesisTopic = input.next();
Graduate
= new GraduateStudent( StudentID ,
stdFirstName , stdLastName, stdMarks2 ,
stdAddress,
subject , yearOfEntry , thesisTopic);
studentsarray[index]
= Graduate;
index++;
break;
case 3:
System.out.println("View
all the students");
for(
int i = 0 ; i <studentsarray.length ; i++){
if(studentsarray[i] != null )
System.out.println(studentsarray[i]);
}
break;
case 4:
if(
Graduate != null && Undergraduate !=null ){
System.out.println("View
only eligible students for graduation");
for(
int i = 0 ; i <studentsarray.length ; i++){
if(Graduate.Graduate()
&& Undergraduate.Graduate())
System.out.println( studentsarray[i] );
}
}
else
if( Graduate != null ){
System.out.println("View
only eligible students for graduation");
for(
int i = 0 ; i <studentsarray.length ; i++){
if(Graduate.Graduate() )
System.out.println( studentsarray[i] );
}
}
else
if( Undergraduate != null ){
System.out.println("View
only eligible students for graduation");
for(
int i = 0 ; i <studentsarray.length ; i++){
if(Undergraduate.Graduate())
System.out.println( studentsarray[i] );
}
}else{
System.out.println("add the
element to list first in order to print ");
}
break;
case 5:
System.exit(0);
break;
} // end switch
} //
end while
} //
end main
public
static void menu (){
System.out.println("1.Add
undergraduate student\n"+
"2.Add graduate student\n"+
"3.View all the students\n"+
"4.View only eligible students for
graduation\n"+
"5.exit\nyour option: " );
}
}// end
class
import
java.util.Arrays;
import
java.util.Scanner;
public
class Student {
int
StudentID ;
String
stdFirstName;
String
stdLastName;
double
[] stdMarks ;
Address
stdAddress ;
//constructor
public
Student(int StudentID , String stdFirstName ,String stdLastName,double []
stdMarks , Address stdAddress ) {
this.StudentID = StudentID;
this.stdFirstName =
stdFirstName;
this.stdLastName = stdLastName;
this.stdMarks = stdMarks;
this.stdAddress = stdAddress;
}
//
getter methods
public
int getStudentID (){
return
StudentID;
}
public
String getstdFirstName(){
return
stdFirstName;
}
public
String getstdLastName(){
return
stdLastName;
}
public
double [] getstdMarks (){
return
stdMarks;
}
public
Address getstdAddress (){
return
stdAddress;
}
//
setter methods
public
void StudentID (int s){
StudentID
= s;
}
public
void setstdFirstName( String f){
stdFirstName
= f;
}
public
void setstdLastName(String s){
stdLastName
= s;
}
public void setstdMarks (double [] m){
stdMarks
= m;
}
public
void setstdAddress (Address s){
stdAddress
=s ;
}
public
double Average(){
double
sum = 0;
for(int
i = 0 ; i < stdMarks.length; i++){
sum += stdMarks[i];
}
return sum / (double
)stdMarks.length;
}
public
String toString() {
return "\nStudentID:
"+StudentID + "\nFirstName: "+stdFirstName +"\nLastName:
"+stdLastName+"\nMarks: "+Arrays.toString(stdMarks)+
"\nAddress: "+
stdAddress.toString()+"\n";
}
public boolean Graduate(){
return Average() > 50 ? true :false ;
}
}
import
java.util.Arrays;
import
java.util.Scanner;
public
class UndergraduateStudent extends
Student {
String
subject;
int yearOfEntry;
public
UndergraduateStudent (int StudentID , String stdFirstName ,String
stdLastName,double [] stdMarks , Address stdAddress,
String
subject , int yearOfEntry) {
super(StudentID
,stdFirstName ,stdLastName,stdMarks,stdAddress);
this.subject = subject;
this.yearOfEntry = yearOfEntry;
}
//
getter methods
public
String getsubject (){
return subject;
}
public
int getyearOfEntry(){
return yearOfEntry;
}
//
setter methods
public
void setsubject (String s){
subject = s ;
}
public
void setyearOfEntry(int y){
yearOfEntry = y ;
}
//Graduate()
- Boolean that returns true if the Student is eligible to graduate when the
average of their marks is greater than 50.
public
boolean Graduate(){
if(
super.Average() > 50 )
return
true;
return
false;
}
public
String toString() {
return
super.toString()+"\nsubject: "+subject+"\nyear Of Entry:
"+yearOfEntry;
}
}