Question: Write a Java statement to accomplish each of the following tasks. (2 marks) Assign the sum of x and y to z, and increment x

  1. Write a Java statement to accomplish each of the following tasks. (2 marks)

  1. Assign the sum of x and y to z, and increment x by 1 after the calculation. Use only one statement.

  1. Calculate the remainder after q is divided by num, and assign the result to q.

Write this statement in two different ways.

  1. Determine the best data type for each of the following so that any reasonable value is accommodated but no memory storage is wasted. Give an example of a typical value that would be held by the variable. (3 marks)
  • Age of a college student
  • Postcode of a house address
  • Price of products in a supermarket

  1. Meadowdale Dairy Farms sells organic eggs to local customers. They charge $3.25 for

a dozen eggs, or 45 cents for individual eggs that are not part of a dozen. Write a program that prompts user for the number of eggs in the order and then display the amount owed with a full explanation. For example, typical output might be, You ordered 27 eggs. Thats 2 dozen at $3.25 per dozen and 3 loose eggs at 45 cents each for a total of $7.85. Use a sequence program structure. (6 marks)

  1. Declare a variable named operation and assign an integer value of 2. Another integer type variable named number is assigned a value of 10. Write a switch segment code named operation. The following actions must be executed when users enter the case options:
  • Enters 1, number will hold the result of number + 10.
  • Enters 2, number will hold the result of number 4.
  • Enters 3, number will hold the result of number /3.
  • Enters 4, number will hold the result of number * 10.

(6 marks)

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 Databases Questions!