Code the following: When an employee has worked for Anderson & Beckett for 30 years or more,...

60.1K

Verified Solution

Question

Programming

  1. Code the following:
  1. 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.

  1. 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.

  1. Re-code 1b using a while loop.

  1. 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!”

  1. Re-code 1d using double-selection ifs. You’lluse a conditional logical operator to join the sets of relationalconditions (choose the right one).

  1. 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.

  1. 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);

Answer & Explanation Solved by verified expert
4.0 Ratings (775 Votes)
please check out the solution please do a comment for any doubt thank you 1a Shares will be awarded if the employee works for 30 years using ternary operator it can be written as preferredShares yearsEmployed30 100 0 1b do SystemoutprintlnGOTTA FIND MY CAR KEYS printing the given massage foundKeysscnrnexcharAt0 taking input for foundKeys here scnr is the object of Scanner class whilefoundKeysn loop will continue until foundKeys notequals    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students