CSC236 Data Structures in Java
Lab 1

The main disadvantage of arrays is that they are fixed in size. Once you create the array you cannot make it bigger or smaller. In this lab you will create a class that is similar to an array, but it is able to increase and decrease in size.

We will use this array class to hold the records for all courses taken at MCC by a student.

Part 1

Course Class

Create a class to hold the information on a course attempt. This class has the following fields:

credits is an int, the rest of the fields are Strings.

The methods for the Course class are:

After you complete your Course class use CourseTest.java to make sure that your Course class works correctly. Check the output from CourseTest to verify that your Course class is working correctly before you proceed to Part 2 of the lab.

Part 2

MyArray Class

This class creates an array that can get larger if necessary. The MyArray object will contain a Java array to hold its elements, but the client/demo code cannot use subscripts since a MyArray object is not actually an array. Instead the class will have methods to add, modify, and access the elements stored in a MyArray object.

Each element stored in a MyArray object has a position. The first element is at position 0.

Your class should have the following fields:

Your class should have the following methods:

After you complete your MyArray class use MyArrayTest.java to make sure that your MyArray class works correctly. Check the output from MyArrayTest to verify that your MyArray class is working correctly before you proceed to Part 3 of the lab.

Part 3

Client Code

Create a class called Transcript to contain your client/demo code. In this class you will read a transcript from a file, print the transcript, and calculate and print the number of credits and GPA. Then you will add and drop current semester courses from the keyboard, and print the transcript again.

  1. Create a MyArray of Course objects.
  2. Read the student name, student number, and completed courses from the file transcript.txt. The file has student name on the first line, student number on the second line, and then the courses, with each field on a separate line, in the following order: course number, course name, section, department, semester (Fall, Spring, Winter, or Summer and year), grade, credits. For each course read the fields, create a Course object, and add it to the MyArray of Courses.
  3. Print the student name and student number, then print all completed courses.
  4. Calculate and print the total credits earned.
  5. Calculate and print the GPA. This table shows the points earned for each grade.
    grade points
    A 4.0
    A- 3.7
    B+ 3.5
    B 3
    B- 2.7
    C+ 2.5
    C 2.0
    D 1.0
    F 0
    Calculate the grade points for a course by multiplying the points earned by the number of credits. Then calculate the GPA, by adding the points earned for all courses and dividing by the total number of credits completed.
  6. Prompt the user to enter four courses being taken during the current semester. Use an empty String for the grade.
  7. Prompt the user to drop one of the courses. Prompt for the course number, section, and semester. Create a Course object with these fields, find the matching course in the MyArray, and remove it.
  8. Print the student name and number and all of the courses in the MyArray.

Do not put all of the code in main. Create some other methods so that main is not too long.



Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2023