Question
Code the following: When an employee has worked for Anderson & Beckett for 30 years or more, 100 shares of preferred stock are awarded; otherwise
- Code the following:
- When an employee has worked for Anderson & Beckett for 30 years or more, 100 shares of preferred stock are awarded; otherwise no shares are awarded. Code this if else control structure using the conditional operator (ternary operator). The variables yearsEmployed and preferredShares are already declared.
- Code a do-while loop that keeps printing the message GOTTA FIND MY CAR KEYS! as long as the keys havent been found. Assume foundKeys and input (for the Scanner class) are already declared. The variable foundKeys has been initialized to n and its the loop-control variable.
- Re-code 1b using a while loop.
- Assume calories is already declared as an integer. Code a fall-through switch statement by dividing calories by 100 in the controlling expression of the switch header, so the following messages print:
When calories are 1200 through 1800: Diet is on target.
When calories are 2000 through 2550: Calorie intake ok if active.
When calories are any other value: Calorie intake is either insufficient or too much!
- Re-code 1d using double-selection ifs. Youll use a conditional logical operator to join the sets of relational conditions (choose the right one).
- Code a for loop with the switch structure from 1d and allow 3 attempts. Prompt the user to enter calories. When the number entered is in the correct range exit the loop (not the program) after one of the messages in 1d is printed. Print the message No more attempts left! when it is the last attempt.
- Re-code the following as a do-while loop with a switch statement. Assume cruise is declared and has been set to true, so it can enter the loop. Assume choice and destination are already declared.
while(cruise)
{
System.out.printf(%nChoose a number from 1 through 4 to find out
+ which cruise you have won: );
choice = input.nextInt();
if(choice == 1)
{
destination = Bahamas;
}
else
{ if(choice == 2)
{
destination = British Isles;
}
else
{ if(choice == 3)
{
destination = Far East;
}
else
{ if(choice == 4)
{
destination = Amazon River;
}
else
{
System.out.printf(%nInvalid choice! Enter
+ 5 to continue or 0 to exit: );
choice = input.nextInt();
}//END if choice = 4 else NOT = 4
}//END if choice = 3 else NOT = 3
}//END if choice = 2 else NOT = 2
}//END if choice = 1 else NOT = 1
if(choice >= 0 && choice < 5)
{
cruise = false;
}//END if choice from 1-4
}//END while cruise is true
System.out.printf(%nYou have won a cruise to the %s!, destination);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started