Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added text file with answers to exercise questions #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions BlueJ.ExerciseQuestions.rtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{\rtf1\ansi\ansicpg1252\cocoartf2636
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0

\f0\fs24 \cf0 Exercise 2.2\
\
"Ticket price: 500 cents. Your total is 900."\
\
Exercise 2.3\
\
Yes the machine continues to take money, but never gives a ticket and it continues to add to the total. I do not receive a refund it continues to add on to the inserted money. It still adds to the total balance.\
\
Exercise 2.4\
\
I believe I have a good understanding\
\
Exercise 2.5\
\
No the code still doesn't look any different\
\
Exercise 2.6\
\
public class Student and public class LabClass\
\
Exercise 2.7\
\
Yes it does, the error message states the identifier is missing. Yes I notice the change in the class diagram.\
No, I think the error message should clarify what is missing from the section like state the identifier as public or private.\
\
Exercise 2.8 \
\
It is possible to leave out the word public and keep running, but public is important for any other class to use the codes.\
\
Exercise 2.9\
\
Constructors do not return anything and are usually named after the public class name. Like TicketMachine in this example. Fields are any variables set equal to something, like balance = 0 or total = total + balance. Methods are any codes that have a return or will change something in the code. For example public string printTicket() is a method it will affect the total in the code and increase the ticket number.\
\
Exercise 2.10\
\
Yes, the constructor does not return any value.\
\
Exercise 2.11\
Types are next to the private or public\
Private int count; int\
Private Student representative; Student\
Private Server host; Server\
\
Exercise 2.12\
Names are after the identifier\
Private boolean alive; alive\
Private Person tutor; tutor\
Private Game game; game\
\
Exercise 2.13\
\
Yes, the private must be before int. There are error message it is missing the identifier\
\
Exercise 2.14\
\
Yes, you always need a semicolon \
\
Exercise 2.15\
\
Private int status}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ Work through all these exercises. You edit this file with your answers for these
* Use `getBalance` to check that the machine has a record of the amount inserted.
* You can insert several separate amounts of money into the machine, just like you might insert multiple coins or notes into a real machine. Try inserting the exact amount required for a ticket. As this is a simple machine, a ticket will not be issued automatically, so once you have inserted enough money, call the `printTicket` method. A facsimile ticket should be printed in the BlueJ terminal window.




### Exercise 2.2
* What value is returned if you check the machine’s balance after it has printed a ticket?
* What value is returned if you check the machine’s balance after it has printed a ticket? A higher value

### Exercise 2.3
* Experiment with inserting different amounts of money before printing tickets.
Expand Down
37 changes: 35 additions & 2 deletions TicketMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author David J. Barnes and Michael Kolling
* @version 2008.03.30
*/
public class TicketMachine
class TicketMachine
{
// The price of a ticket from this machine.
private Integer price;
Expand All @@ -19,12 +19,20 @@ public class TicketMachine
private Integer total;
// The number of tickets printed.
private Integer ticketNumber;

private int status;

private int score;


/**
* Create a machine that issues tickets of the given price.
* Note that the price must be greater than zero, and there
* are no checks to ensure this.
*/



public TicketMachine(Integer ticketCost)
{
price = ticketCost;
Expand Down Expand Up @@ -95,4 +103,29 @@ public String printTicket()

return "Ticket price: " + price + " cents. " + "Your total is " + total + ".";
}
}

public void setPrice(int ticketCost) {
price = ticketCost;

}


public void increase(int points){
points = score;

}

public void discount(int amount) {

price = price - amount;
}

public void prompt() {
System.out.println("Please insert the correct amount of money");
}

public void showPrice() {
System.out.println("# " + "price" + "cents");
}
}

62 changes: 42 additions & 20 deletions bluej.pkg
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
#BlueJ package file
dependency1.from=TicketMachineTest
dependency1.to=TicketMachine
dependency1.type=UsesDependency
editor.fx.0.height=722
editor.fx.0.width=800
editor.fx.0.x=709
editor.fx.0.y=113
objectbench.height=101
objectbench.width=461
editor.fx.0.x=683
editor.fx.0.y=25
objectbench.height=100
objectbench.width=776
package.divider.horizontal=0.6
package.divider.vertical=0.8007380073800738
package.editor.height=427
package.editor.width=674
package.editor.x=1067
package.editor.y=119
package.divider.vertical=0.8003731343283582
package.editor.height=422
package.editor.width=684
package.editor.x=640
package.editor.y=30
package.frame.height=600
package.frame.width=800
package.numDependencies=0
package.numTargets=1
package.numDependencies=1
package.numTargets=4
package.showExtends=true
package.showUses=true
project.charset=UTF-8
readme.height=58
readme.height=60
readme.name=@README
readme.width=47
readme.width=48
readme.x=10
readme.y=10
target1.height=50
target1.name=TicketMachine
target1.showInterface=false
target1.type=ClassTarget
target1.width=120
target1.x=80
target1.y=50
target1.height=70
target1.name=ExerciseAnswers.txt
target1.type=TextTarget
target1.width=130
target1.x=10
target1.y=190
target2.height=70
target2.name=TicketMachineTest
target2.showInterface=false
target2.type=UnitTestTargetJunit4
target2.width=130
target2.x=140
target2.y=110
target3.height=50
target3.name=TicketMachine
target3.showInterface=false
target3.type=ClassTarget
target3.width=120
target3.x=80
target3.y=50
target4.height=70
target4.name=README.md
target4.type=TextTarget
target4.width=120
target4.x=10
target4.y=110
Binary file modified doc/BlueJ-objects-first-ch2.pdf
Binary file not shown.
62 changes: 42 additions & 20 deletions package.bluej
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
#BlueJ package file
dependency1.from=TicketMachineTest
dependency1.to=TicketMachine
dependency1.type=UsesDependency
editor.fx.0.height=722
editor.fx.0.width=800
editor.fx.0.x=709
editor.fx.0.y=113
objectbench.height=101
objectbench.width=461
editor.fx.0.x=683
editor.fx.0.y=25
objectbench.height=100
objectbench.width=776
package.divider.horizontal=0.6
package.divider.vertical=0.8007380073800738
package.editor.height=427
package.editor.width=674
package.editor.x=1067
package.editor.y=119
package.divider.vertical=0.8003731343283582
package.editor.height=422
package.editor.width=684
package.editor.x=640
package.editor.y=30
package.frame.height=600
package.frame.width=800
package.numDependencies=0
package.numTargets=1
package.numDependencies=1
package.numTargets=4
package.showExtends=true
package.showUses=true
project.charset=UTF-8
readme.height=58
readme.height=60
readme.name=@README
readme.width=47
readme.width=48
readme.x=10
readme.y=10
target1.height=50
target1.name=TicketMachine
target1.showInterface=false
target1.type=ClassTarget
target1.width=120
target1.x=80
target1.y=50
target1.height=70
target1.name=ExerciseAnswers.txt
target1.type=TextTarget
target1.width=130
target1.x=10
target1.y=190
target2.height=70
target2.name=TicketMachineTest
target2.showInterface=false
target2.type=UnitTestTargetJunit4
target2.width=130
target2.x=140
target2.y=110
target3.height=50
target3.name=TicketMachine
target3.showInterface=false
target3.type=ClassTarget
target3.width=120
target3.x=80
target3.y=50
target4.height=70
target4.name=README.md
target4.type=TextTarget
target4.width=120
target4.x=10
target4.y=110