Question

Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties:...





Part I (20%) [File: Student.java]

Create a class called Student that has the following stored properties:

• StudentID
• First Name
• Last Name

Class Student should have read/write properties, constructor(s) and should implement the Academic interface. For academic methods, return zero for average, zero for credits and false for graduate. Also implement the toString() method that returns the above information as a String.

Part II (5%) [File: Academic.java]
Create an interface Academic that declares three methods:
1. average - that returns the average grade for students
2. credits – returns the number of credits that students have.
3. graduate – Boolean that returns true if the student is eligible to graduate.

Part III (25%) [File: UndergraduateStudent.java]
Create a class called UndergraduateStudent that inherits from Student and has the following members:

• grades – array of student marks for each course

Class UndergraduateStudent should have read/write property, constructors(s) and should override the description property. It should also implement the Academic interface. Undergraduate student get 0.5 credits per course and are eligible to graduate if they have 10 credits. They can only receive a credit if their mark for a course is 50% or higher. It should override the toString() method as well.

Part IV (25%) [File: GraduateStudent.java]
Create a class called GraduateStudent that inherits from Student and has the following members:

• grades - array of student marks for each course
• thesis – description of thesis (String type)
• weeklyHours – number of hours teaching per week

Class GraduateStudent should have read/write properties, constructor(s) and should override the toString() method. It should also implement the Academic interface. Graduate student gets 1.0 credits per course and is eligible to graduate if they have 6 credits. They can only receive a credit if their mark for a course is 60% or higher.


Part VI (25%) [File: main.java]

Create an array that can hold Student objects. Populate this array with 6 objects (3 of UndergraduateStudent and 3 of GraduateStudent objects).

Sort and display the students based on credits earned from high to low and by average from high to low. Also display all other relevant information including availability to graduate.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Academic.java

public interface Academic {

   double average();
   double credits();
   boolean graduate();
}

Student.java

public class Student implements Academic{
  
   int studentID;
   String firstName;
   String lastName;
  
  

   @Override
   public String toString() {
       return "Student [studentID=" + studentID + ", firstName=" + firstName + ", lastName=" + lastName + "]";
   }

   public Student(int studentID, String firstName, String lastName) {
       super();
       this.studentID = studentID;
       this.firstName = firstName;
       this.lastName = lastName;
   }
  
  

   public int getStudentID() {
       return studentID;
   }

   public void setStudentID(int studentID) {
       this.studentID = studentID;
   }

   public String getFirstName() {
       return firstName;
   }

   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   @Override
   public double average() {
       // TODO Auto-generated method stub
       return 0;
   }

   @Override
   public double credits() {
       // TODO Auto-generated method stub
       return 0;
   }

   @Override
   public boolean graduate() {
       // TODO Auto-generated method stub
       return false;
   }

   public int compareTo(UnderGraduateStudent arg0) {
       // TODO Auto-generated method stub
       return 0;
   }

   public void setGrades(double[] grades) {
       // TODO Auto-generated method stub
      
   }
  
  

}

UnderGraduateStudent.java

import java.util.Arrays;

public class UnderGraduateStudent extends Student{
  
   double[] grades;

   public UnderGraduateStudent(int studentID, String firstName, String lastName,double[] grades) {
       super(studentID, firstName, lastName);
       this.grades = grades;
       // TODO Auto-generated constructor stub
   }

  

   public double[] getGrades() {
       return grades;
   }

   public void setGrades(double[] grades) {
       this.grades = grades;
   }

   @Override
   public String toString() {
       return super.toString()+"UnderGraduateStudent [grades=" + Arrays.toString(grades) + "]";
   }
  
  
   @Override
   public double average() {
       // TODO Auto-generated method stub
       double sum =0;
       for(int i=0;i<grades.length;i++)
           sum = sum + grades[i];
      
      
       return sum/grades.length;
   }

   @Override
   public double credits() {
       // TODO Auto-generated method stub
       double credit = 0;
      
       for(int i=0;i<grades.length;i++) {
           if(grades[i]>=50)
               credit = credit + 0.5;
       }
       return credit;
   }

   @Override
   public boolean graduate() {
       // TODO Auto-generated method stub
      
       double credit = credits();
      
       if(credit>=10)
           return true;
      
       return false;
   }

}

GraduateStudent.java

import java.util.Arrays;

public class GraduateStudent extends Student{
  
   double[] grades;

   public GraduateStudent(int studentID, String firstName, String lastName,double[] grades) {
       super(studentID, firstName, lastName);
       this.grades = grades;
       // TODO Auto-generated constructor stub
   }

   public double[] getGrades() {
       return grades;
   }

   public void setGrades(double[] grades) {
       this.grades = grades;
   }
  
  

   @Override
   public double average() {
       // TODO Auto-generated method stub
       double sum =0;
       for(int i=0;i<grades.length;i++)
           sum = sum + grades[i];
      
      
       return sum/grades.length;
   }

   @Override
   public double credits() {
       // TODO Auto-generated method stub
       double credit = 0;
      
       for(int i=0;i<grades.length;i++) {
           if(grades[i]>=60)
               credit = credit + 1;
       }
       return credit;
   }

   @Override
   public boolean graduate() {
       // TODO Auto-generated method stub
      
       double credit = credits();
      
       if(credit>=6)
           return true;
      
       return false;
   }

   @Override
   public String toString() {
       return super.toString()+"GraduateStudent [grades=" + Arrays.toString(grades) + "]";
   }
  
  
  
  
  

}

Main..java

import java.util.Arrays;

public class Main {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       Student students[] = new Student[6];

       // Under Graduate Students
      
       double[] grades = { 10, 20, 30, 40, 60, 70, 80, 40, 90 };

       students[0] = new UnderGraduateStudent(1, "john", "Victor",grades);
      
      
       double[] grades1={60,70,80,40,90,60,70,80,20,90,100};

       students[1] = new UnderGraduateStudent(2, "john", "Jashuar",grades1);
      
       double[] grades2={60,70,80,40,90,60,70,80,20,90,100,60,50,60,67,87,58,74,57,57,78.98,98,77,76,86,79,58,37,80,98.89,70,98};

       students[2] = new UnderGraduateStudent(2, "betal", "Jeshan",grades2);
      
       // Graduate Students
      
       double[] grades3 = { 10, 20, 30, 40, 60, 70, 80, 40, 90 };

       students[3] = new GraduateStudent(1, "john", "blaker",grades3);

       double[] grades4={60,70,80,40,90,60,70,80,20,90,100};

       students[4] = new GraduateStudent(2, "guita", "Blake",grades4);
      
       double[] grades5={60,70,80,40,90,60,70,80,20,90,100,60,50,60,67,87,58,74,57,57,78.98,98,77,76,86,79,58,37,80,98.89,70,98};

