18) Given the following code, what will be the value of finalAmount when it is d
ID: 3915126 • Letter: 1
Question
18) Given the following code, what will be the value of finalAmount when it is displayed? 18) public class order private int orderNumber private double orderAmount private double orderDiscount; public Order (int orderNum, double orderAmt, double orderDisc) orde rNum = orde rNumber; orderAmount # orderAmt ; orderDiscountorderDisci public double getorderAmount return orderAmount; public double getorderDiscount ) return orderDiscounti import java.text. NumberFormat public class Customerorder public static void main(stringt args) int ordNum1234: double ordAmount 580.00 double discountPer 0.10 order orders new Order (ordNum, ordAmount, discountPer) double finalAmount finalAmount- orders.getorderA mount )-orders.getorderAmount ) orders.getorderDiscount ) NumberFormat fmt- NumberFormat.getCurrencyInstance) system.out.printin( Pinal order amount : t mt. format system.out.println ("Pinal order amount:t. (finalAmount));Explanation / Answer
Answer :
Output is as follows,
Final order amount : Rs.522.00
Here I have added my comments for main function.
public static void main(String[] args) {
int ordNum = 4;
double ordAmount = 580.00;
double discountPer = 0.10;
// create object and set data variables to given input
Order orders = new Order(ordNum, ordAmount, discountPer);
double finalAmount;
finalAmount = orders.getOrderAmount() - orders.getOrderAmount() * orders.getOrderDiscount();
// = 580.00 - 580.00 * 0.10
// = 580.00 - 58.00
// = 522.00 <--- answer
// Number format is used to format result into currency format
NumberFormat fmt = NumberFormat.getCurrencyInstance();
System.out.println("Final order amount : " + fmt.format(finalAmount));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.