Java Coding

profilepreaim
le_5.3_methods.docx

IS 2031: LE 5.3 - Methods Student Name:

1. Write the following static methods. Assume the reference variable input for the Scanner class and any global variables mentioned are already declared. All other variables will have to be declared as local unless they are parameter variables. Use printf.

a. A method that prompts for the party theme and returns the theme. Print the message “Invalid theme! Try again.” if the theme is out of range. Re-prompt until a valid entry is made.

Prompt: Party Themes

1. Anniversary

2. Birthday

3. Graduation

Enter your theme:

b. A value-receiving method that accepts the theme, and asks for the number of guests and returns that number.

Prompt: How many people will be invited to your xxxxxxxxxxxx party? where the Xs is the name of the theme from 1a. The variable storing the name of the theme is global.

c. A value-receiving method that accepts the number of guests and returns the cost for the food. Assume the cost per guest is $12.00.

d. A method that accepts the number of guests, prompts for party favors and returns the cost. Allow for multiple party favors to be chosen.

Prompt: Make your party favor selections. The cost is per guest.

1. Party Favors for Women $3.00

2. Party Favors for Men $3.00

3. Party Favors for Kids $2.00

4. Party Favors for Teenagers $3.00

5. Exit

Enter your choice:

e. A method that accepts the cost for the food and the party favors and calculates the total cost for the party and prints it:

( where the Xs is the party theme and the Zs is the total cost. )

Party: Xxxxxxxxxxxxxxx

Cost: $Z,ZZ9.99

2. Write statements that will call each of the methods you coded above. Store the values returned by the value-returning methods in variables local to the main() where main() is in the same class.

a.

b.

c.

d.

e.

1