In: Computer Science
how do you send the values of a method to the main in obj java. im having syntax errors and im not sure how to fix them or what the problem is.
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 getOrderAmount()
{
return orderAmount;
}
public double getOrderDisc()
{
return orderDiscount;
}
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);
Program:
Explanation:
Line 27: Here creating object called order for class Order by passing integer parameter
Line 28: calling setAge() method using object goodStudent
Program:
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 getOrderAmount()
{
return orderAmount;
}
public double getOrderDisc()
{
return orderDiscount;
}
public static void main(String[] args)
{
int ordNum =1234;
double ordAmount = 580.00;
double discountPer = .1;
Order order=new
Order(ordNum,ordAmount,discountPer);
double finalAmount = order.getOrderAmount()-order.getOrderAmount()
* order.getOrderDisc();
System.out.println("Final order amount =$" + finalAmount);
}//End of main()
}//End of class Order
Output: