Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q2. When the following is executed, the output is 2, What would the programmed will do the code to get the output as 8? (Hint:
Q2. When the following is executed, the output is 2, What would the programmed will do the code to get the output as 8? (Hint: Please do not change the values) public class AnswerTest { public static void main(String[] args) { int i = 42 + 45 - 48 - 5; int j = 5 + 5 - 8 + 2; int ans = i % j; System.out.printf("%d", ans); Page 3 of 6 Object Oriented Programming PROGRAMMING CS102 [02 Marks] Q3. An online retailer sells five products whose retail prices are as follows: Product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49 and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows: a) product number b) quantity sold Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping, until product number not equal to 0 and display the final results. The Output as shown: Enter product number (1-5 or 0 to stop): 1 Enter quantity sold: 5 Enter product number (1-5 or 0 to stop): 5 Enter quantity sold: 3 Enter product number (1-5 or 0 to stop): 4 Enter quantity sold: 4 Enter product number (1-5 or 0 to stop): 3 Enter quantity sold: 6 Enter product number (1-5 or 0 to stop): 5 Enter quantity sold: 2 Enter product number (1-5 or 0 to stop): 0 Total retail value of all products sold is: SR 127.09 [09 Marks] Note: Type the code in the eclipse, copy the executed code and paste it in the space provided
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