Program2.doc

advertisement

COP 2551

Summer 2004

Programming Assignment #2

Objectives:

To learn how to obtain input from the Linux command line.

To practice using the integer division and remainder operators.

To gain experience using Sytem.out.print() and System.out.println().

Assignment:

You are to write a program named Payday.java that takes as a command-line argument the number of dollars an employee has earned. For example, if the employee has earned $478, you would enter on the command line:

$ java Payday 478

The program would then calculate and display the number of twenty, ten, five and one dollar bills that the employee should receive in their pay envelope. For the above example, the program will display on the screen:

The employee will receive:

23 Twenties, 1 Tens, 1 Fives, 3 Ones.

Note that the output above does not correctly display singular and plural spellings for the bills. To do so would require use of if-else statements which we will not cover before the program is due. However, any student who is able to employ if-else statements to display output (as in the above example):

The employee will receive:

23 Twenties, 1 Ten, 1 Five, and 3 Ones. or given another example, if you type on the command line:

$ java Payday 405 the program will display

The employee will receive:

20 Twenties, 0 Tens, 1 Five, and 0 Ones. will receive 5 points extra credit .

Your program is to use the integer division operator ( / ) and the remainder operator , also called the modulus operator ( % ), in the calculations to arrive at the new time. No other math operations are to be used .

I have placed a demonstration file named ArgDemo.java

in the

/usr/public/cop2551/phigbee/Summer04/Program2 public subdirectory. This file demonstrates the input of a command-line argument.

Your programming style should adhere to the design guidelines in Appendix G of your text which is basically the style used in class demonstrations.

You are to turn in a shared directory that has your userid as its name (similar to your first programming assignment). In that subdirectory you are to have the source code for your program in a file named Payday.java

along with a simple text file named

Discussion.txt

. The text file is to include the following:

1.

Your name, date, class and section number.

2.

The name of your program (which is Payday.java) .

3.

A description of how you tested the program. The results you obtained.

Were the results always what you expected? Note that there is no penalty for having to modify your program, but there is a penalty if something doesn’t work correctly when I test it. However, this penalty is less if you identify problems with your program and output than it is if you assume your output is correct and I find it isn’t.

4.

A brief description of any problems you had creating the program, what you did to solve them, and any unresolved problems.

5.

A statement of whether or not you did an extra credit version of the program. The use of if … else statements will be required for the extra credit and we will not cover these statements until the class the program is due. I suggest you get the initial version done early – there won’t be much to add if you have that done.

The assignment code for this program is higbee.cop2551_43.p2.

The program is to be completed on osprey using one of osprey’s editors . It is due on Monday, June 1 st by start of class.

Paul Higbee

Download