Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The remaining questions all involve writing code. Yon do not have to write a ful

ID: 3852816 • Letter: T

Question

The remaining questions all involve writing code. Yon do not have to write a full program for any of these! Assume that the class and main method are already included. Assume that any needed import statements are already included. Assume that you have a Scanner object named s already created. Declare any new variables you want to use. Unless you have a strangely masochistic attitude towards your writing hand you can abbreviate System.out.println as SOP. Suppose you are setting up a pricing scheme for a data plan. The basic charge is exist0.05 per MB of data transfer per month. However to encourage your customers to transfer loss of data (and hence make yourself filthy rice) you offer the following discounts. The discounts are applied to the entire data amount transferred. (This means it would actually be cheaper to transfer 2001 MB instead of 2000 MB.) a. Suppose you've already declared two variables: dataAmt, to hold the amount of data transferred in MB, and cost, to hold the customer's cost in dollars. dataAmt already has a value assigned to it, but cost does not. Write a multibranch if statement that assigns the correct value to cost based not. Write a multibranch if statement that assigns the correct value to cost based on the table above. b. Would a switch statement be a good choice for the above task? Why or why not?

Explanation / Answer

so, here is the program via using if-else statement:-

   double dataAmt, cost;
       double discount;
      
       if(dataAmt<=2000){
           discount=0;
       }else if(dataAmt>200 && dataAmt<=5000){
           discount = 0.15;
       }else if(dataAmt>5000){
           discount=0.25%;
       }
      
       // cost = original price - discounted price.

i am just writing the logic, you can calculate the cost of data used.

You can't use conditional statements with switch.

because

switch statements can only work with fixed values.