CS230 Assignment 1

Assignment 1

 

Goals:

Practice with:

  • working with BlueJ IDE to write, compile, run simple java programs
  • java primitive data types, expressions and operators
  • reading from the standard input (Scanner)
  • conditionals and while loops
  • defining and invoking helper methods
 

DUE: Thursday, Sep 12 at 11:59pm

  • How to turn in your assignment
  • Cover page for submission - submit the form.
  • For every task, include a file showing testing of your solution, e.g., the contents of the BlueJ Console demonstrating correct executions of your program on various sample data
  • Remember that for this and all assignments, you could use a 48 hour extension without asking for permission. However, if those two extra days are not sufficient for you to complete the assignment, you are required to contact the instructor and discuss a plan for completing the assignment before the assignment is due. We will work together to make sure that plan is a reasonable and effective so that it supports both your learning and your health.
 

Task 1: Making Change

Write an application, CorrectChange, that makes correct change for a specified amount of money. Your application should prompt the user for an amount of money (dollars and cents) and then print out the correct change using the fewest possible number of $20 bills, $10 bills, $5 bills, $1 bills, quarters, dimes, nickels, and pennies.

To give you a sense (sense/cents... get it?) of how your program should behave, see this screen capture:

Some important notes on this task:

  • Use the Scanner class to read in the user input from the keyboard, as one number. The nextDouble() method may be used to read in a decimal number. You do not need to handle the case when the user enters invalid input, e.g., a negative number, a word or other non-decimal number, a fractional amount of cents (0.15485).
  • The amount entered by the user will be a decimal number indicating dollars and cents. Your program will be simpler if you work strictly with cents, so convert the amount entered by the user into an integer number of cents, e.g., $5.47 is 547 cents.
  • Your application should include a method makeChangeWithOneDenomination(int total, String denominationName, int denomination) that satisfies this contract.

  • Your makeChangeWithOneDenomination() method has to use integer division (do not use loops in this program). (In Task 2 below, you will work on an alternative solution involving loops rather than integer division.)
 

Task 2: Making Change with a Loop

Write an application, CorrectChange_Loop, that behaves exactly as the one described in Task 1 above. However, to implement the makeChangeWithOneDenomination() method you have to use a loop (not an integer division)

 

Task 3: Area of a Triangle

Write an application, AreaTriangle, that prompts the user three times for the side lengths of a triangle. Based on the three triangle side lengths, the application prints out whether the triangle is isosceles or not and prints out the area of the triangle. Sample execution of the application is shown below:

Some important notes on this task:

  • Equilateral triangles are considered isosceles.
  • To compute the area of the triangle given the three side lengths, use Heron's Formula.
  • In addition to the main() method, you must use at least three other methods in your application.
  • If the user enters three side lengths that cannot possibly form a triangle (ex. 1,1,2), your program should print out an "Invalid input" error message, and stop execution.
  • You do not need to handle the case when the user enters other invalid input, e.g. a negative number(s) or words rather than numbers.