ICS 211 Homework 2

Reading and Understanding Programs

0. Goals and Overview

The goals of this assignment are to learn to read and understand and modify existing Java programs. You will also get practice working with command-line arguments, loops, and Java Strings.

1. Mystery Program

Carefully study the Mystery Program 1 and do your best to understand what the program is designed to do.

After you have tried to understand the program, run it to see if it indeed does what you think it does. If not, go back and study the program again.

Modify the program to accept more than one command-line argument, and to do for each argument what MysteryProgram1 does to its single argument.

Deliverables

  1. (10%) Provide a description of what the program does. The description must be concise, meaning no more than 100 words. Each of these words must be your own, and to get credit, the text must clearly describe what the program does. Turn in this summary.
  2. (20%) Turn in your modified MysteryProgram1.java.

2. ChangeDue

Carefully study the ChangeDue Program and do your best to understand what the program is designed to do.

Run the program, and see if your understanding is correct. If not, go back to the program. Try to understand every part of the code.

The result is currently printed by the program using System.out.print and System.out.println. Modify the program to print the result in a window such as used for obtaining the data. To do so, you should build the result into a string variable, then display your string variable using JOptionPane.showMessageDialog(null, yourStringVariable).

To get ChangeDue to compile, users of Eclipse may need to add the line

    requires java.desktop;
inside their module declaration under module-info.java (information from this video).

Deliverables

  1. (30%) Provide a clear description of what each method in the program does, so one description each for main, requestAmount, printDollar, and printChange. Again the length of each of these descriptions is to be no more than 100 words, all of them your own words. Turn in these summaries.
  2. (40%) Turn in your modified ChangeDue.java.

Turning in the Assignment

Once you are done, export your code and use Laulima to turn in your files to the TA. Once you log into Laulima and select the ICS 211 site, on the left-hand side will be an assignments tab.