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:
Here are the methods needed for CIS425_Course:
--------------------------------------------------------------------
Sample console output:
Sally Smarty has a grade of: 100 on exam 1
Phil Phailure has a grade of: 60 on exam 1
Class average for exam 1: 80.0
------------------------------------------------------------
Here is an outline of your program:
package edu.buffalostate.cis425.sp19.assignments.put-your-lastname-here; /* * don't forget comments */ public class CIS425_Student extends Student { public CIS425_Student( String id, String name, int num_exams ) { } public boolean addGrade( int exam, int grade ) { } public int getGrade( int exam ) { } public String getName() { } } // CIS425_Student class
package edu.buffalostate.cis425.sp19.assignments.put-your-lastname-here; /* * don't forget comments */ public class CIS425_Course { public CIS425_Course( int capacity ) { } public boolean addStudent( String id, String name, int num_exams ) { } public CIS425_Student findStudent( String id ) { } public double computeAverage( int exam ) { } public static void main( String[] args ) { } } // CIS425_Course class
package edu.buffalostate.cis425.sp19.assignments.put-your-lastname-here; /* * don't forget comments */ public class Student { private String id, name; // Constructor, set name of student public Student( String id, String name ) { this.setName(name);
this.setID(id);
}
/**
* set name of student
* @param name string -- student name
*/
public void setName(String name){
this.name = name;
} // return name of student public String getName() { return this.name; } // Add accessors to set the student ID and to get (return) the student ID
} // Student class
All the requirements have been satisfied.
Comment below if you have any doubts or require
modifications..
Please do upvote the answer if it is helpful
thanks...
Getter setter methods for ID field of Student class:
package HomeworkLib;
public class Student {
private String id, name;
// Constructor, set name of student
public Student(String id, String name) {
this.setName(name);
this.setID(id);
}
public void setID(String id) {
this.id = id;
}
public String getID() {
return this.id;
}
/*** set name of student * @param name string -- student name */
public void setName(String name) {
this.name = name;
}
// return name of student
public String getName() {
return this.name;
}
// Add accessors to set the student ID and to get (return) the student ID
} // Student class
Student implementation:
package HomeworkLib;
public class CIS425_Student extends Student {
int exams[];
int num_exams;
public CIS425_Student(String id, String name, int num_exams) {
super(id, name);
exams = new int[num_exams];//Creating array
this.num_exams = num_exams;//Svaed for error checking later
}
public boolean addGrade(int exam, int grade) {
if(exam < 0 || exam > num_exams) {//error checking
return false;
}
exams[exam] = grade;
return true;
}
public int getGrade(int exam) {
if(exam < 0 || exam > num_exams) {//error checking
return -1;
}
return exams[exam];
}
public String getName() {
return super.getName();//Calling super class method
}
} // CIS425_Student class
Course class:
package HomeworkLib;
public class CIS425_Course { int capacity; CIS425_Student roster[]; int currIndex = 0;//to identify where to insert public CIS425_Course(int capacity) { this.capacity = capacity; roster = new CIS425_Student[capacity]; } public boolean addStudent(String id, String name, int num_exams) { CIS425_Student student = new CIS425_Student(id, name, num_exams); if(currIndex < capacity) {//if room is there roster[currIndex] = student; currIndex++; return true; } return false;//No space } public CIS425_Student findStudent(String id) { for(int i = 0; i < currIndex; i++) { if(roster[i].getID().equalsIgnoreCase(id)) {//Student found return roster[i]; } } return null;//No matchng records found } public double computeAverage(int exam) { int sum = 0; for(int i = 0; i < currIndex; i++) { sum += roster[i].getGrade(exam); } return sum / currIndex; } public static void main(String[] args) { CIS425_Course course = new CIS425_Course(2); course.addStudent("1", "Smarty", 2); course.addStudent("2", "Phailure", 2); course.findStudent("1").addGrade(1, 100); System.out.println("Sally Smarty has a grade of:"+ course.roster[0].getGrade(1)+" on exam 1 "); course.findStudent("2").addGrade(1, 60); System.out.println("Phil Phailure has a grade of:"+ course.roster[1].getGrade(1)+" on exam 1 "); System.out.println("Class average for exam 1: " + course.computeAverage(1)); } } // CIS425_Course class
Sample output:
Hi, I am writing Java code and I am having a trouble working it out. The...
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; } ...
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...
I am having trouble getting this program to run with 3 parts. Could I get assistance to understand this code as well? Here is the information given. 7.20 Chapter 7A Create the class described by the UML and directions are given below: Student - studentName: string - midterm: int - finalGrade: int +Student() +Student(name: string, midterm: int, fin: int) +setMidterm(grade: int): void +setFinal(grade: int): void + setStudentName(studentName: string): void +getName():String +getMidterm():int +getFinal():int +computeAverage(): double +computeLetterGrade(): string +printGradeReport():void Create the class...
Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed to the constructor Methods: Accessors int getID( ) String getName( ) Class Roster: This class will implement the functionality of all roster for school. Instance Variables a final int MAX_NUM representing the maximum number of students allowed on the roster an ArrayList storing students Constructors a default constructor should initialize the list to empty strings a single parameter constructor that takes an ArrayList<Student> Both...
Hi, I am having trouble solving the constructor, it requires to ArrayList marks to be a deep copy of the instance variable. I have also provided the J-Unit test I have been provided. import java.util.*; public class GradebookEntry { private String name; private int id; private ArrayList<Double> marks; /** * DO NOT MODIFY */ public String toString() { String result = name+" (ID "+id+")\t"; for(int i=0; i < marks.size(); i++) { /** * display every mark rounded off to two...
Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...
How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...
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)...
Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...
Hello, How can I make the program print out "Invalid data!!" and nothing else if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero? I need this done by tomorrow if possible please. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student...