       students[5] = new GraduateStudent(2, "john", "JPeterr",grades5);
      
      
      
      
       for (int i = 0; i < 6; i++)
{
for (int j = i + 1; j < 6; j++)
{
if (students[i].credits() > students[j].credits())
{
Student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
      
      
       for(int i=0;i<6;i++) {
           System.out.println(students[i].toString());
           System.out.println("Number of credits is "+ students[i].credits());
           System.out.println("Graduate status is "+students[i].graduate());
          
       }
         
      
      
   }

}

Output

Student [studentID=1, firstName=john, lastName=Victor]UnderGraduateStudent [grades=[10.0, 20.0, 30.0, 40.0, 60.0, 70.0, 80.0, 40.0, 90.0]]
Number of credits is 2.0
Graduate status is false
Student [studentID=1, firstName=john, lastName=blaker]GraduateStudent [grades=[10.0, 20.0, 30.0, 40.0, 60.0, 70.0, 80.0, 40.0, 90.0]]
Number of credits is 4.0
Graduate status is false
Student [studentID=2, firstName=john, lastName=Jashuar]UnderGraduateStudent [grades=[60.0, 70.0, 80.0, 40.0, 90.0, 60.0, 70.0, 80.0, 20.0, 90.0, 100.0]]
Number of credits is 4.5
Graduate status is false
Student [studentID=2, firstName=guita, lastName=Blake]GraduateStudent [grades=[60.0, 70.0, 80.0, 40.0, 90.0, 60.0, 70.0, 80.0, 20.0, 90.0, 100.0]]
Number of credits is 9.0
Graduate status is true
Student [studentID=2, firstName=betal, lastName=Jeshan]UnderGraduateStudent [grades=[60.0, 70.0, 80.0, 40.0, 90.0, 60.0, 70.0, 80.0, 20.0, 90.0, 100.0, 60.0, 50.0, 60.0, 67.0, 87.0, 58.0, 74.0, 57.0, 57.0, 78.98, 98.0, 77.0, 76.0, 86.0, 79.0, 58.0, 37.0, 80.0, 98.89, 70.0, 98.0]]
Number of credits is 14.5
Graduate status is true
Student [studentID=2, firstName=john, lastName=JPeterr]GraduateStudent [grades=[60.0, 70.0, 80.0, 40.0, 90.0, 60.0, 70.0, 80.0, 20.0, 90.0, 100.0, 60.0, 50.0, 60.0, 67.0, 87.0, 58.0, 74.0, 57.0, 57.0, 78.98, 98.0, 77.0, 76.0, 86.0, 79.0, 58.0, 37.0, 80.0, 98.89, 70.0, 98.0]]
Number of credits is 24.0
Graduate status is true

Add a comment
Answer #2

//Student.java

package Test.main;

public class Student implements Academic {

public long studentID;

public String fName;

public String lName;

public Student(long studentID, String fName, String lName) {

this.studentID = studentID;

this.fName = fName;

this.lName = lName;

}

public double Average() {

return 0;

}

public double Credits() {

return 0;

}

public boolean Graduate() {

return false;

}

public String toString() {

return fName + " "+ lName +" " + studentID ;

}

}

//UnderGraduate.java

package Test.main;

public class UndergraduateStudent extends Student{

int[] grades= new int[20];

UndergraduateStudent(long studentID, String fName, String lName,int grades[]) {

super(studentID,fName,lName);

this.grades = grades;

}

public double Average() {

int numberofCourses = grades.length;

double average = 0;

for(int i=0;i<numberofCourses;i++) {

average += grades[i];

}

return average/numberofCourses;

}

public double Credits() {

int numberofCourses = grades.length;

double credits = 0;

for(int i=0;i<numberofCourses;i++) {

if(grades[i]>50)

credits+=0.5;

}

return credits;

}

public boolean Graduate() {

if(Credits()>=10)

return true;

return false;

}

public String toString() {

return super.toString() + grades;

}

}

//Graduate.java

package Test.main;

public class GraduateStudent extends Student{

int grades[];

String thesis;

int weeklyHours;

GraduateStudent(long studentID, String fName, String lName,int grades[], String thesis, int weeklyHours) {

super(studentID,fName,lName);

this.grades = grades;

this.thesis = thesis;

this.weeklyHours = weeklyHours;

}

public double Average() {

int numberofCourses = grades.length;

double average = 0;

for(int i=0;i<numberofCourses;i++) {

average += grades[i];

}

return average/numberofCourses;

}

public double Credits() {

int numberofCourses = grades.length;

double credits = 0;

for(int i=0;i<numberofCourses;i++) {

if(grades[i]>60)

credits++;

}

return credits;

}

public boolean Graduate() {

if(Credits()>=6)

return true;

return false;

}

public String toString() {

return super.toString() + grades+ "" +thesis+ "" + weeklyHours;

}

}

//Main.java

package Test.main;

import java.util.*;

import java.io.*;

interface Academic{

double Average();

double Credits();

boolean Graduate();

String toString();

}

public class Main {

public static void main(String args[]) {

UndergraduateStudent [] UG;

UG = new UndergraduateStudent[3];

int grades1[] = new int[] {48,49,50,52,53,43,78,67,76,56,48,82,81,71,61,61,83,84,74,74};

int grades2[] = new int[] {90,89,50,52,53,43,78,67,76,56,48,82,81,71,61,61,83,84,74,74};

int grades3[] = new int[] {77,78,50,52,53,43,78,67,76,56,48,82,81,71,61,61,83,84,74,74};

UG[0] = new UndergraduateStudent(123, "James" , "Bond" , grades1);

UG[1] = new UndergraduateStudent(456, "Lord" , "Snow" , grades2 );

UG[2] = new UndergraduateStudent(789, "Tom" , "Cruise", grades3);

GraduateStudent [] G;

G = new GraduateStudent[3];

int grades4[] = new int[] {52,53,43,78,67,76,56,48,82,81};

int grades5[] = new int[] {50,52,53,43,78,67,76,56,48,82};

int grades6[] = new int[] {77,78,50,52,53,43,78,67,76,56};

G[0] = new GraduateStudent(112, "Robin", "Singh", grades4, "Recognition System", 20);

G[1] = new GraduateStudent(112, "Sachin", "Ramesh", grades5, "Recommendation System",40);

G[2] = new GraduateStudent(112, "Virendra", "Sehwag", grades6, "Mobile System",30);

double [] avg;

avg = UG.Average();

double [] crd;

crd = UG.Credits;

Arrays.sort(avg);

Arrays.Sort(crd);

double [] avg1;

avg1 = UG.Average();

double [] crd1;

crd1 = UG.Credits;

Arrays.sort(avg1);

Arrays.Sort(crd1);

System.out.printf("Modified arr[] : %s", Arrays.toString(UG));

System.out.printf("Modified arr[] : %s", Arrays.toString(G));

}

}

Add a comment
Know the answer?
Add Answer to:
Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • In Java Create an interface called Amount that includes a method called setPrice (). Create an a...

    In Java Create an interface called Amount that includes a method called setPrice (). Create an abstract class named Book that inherits from the interface Amount. Include a String field for the book’s title and a double field for the book’s Price . Within the class, include a constructor that requires the book title and add two getter methods — one that returns the title and one that returns the price. Include an abstract method named setPrice (). Create a...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Create a java project and create Student class. This class should have the following attributes, name...

    Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...

  • PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...

    PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a method that adds all persons Validate all input, not left empty for First Name, Last Name, Gender and numeric for age and throw an exception if it does not validate within the class. Create a Student Class that: Inherits the Person Class Accepts GPA Validate GPA (>= 0 and <= 4.0) and throw exception if it does not validate within the class. Has methods...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class...

    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...

  • PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property...

    PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property 1 constructor that takes 3 arguments pass each argument to the appropriate property Task 2 In a new file import the Window class Instantiate the Window object Output the two public properties Task 3 Alter the Window class in Task 1 Add an accessor and mutator (the ability to access and change) to the private property Task 4 Create a class named Instrument Give...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT