- Code the following:
- When an employee has worked for Anderson & Beckett for 30years or more, 100 shares of preferred stock are awarded; otherwiseno shares are awarded. Code this if … else controlstructure using the conditional operator (ternaryoperator). The variables yearsEmployed andpreferredShares are already declared.
- Code a do-while loop that keeps printing themessage “GOTTA FIND MY CAR KEYS!†as long as the keys haven’t beenfound. Assume foundKeys and input (for theScanner class) are already declared. The variablefoundKeys has been initialized to ‘n’ and it’sthe 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 dividingcalories by 100 in the controlling expression of the switch header,so the following messages print:
When calories are 1200through 1800: “Diet is on target.â€
When calories are 2000through 2550: “Calorie intake ok if active.â€
When calories are any othervalue: “Calorie intake is either insufficient or too much!â€
- Re-code 1d using double-selection ifs. You’lluse a conditional logical operator to join the sets of relationalconditions (choose the right one).
- Code a for loop with the switch structure from1d and allow 3 attempts. Prompt the user to enter calories. Whenthe number entered is in the correct range exit the loop (not theprogram) after one of the messages in 1d is printed. Print themessage “No more attempts left!†when it is the last attempt.
- Re-code the following as a do-while loop witha switch statement. Assume cruise isdeclared and has been set to true, so it can enter theloop. Assume choice and destination are alreadydeclared.
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 acruise to the %s!â€, destination);