Question: Learning Goals: Conditional Structures in Java if, if else, cascaded if, nested if, switch Testing. Make sure your programs run by testing them. Correct them

Learning Goals:

Conditional Structures in Java if, if else, cascaded if, nested if, switch

Testing. Make sure your programs run by testing them. Correct them if they do

not.

This is an individual lab. Complete each of the programs here. (I may do the first with you in

class.) Note that these are programs that we previously did as pseudo code. Copy or re-write the

pseudo code as single line // java comments as an outline for your program. Create separate

Netbeans project for each program using the names I specified. Create single java main class

for each of the programs using the filenames I specified.

Don't forget to code the pseudo code for your program first within the java main() section as

single line comments

// comment.....

Then code the java statements for the pseudo code. In each

task, use a test suite that covers each of the logical paths the program can take. e.g. (for the first

program) user enters an item less than $100, or user enters one > $100 Your screen shots should

support that you did this testing! (You don't have to provide shots for each case though, just at

least one for each task.)

Simulating Input: since we don't know how to do java input yet, we will simulate it. Just set the

variable to a value as if you had input it. Change your code and rerun it to test multiple values.

In most cases, the testing just requires you to confirm that the code works when the input is

correct and when it is not.

if (CONDITION)

{

Code statements in this block execute if the CONDITION is true

}

// this is the end of the block like the endIf in our pseudo code

And here is the if..else:

if (CONDITION)

{

Code statements in this block execute if the CONDITION is true

}

else

{

Code statements in this block execute if the CONDITION is false

}

// this is the end of the block like the endIf in our pseudo code

Cascaded if:

if(CONDITION)

{

}

else if (CONDITON)

{

}

// more else if (CONDITON) blocks go here

else // no condition a default when all the other if tests fail

{

}

As you test each program, you have to run it multiple times. Instead of screen shots, just

copy the output window from Netbeans into the doc for EACH test run. There will be

several for each program. Please make sure that your output is readable, that's what we

use to grade your work.

1. Task 1 (5 pts):

Project name: ShipCostCalculator

Main file name: shipCost.java

An application program where the user enters the price of an item and the program

computes shipping costs. If the item price is $100 or more, then shipping is free

otherwise it is 2% of the price. The program should output the shipping cost and the

total price.

Test runs: (insert the output widow copies here for the test runs)

- valid input less than 100

- valid input greater than 100

2. Task 2 (5 pts):

Project name: BirthMonth

Main file name: birthMonth.java

A program that asks the user to enter their birth month (integer 1 - 12 inclusive). If the

user enters a value in range, the program echoes the input ("Your birth month is: N")

If the value is not in the range it outputs an error msg ("You entered an incorrect

month value: N"). Here N should be the value they entered.

Test runs: (insert the output widow copies here for the test runs

- valid input in range 1 - 12

- invalid input out of range

3.

Task 3 (5 pts):

Project name: PartyAffiliation

Main file name: partyAffil.java

(This task uses Strings:) A program that prompts the user for their party affiliation

(Democrat, Republican, or Independent) and responds accordingly with a Donkey,

Elephant, Person, or Other. (i.e. "You get a Democratic Donkey.") Notes: create

menu so the user chooses D, R, or I and assume that any other choice will be Other.

Tests: just the four options D, R, I, Other. Use as cascaded if structure not separate if

statements!

Test runs: (insert the output widow copies here for the 4 test runs)

4. Task 4 (5 pts):

Project name: KioskCheck

Main file name: Kiosk.java

As people pass through an entry kiosk at the theater, they are prompted to enter their age.

If they are 21 or older, they get a paper wrist band. Code a logic program that asks the

user to enter their age and then if they are 21 or over displays a message that they get a

wrist band. (Note that the program does nothing if they are not 21 or over...)

4. Task 5 (3 pts Extra or Graduate Credit):

Project name: Comparitor

Main file name: Comparitor.java

A program that takes two numbers as inputs from the user and compares them. It

indicates if they are equal or if they are not indicates the one that is less.

EMBED SCREEN SHOTS OF NETBEANS HERE SHOWING YOUR PROGRAM

RUN

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!