DESC 391 Assignments Fall 2009 Print E-mail
Written by Chitu Okoli and Bilal Abdul Kader   
Friday, 19 September 2008 11:35
Article Index
DESC 391 Assignments Fall 2009
1: Interest and coins
2: Circles and dice
3: Student scores, and reservations
4: GUI programming
All Pages

DESC 391 Assignments

This page lists the assignments for DESC 391, Fall 2009. Assignments will be graded according to the following guidelines (thanks to Bilal Abdul Kader for delineating these criteria):

  • Correct execution of the program (75%)
    • Compilation without errors
    • No logical errors at run time
    • Implementation of all required instructions
    • User-friendly prompts (if any)
    • Coherent display (if any)
  • Elegance of the code (25%)
    • Correct usage of Java structure and logical flow
    • Neat implementation of class code
    • Usage of correct naming conventions for classes, variables, and functions
    • Usage of meaningful class, variable and function names
    • Consistent indentation and alignment of code blocks
    • Usage of comments within the code
    • Adding a description section for the class at the beginning of the file (a few lines to describe the class, its methods, attributes, and general idea about its functionality)
    • Description of dependencies and inheritance (if any)
  • Innovation above and beyond the requirements (bonus points)
    • Adding extra graphics or features
    • Smart usage of advanced Java structures
    • Reusing previous code (if possible)
    • Impressive logic in implementing complicated functions

 

 


Assignment 1: Interest and coins

Due: 11:59 pm on Wednesday September 23

The purpose of this assignment is for you to begin writing simple programs in Java. There are two exercises.

1. Calculate interest (2.5%)

Console


Welcome to the Interest Calculator

Enter loan amount:   520000
Enter interest rate: .05375

Loan amount:         $520,000.00
Interest rate:       5.375%
Interest:            $27,950.00

Continue? (y/n): y

Enter loan amount:   4944.5
Enter interest rate: .01

Loan amount:         $4,944.50
Interest rate:       1%
Interest:            $49.45

Continue? (y/n): n

Press any key to continue . . .

Operation

  • The application prompts the user to enter a loan amount and an interest rate.
  • The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user.
  • The application prompts the user to continue.

Specifications

  • Create the program in one class named InterestCalculator.
  • This application should round the interest that’s calculated to two decimal places, rounding up if the third decimal place is five or greater. Because of Java rounding error, it is acceptable for your results to be off by one cent ($0.01). However, if you use BigDecimal arithmetic to fix the rounding error, you will get 0.5 point bonus. (Caution: Make sure everything else is working first before going for the bonus.)
  • The value for the formatted interest rate should allow for up to 3 decimal places.
  • Assume that the user will enter valid double values for the loan amount and interest rate.
  • The application should continue only if the user enters “y” or “Y” to continue.

2: Calculate coins for change (2.5%)

Console

Welcome to the Change Calculator

Enter number of cents (0-99): 99

Quarters: 3
Dimes:    2
Nickels:  0
Pennies:  4

Continue? (y/n): y

Enter number of cents (0-99): 55

Quarters: 2
Dimes:    0
Nickels:  1
Pennies:  0

Continue? (y/n): n

Press any key to continue . . .

Operation

  • Create the program in one class named ChangeCalculator.
  • The application prompts the user to enter a number of cents from 0 to 99.
  • The application displays the minimum number of quarters, dimes, nickels, and pennies that represent the coins that make up the specified number of cents.
  • The application prompts the user to continue.

Specifications

  • Assume that the user will enter a valid integer value for the number of cents.
  • The application should continue only if the user enters “y” or “Y” to continue.

Submission

To submit the assignment, do the following:

  • Package your completed assignment as one single .jar file with two classes, InterestCalculator and ChangeCalculator: In BlueJ, Project -> Create Jar File... -> Continue (Main class: none; select Include source and BlueJ project files). Name the file:
    "YourFirstName YourLastName Assignment 1.jar".
  • E-mail the jar file to This e-mail address is being protected from spambots. You need JavaScript enabled to view it no later than 11:59 pm on Wednesday September 23.
  • This assignment counts as 5% of your class grade.

 

 

 


Assignment 2: Circles and dice

Due: 11:59 pm on Friday October 9

The purpose of this assignment is for you to begin writing simple object-oriented programs in Java. There are two exercises.

1. Calculate a circle’s circumference and area (3.5%)

Console

Welcome to the Circle Tester
 
Enter radius:  3
Circumference: 18.85
Area:          28.27
 
Continue? (y/n): y
 
Enter radius:  6
Circumference: 37.70
Area:          113.10
 
Continue? (y/n): n
 
Goodbye. You created 2 Circle object(s).

Operation

  • The application prompts the user to enter the radius of a circle.
  • If the user enters invalid data, the application displays an appropriate error message and prompts the user again until the user enters valid data.
  • When the user enters a valid radius, the application calculates and displays the circumference and area of the circle to the nearest 2 decimal places.
  • The application prompts the user to continue.
  • When the user chooses not to continue, the application displays a goodbye message that indicates the number of Circle objects that were created by the application.

Specifications

  • Create a class named Circle to store the data about this circle. This class should contain these constructors and methods:
    public Circle(double radius)
    public double getCircumference()
    public String getFormattedCircumference()
    public double getArea()
    public String getFormattedArea()
    private String formatNumber(double x)
    public static int getObjectCount()
  • Create any fields (instance variables) necessary to implement your solution. However, these must all be declared private.
  • The formulas for calculating circumference and area are:
    circumference = 2 * pi * radius
    area = pi * radius
    2
  • For the value of pi, use the PI constant of the java.lang.Math class.
  • Create a class named CircleApp that gets the user input, creates a Circle object, and displays the circumference and area.
  • Create a Validator class like the one from chapter 6 to validate the input data in this application. Use a comment at the top of the class file to clear cite that you got the code from chapter 6, with the full textbook title and author name. (Note: This specification is not optional—that is, you must use code from chapter 6, and you must cite it properly. This is to demonstrate that you know how to properly cite borrowed code.)

2. Roll the dice (4.5%)

Console

Welcome to the Monopoly Roller application

Roll the dice? (y/n): y

Roll 1:
2
5
Total: 7

Roll again? (y/n): y

Roll 2:
3
3
Total: 6

Double! Roll again!

Roll 3:
1
6
Total: 7

Roll again? (y/n): y

Roll 4:
2
2
Total: 4

Double! Roll again!

Roll 5:
3
3
Total: 6

Double! Roll again!

Roll 6:
4
4
Total: 8

Go to jail!

Roll again? (y/n): n

Operation

  • If the user chooses to roll the dice, the application rolls two six-sided dice, displays the results of each, and asks if the user wants to roll again, following MonopolyTM  rules for rolling dice.

Specifications

  • Create a class named Die to store the data about each die. This class should contain these constructors and methods:
    public Die()              // default to a six-sided die
    public Die(int sides)     // allow a variable number of sides
    public void roll()        // Use Math.random() to generate a number from 1 to 6
    public int getValue()
  • Create any fields (instance variables) necessary to implement your solution. However, these must all be declared private.
  • Create a class named PairOfDice to store two dice. This class should contain two instance variables of the Die type, an instance variable that holds the sum of the two dice, and these constructors and methods:
    public PairOfDice()           // default to six-sided dice
    public PairOfDice(int sides)  // allow a variable number of sides
    public void roll()
    public int getValue1()        // get value of die1
    public int getValue2()        // get value of die2
    public int getSum()           // get the sum of both dice
  • Create a class named DiceRollerApp that uses the PairOfDice class to roll the dice. This class should display the value of each die, and the sum of the two dies. For this application, assume that two six-sided dice are used.
  • If a double is rolled (that is, both dies roll the same number), then the system should automatically roll again without prompting the user. If the resulting roll is also a double, then the system should automatically roll again. However, if the third consecutive roll is a double, the system should print, “Go to jail!” and then continue as normal (that is, prompt the user whether to roll again or not).
  • Accept only “y” or “n” (lower or upper case). (If you like, you could also accept “yes” or “no”.) For any other input, display an appropriate error message and repeat the prompt.

Submission

To submit the assignment, do the following:

  • Package your completed assignment as one zip file with two executable jar files:
    • The first jar file named "YourFirstName YourLastName Assignment 2 CircleApp.jar" should have three classes: CircleApp, Circle, Validator. Package it in BlueJ using Project -> Create Jar File... -> Continue (Main class: CircleApp; select Include source and BlueJ project files).
    • The second jar file named "YourFirstName YourLastName Assignment 2 DiceRollerApp.jar" should also have three classes: Die, PairOfDice, DiceRollerApp. Package it in BlueJ using Project -> Create Jar File... -> Continue (Main class: DiceRollerApp; select Include source and BlueJ project files).
    • Zip the two jar files into one file named "YourFirstName YourLastName Assignment 2.zip".
  • E-mail the zip file to This e-mail address is being protected from spambots. You need JavaScript enabled to view it no later than 11:59 pm on Friday October 9.
  • This assignment counts as 8% of your class grade.

 

 


