CSC 212 – Principles of Programming

Fall 2007

Homework Assignment 2


Purpose

The purpose of this assignment is to give you an opportunity to work through exercises based on the ideas discussed in class and in lab. You will be working with conditional statements, iteration, files, and other topics.


This assignment is to be completed individually. It is not acceptable to consult your classmates for specific answers or to share program code. It is also unacceptable to use program code from other sources (Internet, work submitted in previous semesters, etc.). Evidence of unauthorized collaboration or plagiarism will result in the student(s) receiving no credit for this assignment.


Turn-in Instructions

This assignment is due by Wednesday, October 17 at 5:00PM

You will turn in your assignment via the Angel system. The Angel web site is:


https://oswego.sln.suny.edu/


You will turn in three (or, optionally four) files. The files are the Java source code (.java file) for each of the programs. MAKE SURE YOUR PROGRAM COMPILES AND RUNS WITHOUT ERRORS! Java programs that do not compile will receive no credit.


As stated in the course syllabus, there is a 10% per day lateness penalty. Assignments more than five days late will not be accepted.


Programming Assignments

Write Java programs that perform the tasks described below. Turn in a separate Java file for each question.


  1. Use the ideas presented in Labs 4 and 5 to read and process information in a file about student grades. The file (called grades1.txt) contains the following entries for each student (each on its own line): Last Name, First Name, Quiz 1, Quiz 2, Quiz 3, Midterm, Final. The first and last name are strings, and the remainder of the values are integers. Here is an example:

      Olivier

      Laurence

      85

      89

      87

      79

      89

    A blank line (only a CR/LF) separates student entries.

    Compute and print the name, total average, and letter grade for each student. The total average is computed as follows:

      total = 0.4((quiz1 + quiz2 + quiz3)/3) + 0.3(midterm) + 0.3(final)

    Assign letter grades on a 90=A, 80=B, 70=C, etc. scale. The output line for the values above would be:

      Olivier Laurence 85.2 B

  2. Modify the program in Question 1 so that it can read a new file (called grades2.txt) with all values for a given student on a single line. An example is shown below:

      Olivier Laurence 85 89 87 79 89

    The values on an individual line are separated by spaces. There are no blank lines in the file. The output should be the same as that for Question 1.

  3. A neighborhood association organizes a car pool to bring the neighborhood children to school. Parents volunteer to drive some number of children up to the maximum that can be carried safely in their vehicle. Some parents own child car seats, and the association owns five car seats that it can distribute when needed. Eight children must be assigned to vehicles each week.

    Write a program that first accepts the names of the eight children and whether or not they require a car seat. Next, your program should accept the name of a driver, the number of children they can transport, and the number of car seats they own. Your program should then assign children to a driver and indicate the number of car seats needed from the association. An example session is shown below:

      Enter the child's and Y/N if a car seat is needed:

      Fred Y

      Ethel N

      Ricky N

      Lucy Y

      Ralph N

      Alice Y

      Norton Y

      Trixie N

      Enter the name of the driver, available seats, and number of car seats owned:

      Steve 3 2

      Assigned to Steve: Fred Lucy Ethel ; Car seats: 0

      Enter the name of the driver, available seats, and number of car seats owned:

      Dano 4 1

      Assigned to Dano: Alice Ricky Ralph Trixie ; Car seats: 0

      Enter the name of the driver, available seats, and number of car seats owned:

      Ben 2 0

      Assigned to Ben: Norton ; Car seats: 1

      All children have been assigned

      Car seats remaining: 4

  4. Optional Bonus Challenge (+15%)

    Modify the program is Question 3 to make it interactive. For example, the user can at any point type show children to see a list of all the children and the driver to whom they've been assigned (if any). Typing show drivers will show the list of children and number of car seats assigned to each driver. The add child and add driver commands will perform functions identical to the prompts in Question 3. Typing quit closes the program.