CSCI 125 Fall 2025
Software Design and Implementation
Charles Cusack
Computer Science
Hope College
Main
Schedule
Grading
Gradebook
Homework

Policies
Advice
College
    Policies

Notes
Programs
Tutorials

CSCI 125
CSCI 255
Others

Admin

All Homework

Homework 1

Ticket Machine

Do exercises 2.37, 2.41, 2.44, 2.45. If the exercise asks you to answer a question, put your answer in a comment in the TicketMachine class.

When you have completed this assignment, select "Create Jar File ..." from the Project menu in BlueJ. Check "include source" and "include Bluej project files". Save the file with the name bassett-ticketmachine.jar (except use your name instead of bassett). Then upload the "jar" file into Moodle no less than 10 minutes before the start of class.

Expectations for CSCI 125 projects turned in:

  • The code compiles and runs
  • CSCI 125 naming conventions are used
  • Each class and method has a javadoc /** comment explaining its purpose
  • Each field has a // comment explaining its purpose

Homework 2

Book Exercises

Do Exercises 2.83-2.92 (2.83-2.91 in the 5th edition).
  • Read the directions carefully and make sure you do each part.
  • Use proper indentation.
  • Test all of your methods thoroughly.
  • Write javadoc comments for each method.
  • Note: In exercise 2.86, "immutable" means "cannot be changed by any method you've created up to this point".

When you have completed this assignment, select "Create Jar File ..." from the Project menu in BlueJ. Check "include source" and "include Bluej project files". Save the file with the name dejongh-book.jar (except use your name instead of dejongh). Then upload the "jar" file into Moodle no less than 10 minutes before the start of class.

Homework 3

Clock Exercises

Finish parts 1 through 6 of the Clock Exercises. (Focus on getting parts 1-4 completely correct, make a good effort for 5, and see how much of 6 you are able to tackle.)

When you have completed this assignment, select "Create Jar File ..." from the Project menu in BlueJ. Check "include source" and "include Bluej project files". Save the file with the name bassett-clock.jar (except use your name instead of bassett). Then upload the "jar" file into Moodle no less than 10 minutes before the start of class.

Homework 4

SmallBank

READ THESE DIRECTIONS CAREFULLY

  1. Create a class named BankAccount. This class should include two instance variables, one that records the balance and another that records the name of the account holder. You should provide code for each of the following:
    • Constructor that takes a name as its only input parameter and sets the initial balance to zero.
    • Constructor that takes a name and an initial balance as its two input parameters.
    • An accessor method that returns the current balance of the account.
    • An accessor method that returns the current name of the account.
    • A mutator method that sets the name of the account to the new name in its input parameter.
    • A mutator method that makes a deposit to the account by adding its input parameter to the balance.
    • A method that makes a withdrawal from the account by subtracting its input parameter from the balance.
    • Write your class so that it prohibits negative values for deposit and withdrawal and so that it prohibits a withdrawal of an amount larger than the balance.
    • Test your class thoroughly.
  2. Create a second class named SmallBank. This class should have two instance variables named account1 and account2, each of type BankAccount. The reason this is a small bank is because it can only have two bank accounts - we'll see how to create larger collections in chapter 4. You should provide code for each of the following:
    • SmallBank Constructor that takes an account name and an initial balance as its two input parameters. Since we don't want to have a bank without having an account, this constructor should create a BankAccount object using the account name and initial balance parameters, and store it in the account1 instance variable. It should leave the account2 instance variable uninitialized (i.e., null).
    • A method in SmallBank named addSecondAccount that takes an account name and an initial balance as its two input parameters. This method should create a BankAccount object using the account name and initial balance parameters, and store it in the account2 instance variable.
    • A method in SmallBank named printBankDetails that prints out the details of the stored BankAccounts. This method should work in the case that there is only one BankAccount as well as in the case that there are two BankAccounts. You can check whether there is a value in the account2 instance variable as follows:
      if (account2 != null) // this checks whether account2 has a BankAccount object assigned to it
  3. Write a class named SmallBankTester that has a method named testSmallBank. This method should create a SmallBank object, invoke the printBankDetails method a first time to print the first account's details, invoke the addSecondAccount method to add the second account, and invoke the printBankDetails method a second time to print both account details. This method doesn't need to return anything, but you should look at the Terminal window to make sure the account details printed properly both times.

When you have completed this assignment, select "Create Jar File ..." from the File menu in BlueJ. Check "include source" and "include Bluej project files". Save the file with the name bassett-smallbank.jar (except use your name instead of bassett). Then upload the "jar" file into Moodle no less than ten minutes before the start of class.

Homework 5

Practice with ArrayList

In the music-organizer-v5 project from Chapter 4:
  • Add a playingTime field of type int to the Track class.
    • Update the setDetails method to include the playing time. This will introduce compiler errors until you do the next item.
    • Set playing time to a default value of 99 in the existing constructors.
    • Add a third constructor (with parameters including artist, title, and filename) that can set the playingTime to a different value.
    • Add an accessor method for playing time.
    • Update the getDetails method to include the playingTime.
  • Add a method for the MusicOrganizer class named getTotalPlayingTime() with an int return type. It should add up and return all the values of playingTime for all the tracks stored in its ArrayList.
  • Add a method for the MusicOrganizer class named get99MinuteTracks() that returns an ArrayList with all the tracks that have a 99 minute playing time.
When you have completed this assignment, select "Create Jar File ..." from the Project menu in BlueJ. Check "include source" and "include Bluej project files". Save the file with the name bassett-ch4exercises.jar (except use your name instead of bassett). Then upload the "jar" file into Moodle no less than 10 minutes before the start of class.

Homework 6

Exercises 6.45 and 6.46

Do these exercises by modifying the SupportSystem and Responder classes in the tech-support-complete project.

For exercise 6.45, examples of synonyms are "crash", "crashes", "crashed". Note that you should not add more entries to the responseMap. Instead, create a new HashMap (call it synonymMap) that maps synonyms to a unique key in the responseMap (for example, map "crash", "crashes" and "crashed" to "crash" in the synonymMap).

For exercise 6.46, someone might type in "my windows PC crashed." The SupportSystem class should print out responses for both "windows" and "crashed". You should not have the Responder class do any printing. Also, be sure to print each response out only once (i.e., "crash crashed" should not print the same response twice).

When you have completed this assignment, select "Create Jar File ..." from the File menu in BlueJ. Check "include source" and "include Bluej project files". Save the file with the name bassett-tech-support.jar (except use your name instead of bassett). Then upload the "jar" file into Moodle.

Homework 7

Weblog Analyzer

  1. Part 1
    In Section 7.4, finish exercises 7.12 through 7.18.
  2. Part 2
    • Then read ex. 7.19 and do the following:
    • Add a field to the LogAnalyzer class named dayCounts. It should be an array of type int, and have enough slots for each day of the month. Modify the analyzeHourlyData method so that it also tracks how many accesses were logged each day of the month. (You don't need to add a separate method named analyzeDailyData, just track both the hourly counts and the daily counts in analyzeHourlyData).
    • Then write methods printDailyCounts, busiestDay and quietestDay similar to printHourlyCounts, busiestHour and quietestHour.
  3. Part 3
    Finally, create a class named LogDemo that creates a LogAnalyzer, and invokes the busiestTwoHours, printDailyCounts, busiestDay, and quietestDay methods and prints out the return values for the busiest two hour period, busiest day and quietest day.
  4. Part 4
    Make sure to Javadoc every class and method, regardless of whether or not you made any changes. This includes putting your name and the date in each class you created/modified, having a brief description of what each class does, having a brief description of what every method (including constructors) does, and @param and @return tags everywhere they are appropriate.

When you have completed this assignment, select "Create Jar File ..." from the File menu in BlueJ. Check "include source" and "include Bluej project files". Save the file with the name bassett-loganalyzer.jar (except use your name instead of bassett). Then upload the "jar" file into Moodle no less than 10 minutes before the start of class.