Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions java-track/assignments/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

public class Course {

private String name;
private int Credits;
private int remainingSeats;
private Student[] roster;

public Course( String name, int Credits, int numberofSeats) {

this.name = name;
this.Credits = Credits;
this.remainingSeats = numberofSeats;
this.roster = new Student[numberofSeats];
}


public String getName() {
return name;
}


public int getCredits() {
return Credits;
}


public int getRemainingSeats() {
return remainingSeats;
}


public Student[] getRoster() {
return roster;
}


public boolean addStudent(Student student) {

if (this.remainingSeats == 0) {
return false;
}

for(int i = 0; i < this.roster.length; i++) {
if(this.roster[i] != null && this.roster[i].getName() == student.getName() ) {
return false;
}
}

this.roster[this.roster.length - this.remainingSeats ] = student;
this.remainingSeats -= 1;
return true;
}

public String generateRoster() {

String rosterNames = "";
for(int i = 0; i < this.roster.length; i++) {
if(this.roster != null) {
String names = roster[i].getName();
rosterNames += names + "\n";
}
}

return rosterNames;
}

public double averageGPA(){
double sumGPA = 0.0;
int numberGPA = 0;
for( int i = 0; i < this.roster.length; i++)
{
if(this.roster[i] != null) {
sumGPA += this.roster[i].getGPA();
numberGPA ++;
}
}
double averageGPA = sumGPA/numberGPA;
return averageGPA;
}

public String toString() {

return this.name + " (" + this.Credits + ")";
}






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

}

}
98 changes: 98 additions & 0 deletions java-track/assignments/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

public class Student {

private String name;
private int StudentID;
private int Credits;
private double GPA;

public Student ( String firstName, String lastName, int StudentID){
this.name = firstName + " " + lastName;
this.StudentID = StudentID;
this.Credits = 0;
this.GPA = 0.0;

}

public Student ( String firstName, String lastName, int studId, int Credits, double GPA){
this.name = firstName + " " + lastName;
this.StudentID = studId;
this.Credits = Credits;
this.GPA = GPA;

}




String getName() {
return name;
}

int getStudentID() {
return StudentID;
}

int getCredits() {
return Credits;
}

double getGPA() {
return GPA;
}

public String getClassStanding()
{
if(this.Credits < 30){
return "Freshman";
}
else if( this.Credits <60) {
return "Sophomore";
}
else if( this.Credits <90) {
return "Junior";
}
else
return "Senior";
}

public void submitGrade(double grade, int credits ){
double totalCredits = this.Credits + credits;
double oldQualityScore = this.GPA * this.Credits;
double newQualityScore = oldQualityScore + (credits * grade);
double newGpa = newQualityScore / totalCredits;
this.GPA = (double) Math.round(newGpa * 1000.0) / 1000.0;
this.Credits += (int) credits;
return;
}

public double computeTuition() {

return (this.Credits / 15) * 20000.0 + (this.Credits % 15) * 1333.33;
}

public Student createLegacy(Student parent1, Student parent2) {
return new Student( parent1.getName(),
parent2.getName(),
(parent1.StudentID + parent2.StudentID),
(Math.max(parent1.getCredits(), parent2.getCredits())),
((parent1.getGPA() + parent2.getGPA())/2.0));

}

public String toString() {
return this.name + "(" + this.StudentID + ")" + " " + this.Credits + " " + this.GPA;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
Student s = new Student("Kwaku", "Twumasi", 3690209, 0,3.6);
Student b = new Student("Kwaku", "Twumasi", 3690209, -2,3.5);
Student m = s.createLegacy(s,b);
System.out.println(s.toString());
System.out.println(s.getClassStanding());
System.out.println(m.toString());

}

}
Loading