Question

A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

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 argument and returns the CollegeCourse in that position (0 through 4). Next, create a set method that sets the value of one of the Student’s CollegeCourse objects; the method takes two arguments—a CollegeCourse and an integer representing the CollegeCourse’s position (0 through 4).

B. Write an application that prompts a professor to enter grades for five different courses each for 10 students. Prompt the professor to enter data for one student at a time, including student ID and course data for five courses. Use prompts containing the number of the student whose data is being entered and the course number—for example, Enter ID for student #1, and Enter course ID #5. Verify that the professor enters only A, B, C, D, or F for the grade value for each course. After all the data has been entered, display all the information in order by student then course as shown:

Student #1  ID #101
CS1 1  -- credits. Grade is A
CS2 2  -- credits. Grade is B
CS3 3  -- credits. Grade is C
CS4 4  -- credits. Grade is D
CS5 5  -- credits. Grade is F

CollegeCourse.java

public class CollegeCourse {
private String courseID;
private int credits;
private char grade;
public String getID() {
}
public int getCredits() {
}
public char getGrade() {
}
public void setID(String idNum) {
}
public void setCredits(int cr) {
}
public void setGrade(char gr) {
}
}

InputGrades.java

import java.util.*;
public class InputGrades {
public static void main(String[] args) {
// Write your code here
}
}

Student.java

public class Student {
private int stuID;
private CollegeCourse[] course = new CollegeCourse[5];

public int getID() {
}
public CollegeCourse getCourse(int x) {
}

public void setID(int idNum) {
}
public void setCourse(CollegeCourse c, int x) {
}
}

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

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// InputGrades.java

import java.util.*;

public class InputGrades {

      public static void main(String[] args) {

            // scanner for input

            Scanner scanner = new Scanner(System.in);

            // number of courses and students

            int courseCount = 5, studentsCount = 10;

            // creating an array of Student objects

            Student students[] = new Student[studentsCount];

            // looping for studentCount times

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

                  // creating a student

                  Student s = new Student();

                  // asking for student id, reading and updating in s

                  System.out.print("Enter student id: ");

                  int studentId = scanner.nextInt();

                  s.setID(studentId);

                  int index = 0;

                  // looping until all course data is entered for current student

                  while (index < courseCount) {

                        // asking for course data. to make things simple and easy to

                        // input, we are reading course id, credits and grade together

                        // (in one line), or it will be difficult to enter 3*5*10 inputs

                        // separately

                        System.out.print("Enter id, credits and grade for course#"

                                    + (index + 1) + ": ");

                        // the input must be in the format <courseId> <credits> <grade>

                        String courseId = scanner.next();

                        int credits = scanner.nextInt();

                        char grade = scanner.next().toUpperCase().charAt(0);

                        // validating the grade

                        if (grade == 'A' || grade == 'B' || grade == 'C'

                                    || grade == 'D' || grade == 'F') {

                              // valid, creating a Course and setting attributes

                              CollegeCourse course = new CollegeCourse();

                              course.setCredits(credits);

                              course.setGrade(grade);

                              course.setID(courseId);

                              // setting course at index position in Student s

                              s.setCourse(course, index);

                              // updating index

                              index++;

                        } else {

                              // invalid grade

                              System.out.println("Invalid grade!");

                        }

                  }

                  // adding s to array at index i

                  students[i] = s;

            }

            // looping and displaying details of all students

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

                  System.out.println("\nStudent #" + (i + 1) + " ID #"

                              + students[i].getID());

                  for (int j = 0; j < courseCount; j++) {

                        // since we implemented toString method in CollegeCourse class,

                        // we can simply print it

                        System.out.println(students[i].getCourse(j));

                  }

            }

      }

}

// Student.java

public class Student {

      private int stuID;

      private CollegeCourse[] course = new CollegeCourse[5];

      public int getID() {

            return stuID;

      }

      public CollegeCourse getCourse(int x) {

            return course[x];

      }

      public void setID(int idNum) {

            stuID = idNum;

      }

      public void setCourse(CollegeCourse c, int x) {

            course[x] = c;

      }

     

}

// CollegeCourse.java

public class CollegeCourse {

      private String courseID;

      private int credits;

      private char grade;

      public String getID() {

            return courseID;

      }

      public int getCredits() {

            return credits;

      }

      public char getGrade() {

            return grade;

      }

      public void setID(String idNum) {

            courseID = idNum;

      }

      public void setCredits(int cr) {

            credits = cr;

      }

      public void setGrade(char gr) {

            grade = gr;

      }

      // returns a String containing course id, credits and grade

      public String toString() {

            return courseID + " " + credits + " -- credits. Grade is " + grade;

      }

}

/*sample OUTPUT for 2 courses & 3 students*/

Enter student id: 101

Enter id, credits and grade for course#1: CS1 1 A

Enter id, credits and grade for course#2: CS2 2 X

Invalid grade!

Enter id, credits and grade for course#2: CS2 2 B

Enter student id: 103

Enter id, credits and grade for course#1: CS1 1 C

Enter id, credits and grade for course#2: ENG 2 D

Enter student id: 107

Enter id, credits and grade for course#1: CS2 1 B

Enter id, credits and grade for course#2: CS2 2 C

Student #1 ID #101

CS1 1 -- credits. Grade is A

CS2 2 -- credits. Grade is B

Student #2 ID #103

CS1 1 -- credits. Grade is C

ENG 2 -- credits. Grade is D

Student #3 ID #107

CS2 1 -- credits. Grade is B

CS2 2 -- credits. Grade is C

Add a comment
Know the answer?
Add Answer to:
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...
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
  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

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

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

  • Create an abstract Student class for Parker University. The class contains fields for student ID number,...

    Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for...

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int...

    Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...

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

  • (To be written in Java code) Create a class named CollegeCourse that includes the following data...

    (To be written in Java code) Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display()...

  • create a programn in C++ that creates a class that represents a manufactured part on a...

    create a programn in C++ that creates a class that represents a manufactured part on a bill of material (BOM). with the following attributes: identifier (The parts identifier as an alpha numeric string), drawing (The AutoCAD drawing file that represents the part), quantity (The number of parts that are required). implement the functions for the Part class in the file Part.cpp. The file main.cpp will only be used for testing purposes, no code should be written in main.cpp. -part.cpp file:...

  • You will create a class to keep student's information: name, student ID, and grade. The program...

    You will create a class to keep student's information: name, student ID, and grade. The program will have the following functionality: - The record is persistent, that is, the whole registry should be saved on file upon exiting the program, and after any major change. - The program should provide the option to create a new entry with a student's name, ID, and grade. - There should be an option to lookup a student from his student ID (this will...

  • Here is the code from the previous three steps: #include <iostream> using namespace std; class Student...

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

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