Comp 101 Connect Carolina 2.0 - Jog

Making Schedules -- Jog

Now that you have made courses, it is time to made a Schedule class which can hold Course objects. Everyone needs a little structure in their life! Like in walk, after creating a Schedule class, you will create functions to create Schedule objects and print Schedule objects.

Part 0. Starting the Dev Environment

As with in lecture, begin by opening up VSCode, ensuring your project is still open, and then running the following two commands in the VSCode Integrated Terminal:

  1. npm run pull
  2. npm start

Part 1. Setting up an App

In the same directory used in lecture:

  1. Right click on the ps07-connect-carolina folder
  2. Select "New File"
  3. Name the new file: jog-app.ts
    1. Note: capitalization and punctuation are important!

Part 2. Starting your Code

We don't want any good work to go to waste! Copy and paste all of your code from Walk into Jog, and delete all of the code inside main.


Part 3: Making Schedules

Part 3.1: Define and export a Schedule class

A schedule usually has an owner and a list of courses in it, so in your schedule class you should have two properties called owner (string) and courses (Course array). They should be initialized to an empty string and an empty array, respectively. The class should be declared above the main function like Course was.

Part 3.2: Define and export an addCourseToSchedule function

Since there are a lot of courses in a schedule, it would be nice to have a function we could call anytime we wanted to add a course to our schedule. It's like clicking the Enroll button on Connect Carolina -- but faster. This function should have two parameters -- a Course and a Schedule to which it should be added (Course first, Schedule second). The function should add the course to the end of the Schedule's courses array. After adding the course, return the updated Schedule.

Part 3.3: Define and export a scheduleToString function

This function should loop through a Schedule's courses array (this Schedule should be the single parameter for this function) and use the courseToString function from Walk in order to create one large string representation of an entire Schedule. Of course, we don't want a paragraph of course after course. The schedule would look better if each course was on it's own line, so concatenate a newline character ("\n") after you add each course (from courses) to the composite string.

Before the string of courses, pre-pend the owner of the Schedule's name (make it so that would be the first line when printed).

For example, if the COMP 101 object from walk and another Course object with the properties "COMP", 110, [QR], "An awesome class!" were stored in a Schedule owned by Jeffrey, the scheduleToString function would return "Jeffrey's Schedule:\nCOMP 101: A cool class\nCOMP 110: An awesome class!\n"

Part 3.4: Testing your two new functions

Inside main, you can now test your functions. Create a new Schedule object named mySchedule and set the owner property to be your name. Use the Course constructor to create some Course objects. Now, you should add courses to your Schedule object using addCourseToSchedule. To do this, assign mySchedule (or whatever you named your schedule object) the result of calling addCourseToSchedule passing in a course you created and mySchedule. Repeat this for each course you created. Finally, you can should print your Schedule object using scheduleToString.

The output to your webpage should look something like this:

Jeffrey's Schedule:
COMP 101: A cool class
COMP 110: An awesome class!

Part 3.5: Publish your app.

With your program running in your web browser, find the green "Publish App" button. If you are not still logged into introcs.com, you will be prompted to log in, and then your app will be bundled and published to the web!

Part 3.6: Submit for grading

Once the grader is available, to submit for grading, first publish your project as per Part 3.5. Then, go to My101 in the top-right right corner of this page and select "Submit" next to the assignment. From here you should see a button that allows you to submit for grading. Your work will be graded through an automated process. If you receive points off, please select the "Report" link to see which tests did not pass. You can resubmit as many times as you'd like without penalty up until the deadline. We want you to keep working toward full credit on problem sets!

Now you are ready to pull everything together in Sprint!