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

Given the following code, what will be the value of finalAmount when it is displ

ID: 3574757 • Letter: G

Question

Given the following code, what will be the value of finalAmount when it is displayed?

public class Order
{
   private int orderNum;
   private double orderAmount;
   private double orderDiscount;

   public Order(int orderNumber, double orderAmt,
       double orderDisc)
   {
   orderNum = orderNumber;
   orderAmount = orderAmt;
   orderDiscount = orderDisc;
   }
   public int getOrderAmount()
   {
       return orderAmount;
   }
   public int getOrderDisc()
   {
       return orderDisc;
   }
}

public class CustomerOrder
{
   public static void main(String[] args)
   {
   int ordNum = 1234;
   double ordAmount = 580.00;
   double discountPer = .1;
   Order order;
   double finalAmount = order.getOrderAmount() —
       order.getOrderAmount() * order.getOrderDisc();
   System.out.println("Final order amount = $" +
       finalAmount);
   }
}

528.00

Explanation / Answer

Answer: There is no value because the object order has not been created.

There is a compilation error because Order order; has not been created.

We just decalred that Order object but not initialized. we need to initilaize that object first then only we can access object properties.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote