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
}
/**
* Accessor methods.
*/
// TODO: define a setter and a getter method for each of the
instance variables
/**
* public methods.
*/
@Override
public String toString() {
// TODO: implement so that a string is returned in the following
format:
// "INFS 612 Communication Systems�
}
public String fullString() {
// TODO: implement so that a string is returned in the following
format:
//"INFS 612 Communication Systems, (3) credit hours.�
}
}
/**
* A sub-class which extends the Course class to keep track of a
student
* registration in a course, and also perform
*/
public class TranscriptEntry extends Course
{
/**
* Attributes
*
*/
private String semester;
private int year;
private String grade;
private boolean active;
public TranscriptEntry(Course c, String semester, int year) {
// TODO
// note: active must be initialized to true.
}
/**
* Accessor methods methods.
* // TODO
* define a setter and a getter for each instance variable.
* note: Do not write accessor methods for the active variable since
its an internal variable:
* if a course is flagged active, then the student is currently
enrolled in that course.
* When a grade is posted for a course, active is set to
false.
*/
/**
* Public Methods.
*
*/
public boolean isActive() {
//TODO
}
@Override
public String toString() {
// return a string with the following format:
// "\tINFS 510 Database Systems, credits: 3, GRADE: A"
// And if the student does not have an assigned grade, then the
string value should be:
// "\tINFS 510 Database Systems, credits: 3"
//TODO
}
}
/**
* The main class in the student registration program..
* This class defines public methods to provide the following
functionality:
* - maintains the course catalog.
* - registers and drop courses for students
* - at the end of semester, post grades
*
*/
import java.util.Scanner;
public class Registrar {
/**
* Attributes.
*/
private Student [] students;
private int numStudents; // keeps track of the students array
size
private Course [] courseCatalog;
private int numCourses; // keeps track of the courseCatalog array
size
private String semester;
private int year;
/**
* Constructor.
*/
public Registrar(String semester, int year) {
// TODO.
// note: maximum number of students is 100, and maximum number of
courses is 50.
//
}
/**
* Accessor methods.
*/
public void setSemester(String semester) {
this.semester=semester;}
public String getSemester() { return semester; }
public void setYear(int year) { this.year=year;}
public int getYear() { return year; }
/**
* Public methods.
*/
public boolean addCourse(String code, String title, int hours)
{
// if courseCatalog is full , return false, otherwise, add course
to the catalog.
// TODO
}
public String getCourseCatalog() {
String str="";
for (Course c : courseCatalog)
if (c == null) break;
else str = str + c.fullString() +"\n";
return str;
}
public boolean addStudent(String fname, String lname, long id,
String major,
String degree, String highSchool) {
// if the students array is full, return false.
// otherwise add the student information to the students
arrays
// TODO
}
public boolean addStudent(String fname, String lname, long id,
String major,
String degree, String uMajor, String uInstit) {
// an overloaded method which does the sam as the other addStudent
method
// TODO
}
public boolean register(long id, String courseCode) {
// first check if the course is offered (by searching courseCatalog
array using courseCode), if
// the course is not found return false.
// then find the student object in the students array using their
id number, if no student is found
// return false.
// otherwise register the student in the class and return
true.
// TODO
}
public boolean drop(long id, String courseCode) {
// Find the student object in the students array using their id
number, if no student is found
// return false. otherwise drop the course for the student.
// TODO
}
public boolean postGrade(long id, String courseCode, int score)
{
// Find the student object in the students array using their id
number, if no student is found
// return false. otherwise post a course grade for the
student.
// TODO
}
public String getProgress(long gnum, String semester, int year)
{
Student s = findStudent(gnum);
if (s == null)
return "Student "+gnum+" not found";
String str = String.format(" %s\n", s.toString());
return str+s.getClassList(semester, year);
}
public static String getDeptName(String code) {
// given a course code, this static method will return the
name
// of the academic department to which the course belong
String dept = (new Scanner(code)).next();
if (dept.equalsIgnoreCase("CS"))
return "Computer Science";
else if (dept.equalsIgnoreCase("INFS"))
return "Information Systems";
else if (dept.equalsIgnoreCase("IT"))
return "Information Tecchnoloy";
else if (dept.equalsIgnoreCase("MATH"))
return "Mathematics";
else if (dept.equalsIgnoreCase("PHYS"))
return "Physics";
else return null;
}
/**
* Private methods.
* you will need few helper methods.
*/
}
Course.java:
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()
{
}
public Course(String code2, String title2, int
credits2) {
// TODO Auto-generated constructor
stub
this.code = code2;
this.title = title2;
this.dept = Registrar.getDeptName(code2);
this.credits = credits2;
}
/**
* Accessor methods.
*/
// TODO: define a setter and a getter method for each
of the instance
// variables
public void setCode(String code) {
this.code = code;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public int getCredits() {
return credits;
}
public void setCredits(int credits) {
this.credits = credits;
}
/**
* public methods.
*/
@Override
public String toString() {
// TODO: implement so that a string
is returned in the following format:
// "INFS 612 Communication
Systems�
return code+" "+title;
}
public String fullString() {
// TODO: implement so that a string
is returned in the following format:
// "INFS 612 Communication Systems,
(3) credit hours.�
return code+"
"+title+",("+credits+") credit hours.";
}
public String getCode() {
// TODO Auto-generated method
stub
return code;
}
}
TranscriptEntry.java:
/**
* A sub-class which extends the Course class to keep track of a
student
* registration in a course, and also perform
*/
public class TranscriptEntry extends Course {
/**
* Attributes
*
*/
private String semester;
public String getSemester() {
return semester;
}
public void setSemester(String semester) {
this.semester = semester;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
private int year;
private String grade;
private boolean active;
public TranscriptEntry(Course c, String semester,
int year) {
// TODO
// note: active must be initialized
to true.
super(c.getCode(),c.getTitle(),c.getCredits());
this.semester=semester;
this.year=year;
this.active=true;
}
/**
* Accessor methods methods. // TODO define a setter
and a getter for each
* instance variable. note: Do not write accessor
methods for the active
* variable since its an internal variable: if a course
is flagged active,
* then the student is currently enrolled in that
course. When a grade is
* posted for a course, active is set to false.
*/
/**
* Public Methods.
*
*/
public boolean isActive() {
// TODO
return this.active;
}
@Override
public String toString() {
// return a string with the
following format:
// "\tINFS 510 Database Systems,
credits: 3, GRADE: A"
// And if the student does not have
an assigned grade, then the string
// value should be:
// "\tINFS 510 Database Systems,
credits: 3"
// TODO
if(grade.equalsIgnoreCase("")){
return "\t"+getCode()+" "+getTitle()+", credits:
"+getCredits();
}
else{
return "\t"+getCode()+" "+getTitle()+", credits:
"+getCredits()+", GRADE: "+grade;
}
}
}
Registrar.java:
/**
* The main class in the student registration program..
* This class defines public methods to provide the following
functionality:
* - maintains the course catalog.
* - registers and drop courses for students
* - at the end of semester, post grades
*
*/
import java.util.Scanner;
public class Registrar {
/**
* Attributes.
*/
private Student[] students;
private int numStudents; // keeps track of the
students array size
private Course[] courseCatalog;
private int numCourses; // keeps track of the
courseCatalog array size
private String semester;
private int year;
/**
* Constructor.
*/
public Registrar(String semester, int year) {
// TODO.
// note: maximum number of students
is 100, and maximum number of
// courses is 50.
//
this.semester = semester;
this.year = year;
students = new Student[100];
courseCatalog = new Course[50];
numStudents = 0;
numCourses = 0;
}
/**
* Accessor methods.
*/
public void setSemester(String semester) {
this.semester = semester;
}
public String getSemester() {
return semester;
}
public void setYear(int year) {
this.year = year;
}
public int getYear() {
return year;
}
/**
* Public methods.
*/
public boolean addCourse(String code, String title,
int hours) {
// if courseCatalog is full ,
return false, otherwise, add course to the
// catalog.
// TODO
if (numCourses <
courseCatalog.length) {
Course course = new Course(code, title, hours);
courseCatalog[numCourses] = course;
numCourses += 1;
return true;
}
else
return false;
}
public String getCourseCatalog() {
String str = "";
for (Course c :
courseCatalog)
if (c ==
null)
break;
else
str = str + c.fullString() + "\n";
return str;
}
public boolean addStudent(String fname, String
lname, long id, String major, String degree, String highSchool)
{
// if the students array is full,
return false.
// otherwise add the student
information to the students arrays
// TODO
if(numStudents<students.length){
Student student = new
Student(fname,lname,id,major,degree,highSchool);
students[numStudents]=student;
numStudents+=1;
return true;
}else
return false;
}
public boolean addStudent(String fname, String
lname, long id, String major, String degree, String uMajor,
String uInstit)
{
// an overloaded method which does
the sam as the other addStudent
// method
// TODO
if(numStudents<students.length){
Student student
= new Student(fname,lname,id,major,degree,uMajor,uInstit);
students[numStudents]=student;
numStudents+=1;
return true;
}else
return false;
}
public boolean register(long id, String courseCode)
{
// first check if the course is
offered (by searching courseCatalog
// array using courseCode),
if
// the course is not found return
false.
// then find the student object in
the students array using their id
// number, if no student is
found
// return false.
// otherwise register the student
in the class and return true.
// TODO
boolean
courseCodeAvailable=false;
for(int i=0;i<numCourses;i++){
if(courseCatalog[i].getCode().equalsIgnoreCase(courseCode)){
courseCodeAvailable=true;
break;
}
}
if (!courseCodeAvailable){
return false;
}
boolean studentIdAvailable=false;
for(int i=0;i<numStudents;i++){
if(students[i].getId()==id){
studentIdAvailable=true;
students[i].setCourseCode(courseCode);
break;
}
}
if (!studentIdAvailable){
return false;
}
return true;
}
public boolean drop(long id, String courseCode)
{
// Find the student object in the
students array using their id number,
// if no student is found
// return false. otherwise drop the
course for the student.
// TODO
boolean
studentIdAvailable=false;
for(int i=0;i<numStudents;i++){
if(students[i].getId()==id){
studentIdAvailable=true;
students[i].setCourseCode(null);;
break;
}
}
if (!studentIdAvailable){
return false;
}
return true;
}
public boolean postGrade(long id, String
courseCode, int score) {
// Find the student object in the
students array using their id number,
// if no student is found
// return false. otherwise post a
course grade for the student.
// TODO
boolean
studentIdAvailable=false;
for(int i=0;i<numStudents;i++){
if(students[i].getId()==id){
studentIdAvailable=true;
students[i].setGrade(calculateGrade(score));
break;
}
}
if (!studentIdAvailable){
return false;
}
return true;
}
public String getProgress(long gnum, String
semester, int year) {
Student s =
findStudent(gnum);
if (s == null)
return "Student
" + gnum + " not found";
String str = String.format(" %s\n",
s.toString());
return str +
s.getClassList(semester, year);
}
public static String getDeptName(String code) {
// given a course code, this static
method will return the name
// of the academic department to
which the course belong
String dept = (new
Scanner(code)).next();
if
(dept.equalsIgnoreCase("CS"))
return "Computer
Science";
else if
(dept.equalsIgnoreCase("INFS"))
return
"Information Systems";
else if
(dept.equalsIgnoreCase("IT"))
return
"Information Tecchnoloy";
else if
(dept.equalsIgnoreCase("MATH"))
return
"Mathematics";
else if
(dept.equalsIgnoreCase("PHYS"))
return
"Physics";
else
return
null;
}
/**
* Private methods. you will need few helper
methods.
*/
private Student findStudent(long gnum) {
boolean studentIdAvailable;
for(int
i=0;i<numStudents;i++){
if(students[i].getId()==gnum){
studentIdAvailable=true;
return students[i];
}
}
return null;
}
public String calculateGrade(int score)
{
String grade ="";
if(score>=80){
grade = "A";
}else if(score>=60 &&
score<80){
grade = "B";
}
else if(score>=40 &&
score<60){
grade = "C";
}
else {
grade = "D";
}
return grade;
}
}
Student.java:
public class Student {
String fname;
String lname;
long id;
String major;
String degree;
String uMajor;
String uInstit;
String highSchool;
String courseCode;
String grade;
public String getCourseCode() {
return courseCode;
}
public void setCourseCode(String courseCode) {
this.courseCode = courseCode;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
Student(String fname,String lname,long id,String
major,String degree, String highSchool)
{
this.fname =fname;
this.lname = lname;
this.id =id;
this.major = major;
this.degree = degree;
this.highSchool = highSchool;
}
Student(String fname, String lname, long id, String
major, String degree, String uMajor,
String
uInstit)
{
this.fname =fname;
this.lname = lname;
this.id =id;
this.major = major;
this.degree = degree;
this.uMajor = uMajor;
this.uInstit = uInstit;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getDegree() {
return degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public String getuMajorl() {
return uMajor;
}
public void setuMajorl(String uMajorl) {
this.uMajor = uMajorl;
}
public String getuInstit() {
return uInstit;
}
public void setuInstit(String uInstit) {
this.uInstit = uInstit;
}
public String getClassList(String semester, int year)
{
// TODO Auto-generated method
stub
return null;
}
}
Main.java:
public class Main {
public static void main(String args[])
{
Course c = new Course("INFS
612","Communication Systems",3);
TranscriptEntry te = new
TranscriptEntry(c, "2nd",2019);
Registrar r = new
Registrar("2nd",2019);
r.addCourse("INF2","DBMS",
150);
r.addStudent("John", "Wick", 1,
"ing","ME","Xaviers");
System.out.println(te.fullString());
}
}
Sample Output:
Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...
Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...
I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student { private String firstName; private String lastName; private String id; private boolean tuitionPaid; public Student(String firstName, String lastName, String id, boolean tuitionPaid) { this.firstName=firstName; this.lastName=lastName; this.id=id; this.tuitionPaid=tuitionPaid; } ...
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)...
Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The clone method must allow a deep copy on the students field. In addition, add the equals(Object o) and the toString() methods. Write a test program to invoke the compareTo, clone, equals, and toString methods in a meaningful way. Below is the Listing from the book that needs to be rewritten public class Course { private String courseName; private String[] students = new...
Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{ /** collection of Students */ private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...
I asked this a little bit ago but didn't clarify exactly what I needed, so I'm asking again...I've attached my code below the question. Thanks! Do not change the original contract of the Course class. Instead, ONLY change the implementation of property students, from an array to and ArrayList, and update any methods in class Course that access students to reflect ArrayList. The methods are overridden. That means that you do not need to change the header for methods, only...
using basic c++ please!!! 6. (21%) Consider the following definitions class Student { class Section public: string getFirst (); string getLast (); intgetGrade () void setFirst (string s); void setLast (string s); void setGrade(int g); numStudents (); in Student getNthStudent (int n); string getCourse (); string getInstructor (); private: private: string firstName; string lastName; int Student students [SIZE]; string course; string instructor; grade ; Write a function, honorRoll that returns a dynamic array containing only those students in section sec...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...