Assignment 3: Student scores, and reservations

Due: 11:59 pm on Wednesday November 18

The purpose of this assignment is for you to work with arrays, interfaces, and dates in Java. There are two exercises.

1. Display a sorted list of student scores (5%)

Console

Welcome to the Student Scores Application.

 

Enter number of students to enter: 4

 

Student 1 last name: Rainer

Student 1 first name: Kelly

Student 1 score: 95

 

Student 2 last name: Turban

Student 2 first name: Efraim

Student 2 score: 92

 

Student 3 last name: Schmidt

Student 3 first name: Doug

Student 3 score: 82

 

Student 4 last name: Sanchez

Student 4 first name: Cristal

Student 4 score: 93

 

Rainer, Kelly: 95

Sanchez, Cristal: 93

Schmidt, Doug: 82

Turban, Efraim: 92


Operation

·         This application accepts the last name, first name, and score for one or more students and stores the results in an array. Then, it prints the students and their scores in alphabetical order by last name.

Specifications

·         Create a class named Student that stores the last name, first name, and score for each student. This class should implement the Comparable interface so the students can be sorted by name. If two students have the same last name, the first name should be used to determine the final sort order. Assume that no two students will have the same first and last name.

·         Create a StudentScoresApp class to run the program (that is, in its main method). The program should use an array to store the Student objects. Then, it should sort the array prior to printing the student list.

·         Validate the input so the user can enter only a positive integer for the number of students, the last or first name can’t be an empty string, and the score is an integer from 0 to 100.

2. Calculate reservation totals (5%)

Console

 

Welcome to the Reservation Calculator.

 

Enter the arrival month (1-12): 5

Enter the arrival day (1-31): 16

Enter the arrival year: 2005

 

Enter the departure month (1-12): 5

Enter the departure day (1-31): 18

Enter the departure year: 2005

 

Arrival Date: Monday, May 16, 2005

Departure Date: Wednesday, May 18, 2005

Price: $115.00 per night

Total price: $230.00 for 2 nights

 

Another reservation? (y/n): n


 

Operation

·         This application calculates the charges for a stay at a hotel based on the arrival and departure dates.

·         The application begins by prompting the user for the month, day, and year of the arrival and the departure.

·         Next, the application displays the arrival date, the departure date, the room rate, the total price, and the number of nights.

Specifications

·         Create a class named Reservation that defines a reservation. This class should contain instance variables for the arrival date and departure date. It should also contain a constant initialized to the nightly rate of $115.00.

·         The Reservation class should contain a constructor that accepts the arrival and departure dates as parameters of type Date, as well as methods that return the number of nights for the stay (calculated by subtracting the arrival date from the departure date) and the total price (calculated by multiplying the number of nights for the stay by the nightly room rate). This class should also override the toString method to return a string like this:

Arrival Date: Monday, May 16, 2005
Departure Date: Wednesday, May 18, 2005
Price: $115.00 per night
Total price: $230.00 for 2 nights

·         The main method for the application class (called ReservationCalculatorApp) should contain a loop that asks the user for the arrival and departure date information, creates a Reservation object, and displays the string returned by the toString method.

·         Assume valid data is entered.

Submission

To submit the assignment, do the following:

  • Package your completed assignment as one zip file with two executable jar files:
    • The first jar file named "YourFirstName YourLastName Assignment 3 StudentScoresApp.jar" should have two classes: StudentScoresApp and Student. Package it in BlueJ using Project -> Create Jar File... -> Continue (Main class: StudentScoresApp; select Include source and BlueJ project files).
    • The second jar file named "YourFirstName YourLastName Assignment 3 ReservationCalculatorApp.jar" should also have two classes: Reservation and ReservationCalculatorApp. Package it in BlueJ using Project -> Create Jar File... -> Continue (Main class: ReservationCalculatorApp; select Include source and BlueJ project files).
    • Zip the two jar files into one file named "YourFirstName YourLastName Assignment 3.zip".
  • E-mail the zip file to This e-mail address is being protected from spambots. You need JavaScript enabled to view it no later than 11:59 pm on Wednesday November 18.
  • This assignment counts as 10% of your class grade.

 

 


Assignment 4: GUI programming

Due: Early submission is 11:59 pm on Monday December 7 (if you submit on this date, you will receive your results before the final exam)
Late submission is 11:59 pm on Friday December 11 (late penalties will apply only after this date; however, you will not receive your result before the final exam)

The purpose of this assignment is for you to begin developping GUI applications in Java. You must use a text editor to do this assignment; you must hand-code everything. You are NOT permitted to use a GUI generator that automatically creates windows for you. There are two exercises.

