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: 3537995 • 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 double finalOrderTotal() { return orderAmount - orderAmount * orderDiscount; } } public class CustomerOrder { public static void main(String[] args) { Order order; int orderNumber = 1234; double orderAmt = 580.00; double orderDisc = .1; order = new Order(); double finalAmount = order.finalOrderTotal(); System.out.println("Final order amount = $" + finalAmount); } } 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 double finalOrderTotal() { return orderAmount - orderAmount * orderDiscount; } } public class CustomerOrder { public static void main(String[] args) { Order order; int orderNumber = 1234; double orderAmt = 580.00; double orderDisc = .1; order = new Order(); double finalAmount = order.finalOrderTotal(); System.out.println("Final order amount = $" + finalAmount); } }

Explanation / Answer

The program shows error

public Order(int orderNumber, double orderAmt, double orderDisc)

Return type of Order is not defined.

We have to define the Order return type as void

public void Order(int orderNumber, double orderAmt, double orderDisc)


On Defining the return type of Order the output is :

Final order amount = $0.0

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