Programming

You will be creating TWO console applications.

Application 1

Create a Console application called “Ch4-Vending”. Add a class to the application called “VendingMachine”.This class will be composed

of one field (i.e., instance variable or attribute) and several methods as follows:

· A field of type int called “DepositedAmount” (ALL amounts are in cents, NOT dollars, so an int is appropriate here)

· A constructor that takes no parameters that simply initializes the machine’s DepositedAmount to 0.

· A method (no return value) called “DepositCoin” with a single int parameter called “coinAmount”
This method is intended to add the value passed in the coinAmount parameter to the machine’s DepositedAmount field. However:
(a) the method should check the coinAmount parameter to insure that it is either 5, 10, 25 or 100 (we have a cool machine that accepts

dollar coins) before adding the value to DepositedAmount. If it is not 5, 10, 25 or 100, the method should write “Error: Unrecognized

Coin” to the screen and the amount should NOT be added.
(b) regardless of whether anything is added to the DepositedAmount field, the method should conclude by displaying the current value of

DepositedAmount (e.g., “You have deposited XXX cents so far”).

· A method (no return value) called “GetDrink” with no parameters
This method does one of two things.
(a) If the machine’s DepositedAmount is is sufficient to cover the cost of a drink (125 cents or more), then the method calculates the

change (i.e., DepositedAmount less 125 cents), writes “Your change is {change amount} cents” to the Console, and then resets the

READ ALSO :   Chapter 16: Colonialism and Colonial Transformation

DepositedAmount back to 0 (simulating giving you back your change).
(b) If the machine’s DepositedAmount is not sufficient (less than 125 cents), it just writes “You must insert 125 cents” to the

Console.

· A method (no return value) called “GetRefund” with no parameters
This method does one of two things.
(a) If the DepositedAmount is greater than 0, it simply writes “You were refunded XXX cents” (the refunded amount should be the whole

DepositedAmount) and resets the DepositedAmount field back to 0.
(b) Otherwise, if the DepositedAmount is 0

Your Main method should create a single instance of your VendingMachine class. You should then call methods on this object to fully

test that the machine is functioning properly. No need to get input from the user. Just “hard code” instructions in your Main method.

Make certain that the code in your Main method adequately tests all methods with the vending machine in all possible states. For

example, you should insure that a call to DepositCoin does work with a correct coin but not with an incorrect coin. Certainly you

should also test to make sure that a call to GetDrink fails if there is insufficient funds and succeeds otherwise. Make sure that

GetDrink leaves the DepositedAmount alone if you don’t yet have enough for a drink but that it sets DepositedAmount to zero if you do

get a drink. Etc. Perform other tests as you deem necessary. Use the same VendingMachine object and just call the methods repeatedly to

test these scenarios. Leave all of your test code in Main so that I can see your work.

READ ALSO :   Human Resources-Compensation

Application 2

Create a second Console application called “Ch4-Football”. Add a class to this application called “FootballTeam”. This class will be

composed of several fields (i.e., instance variables or attributes) and methods as follows:

· A field of type String called “Name”

· A field of type int called “Score”

· A constructor that takes a String parameter called “teamName”
The constructor simply initializes the Score field to 0 (zero) and the Name field to the value passed as teamName.

· A method called “ShowScore” with no parameters
This method writes “{Name} has a score of {Score}” to the Console. For example, if the team’s Name is “Augusta University” and their

Score is 24 then the method should write “Augusta University has a score of 24”.

· A method (no return value) called “ScoreTouchdown” with no parameters
This method adds 6 to the team’s Score field then calls ShowScore to display the current score.

· A method (no return value) called “ScoreFieldgoal” with no parameters
This method adds 3 to the team’s Score field then calls ShowScore to display the current score.

· A method (no return value) called “ScoreSafety” with no parameters
This method adds 2 to the team’s Score field then calls ShowScore to display the current score.

· A method (no return value) called “ScoreTwoPointConversion” with no parameters
This method adds 2 to the team’s Score field then calls ShowScore to display the current score.

· A method (no return value) called “ScoreExtraPoint” with no parameters
This method adds 1 to the team’s Score field then calls ShowScore to display the current score.

Use the Main method in your Program class to simulate this year’s BCS championship game between Alabama and Clemson. In other words,

READ ALSO :   Write an essay with examples on conduction, convection, and radiation

create two object instances, one with a Name of “Alabama” and the other with a Name of “Clemson”. Then call ScoreXxx methods on the

appropriate instance to mimic the scoring of the game as summarized here:

http://espn.go.com/college-football/game?gameId=400852743 (Links to an external site.)

In the above summary, TD means touchdown and FG means field goal. Most TD’s are followed by extra points. However, note that one had a

failed 2-point conversion (i.e., no extra point).

At the end of your Main method, call the ShowScore on both instances. The last two lines of a correct program will display as follows:

Alabama has a score of 45
Clemson has a score of 40

As usual, the assignment should be submitted by compressing your solution folders to a .zip or .7z file and submitting them.

TAKE ADVANTAGE OF OUR PROMOTIONAL DISCOUNT DISPLAYED ON THE WEBSITE AND GET A DISCOUNT FOR YOUR PAPER NOW!