Create a new project in BlueJ
· Review sections 3.1 through 3.11 of your textbook. Study problems 3.31 and 3.32 of the book. Modify the clock object described in the book so that it displays a 12-hour time with am/pm. For this question keep the internals of the clock as described in the book and only change the display routine updateDisplay.
Create a new project in BlueJ by clicking on the menu option Project > New project. This will create a folder with the project name (see below). All BlueJ project-related files for this project will be stored in this folder. Create new classes by clicking on the [New Class] button. All Java class files that you create (.java files) will be stored in the BlueJ project folder. The project folder will contain other files as well. After completing and testing your assignment, zip the entire BlueJ folder and submit it. Since your Instructor will need all files in the project folder, make sure you zip the entire folder. For this assignment the names of the BlueJ project, Java class files, and the zip file you submit are given below:
- BlueJ project: clock-display-updatedisplay
- Java files: ClockDisplay.java, NumberDisplay.java
- Submit the full zipped BlueJ project folder: clock-display-updatedisplay.zip
· | ||
Week 3 HA - clock-display-12hr
This exercise is a follow up to the clock-display-updatedisplay project (also given for this week). For this question our goal once again is to create a clock that displays time as a 12-hour notation with am/pm. This time we will modify the internals of the clock object. As given in the book, we have two NumberDisplay objects: (i) for the minutes which run from 0 to 59 and (ii) for the hours which run from 0 to 23. Modify the hours display so that it runs from 1 to 12. Add an additional field that keeps track of whether the time is am or pm.
Create a new project in BlueJ by clicking on the menu option Project > New project. This will create a folder with the project name (see below). All BlueJ project-related files for this project will be stored in this folder. Create new classes by clicking on the [New Class] button. All Java class files that you create (.java files) will be stored in the BlueJ project folder. The project folder will contain other files as well. After completing and testing your assignment, zip the entire BlueJ folder and submit it. Since your Instructor will need all files in the project folder, make sure you zip the entire folder. For this assignment the names of the BlueJ project, Java class files, and the zip file you submit are given below:
- BlueJ project: clock-display-12hr
- Java files: ClockDisplay.java, NumberDisplay.java
- Submit the full zipped BlueJ project folder: clock-display-12hr.zip
· | ||
Week 3 HA - cash_register
In this problem you work with a class that models the behaviour of a simple cash register. You do not have to change the code that is provided to you. The user can enter the amount due and the amount given by the customer. The cash register will then print the change due. The change due should also be expressed as the number of dollars, quarters, dimes, nickels and pennies due. 5 pennies = 1 nickel; 10 pennies = 1 dime; 25 pennies = 1 quarter; 100 pennies = 1 dollar. Download the zipped BlueJ project cash_register.zip, unzip and execute it. Below is a snapshot of a sample run:
The above code was produced by executing:
CashRegister cr = new CashRegister();
cr.setAmountDue(5.67);
cr.setAmountGiven(12.34);
cr.makeChange();
As part of this assignment you will use the debugger and single-step execution to trace through the program's execution. By setting a breakpoint at the appropriate line and single stepping through your code, fill out the table below.
When the amount given is 12.34 and the amount due is 5.67 the value of the coin denomination due and the remaining change amount have been highlighted in blue in the tables below. You need to fill out the blank entries highlighted in green in the tables below. Study the main method and set your own values for AmountDue and AmountGiven. To set your own values for AmountDue and AmountGiven, create a new CashRegister object on the object bench in BlueJ, right-click on the newly created object and invoke the setAmountDue and setAmountGiven methods. Then, with the debugger, single-step through the program line by line tracing its execution. For each step note the amount remaining to be given as stored in the variable change and write it in the table.
Amt Due |
5.67 |
Amt Due |
|
Amt Given |
12.34 |
Amt Given |
|
Change Due |
6.67 |
Change |
|
Coin denomination |
Value of the coin denomination (specified in the first column) due after it changes from a value of 0 (zero). |
Value of the variable “change” after the coin denomination (specified in the first column) is calculated. |
Value of the coin denomination (specified in the first column) after it changes from a value of 0 (zero). |
Value of the variable “change” after the coin denomination (specified in the first column) is calculated. |
Dollars |
6 |
67 |
|
|
Quarters |
2 |
17 |
|
|
Dimes |
1 |
7 |
|
|
Nickels |
1 |
2 |
|
|
Pennies |
2 |
2 |
|
|
Note: Your submission must include the two tables given above after you fill in the empty cells.
· | ||
Week 3 HA - voting_machine
In this exercise you will create a simple VotingMachine. In the United States, when a candidate runs for office, the person is often identified as a Democrat, Republican, or Independent. Write a Java class (VotingMachine.java) which allows one to vote by party affiliation and will also allow us to query the number of votes for each party and who won the election. The behavior is given below:
VotingMachine vm = new VotingMachine();
vm.voteDemocrat();
vm.voteDemocrat();
vm.voteRepublican();
vm.voteIndependent();
vm.countDemocrat(); // returns 2
vm.countRepublican(); // returns 1
vm.countIndependent(); // returns 1
vm.whoWon(); // returns “Democrat”
For simplicity, you may assume that there will be no ties in this election.
Create a new project in BlueJ by clicking on the menu option Project > New project. This will create a folder with the project name (see below). All BlueJ project-related files for this project will be stored in this folder. Create new classes by clicking on the [New Class] button. All Java class files that you create (.java files) will be stored in the BlueJ project folder. The project folder will contain other files as well. After completing and testing your assignment, zip the entire BlueJ folder and submit it. Since your Instructor will need all files in the project folder, make sure you zip the entire folder. For this assignment the names of the BlueJ project, Java class files, and the zip file you submit are given below:
- BlueJ project: voting_machine
- Java files: VotingMachine.java
- Submit the full zipped BlueJ project folder: voting_machine.zip
12 years ago
Purchase the answer to view it

- cash_register_report.xlsx
- solutions.zip