1. Accumulate test scores (4%)

Test Scores

Operation

·         The user enters test scores one at a time and then clicks the Enter Score button.

·         For each entered score, the application adds one to the number of scores, calculates the average score, and determines what the best score is so far. Then, it displays the number of scores, average score, and best score in the three disabled text fields. Note that although the screen does not show the total score, your application will need to store the running total in order to calculate the average properly.

·         The user can click the Clear button to reset everything to zero.

·         When the user closes the frame or clicks the Close button, the application exits.

Specifications

·         The average score is the sum of all scores divided by the number of scores.

·         Assume valid data is entered. However, you may validate the data for extra credit (see below).

·         If you have trouble getting the labels and text fields to line up properly, try adjusting the frame size. When you use the FlowLayout manager, the width of the frame affects how components you add to the frame are lined up.

Extra credit

·         Make sure that you have the application fully working before you try for extra credit!

·         For 0.5% extra credit, validate the test score to permit only a valid double value from 0 to 100. You may use the validation classes from chapter 17 (remember to cite your sources properly).

2. Enter a team lineup (8%)

Lineup

Console output

Rage 12U (home team)

 

H. Perkins, Center Field

C. Cousins, Pitcher

J. Johnson, Catcher

B. Lowe, First Base

A. Licouris, Left Field

N. Shrey, Short Stop

S. Palmore, Third Base

C. Giess, Second Base

A. Nieto, Right Field

 

Operation

·         This application lets the user enter the batting lineup for a baseball or softball team.

·         The user can enter a team name and use the radio buttons to select whether the team is the home team or the visiting team.

·         For each player, the user enters the player’s name in the text field and selects the player’s position from the combo box.

·         When the user clicks OK, the application displays the team roster on the console as shown in the console output. The order is the same order as entered by the user.

Specifications

·         The team positions in the combo boxes should offer the following choices:

Choose a selection
Pitcher
Catcher
First base
Second base
Third base
Short stop
Left field
Center field
Right field

·         Don’t worry about validating the user’s input--even a blank field is OK. However, you may validate the data for extra credit (see below).

·         You may use the BorderLayout and/or the FlowLayout to control the positioning of the labels, text fields, combo boxes, and buttons. However, for extra credit, you may use the GridBagLayout (see below).

·         Hint: Consider simplifying the solution by creating a private method that adds a label, text field, and combo box to the panel. Another option is to declare an array of text fields and an array of combo boxes rather than declaring separate controls for each player.

Extra credit

·         Make sure that you have the application fully working before you try for extra credit!

·         For 1% extra credit, use the Grid Bag layout to control the positioning of the labels, text fields, combo boxes, and buttons. However, you probably need to decide from the beginning whether to use the BorderLayout and/or FlowLayout, or whether to use the GridBagLayout. While you would get extra credit for GridBagLayout, it is harder to use, and more risky. If you're not sure you're up to the challenge, then complete the application using the simplyer layout options, and then try one of the other extra credit opportunities.

·         For 0.5% extra credit, validate the combo box selections so that the user can’t select the same position for two or more players. If the user attempts to set a combo box to a selection that’s already been assigned to a player, the combo box should immediately revert to “Choose a position.” Refer to chapter 17 for validation techniques for GUI programming.

·         For 1% extra credit, instead of printing results to a console, print results to a new frame which displays the results in a text area, and that has only one button "Close" to close the frame. However, for this output frame, the close button only closes that frame; it does not exit the entire application.

 

Submission

To submit the assignment, do the following:

  • Package your completed assignment as one zip file with two executable jar files:
    • The first jar file named "YourFirstName YourLastName Assignment 4 TestScoresApp.jar". Package it in BlueJ using Project -> Create Jar File... -> Continue (Main class: TestScoresApp; select Include source and BlueJ project files).
    • The second jar file named "YourFirstName YourLastName Assignment 4 LineupApp.jar". Package it in BlueJ using Project -> Create Jar File... -> Continue (Main class: LineupApp; select Include source and BlueJ project files).
    • Zip the two jar files into one file named "YourFirstName YourLastName Assignment 4.zip".
  • Submission deadline: E-mail the zip file to This e-mail address is being protected from spambots. You need JavaScript enabled to view it no later than 11:59 pm on Monday December 7. As long as you submit by this early deadline, you will receive your results before the final exam). However, you may submit later by 11:59 pm on Friday December 11 (late penalties will apply only after this date; however, you will not receive your result before the final exam).
  • This assignment counts as 12% of your class grade.

 

Last Updated on Tuesday, 08 December 2009 11:16