Question

In: Computer Science

how do you send the values of a method to the main in obj java. im...

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);

Solutions

Expert Solution

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:



Related Solutions

In Java Script how do you code an array with the values and suits of cards...
In Java Script how do you code an array with the values and suits of cards (all 52 cards in a deck) 2 different array one that just has the face values of the card, and the other with the suit value. Then have it randomly give you 1-2 cards from the deck without repeating? (Example: Dealer gives player two cards. Player asks for a hit and the dealer gives a different card, no repeats). Game is Blackjack.
JS Suppose you have an object named obj. How do you serialize it to a JSON...
JS Suppose you have an object named obj. How do you serialize it to a JSON string with each level indented two spaces? This action is the inverse of JSON.parse.
Language: Java Create a TryIt.java program with a main method. You are going to use this...
Language: Java Create a TryIt.java program with a main method. You are going to use this program to demonstrate some things about how Java works. Make your methods here private, because they are not intended to be called from outside the program. For each test below, make sure that you print to the console: 1) What is being tested 2) The desired output 3) The actual output Question to be answered: Should you use == or the String method equals...
The main method is where Java begins execution of your program. In this assignment, you will...
The main method is where Java begins execution of your program. In this assignment, you will coding other methods in addition to the main method. These additional methods will perform specific functions and, in most cases, return results. Write all your methods in a class named Homework6Methods.java 
 1 Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values 2Write a public static method named getMinOf2Ints that takes in 2...
Hello guys. Below is a test im struggling with I have to do it in Java...
Hello guys. Below is a test im struggling with I have to do it in Java and use OOP concepts. Create. A House class with instance variables erfNumber, location, noOfRooms, etc. Mandatory properties: status(is the asset owned or sold), number of years owned, selling price, and buying price. At least two overloaded constructors that can be used to instatiate House objects. Getter and setter methods for all properties you have created. A method checkProfitOrLoss() that returns the profit or loss...
How do you write a Java method that is called : public static String[] noIdenticalCombine(String[] array1,...
How do you write a Java method that is called : public static String[] noIdenticalCombine(String[] array1, String[] array2) { // instructions: returns an array that contains all the Strings in array1 and array2 but without repetition. order does not matter, but it will return array1's elements and then array2's element that are not in array1. Assume there are no duplicates are in array1 and array2. Could use count which is how many str there are in array2, where !contains(array1, str)....
How much money do you spend to send a single packet to the Internet? How much...
How much money do you spend to send a single packet to the Internet? How much money do you spend to send 1 billion packets to the Internet? Try to explain how do you get these numbers? Try to discuss whether it is a reasonable business model or not?
How is this method coded in Java?
How is this method coded in Java?
Java It would be nice if you use many Functions. rite a method, besides main(), which...
Java It would be nice if you use many Functions. rite a method, besides main(), which will calculate the lowest common multiple (LCM) of two numbers. For example, the multiples of 4 are 4, 8, 12, 16, 20, 24 …, and the multiples of 6 are 6, 12, 18, 24 …. The LCM is 12. Do NOT use any code from the Internet! Here are some more examples: 3:5 LCM is 15 4:8 LCM is 8 5:7 LCM is 35...
How do I go back to the start of the main method with the given code?...
How do I go back to the start of the main method with the given code? Hello I am making this java program and there is a point in the code where if the user types the character y it will start the program back at the beginning of the main method. How can I do this without drastically changing the code? For instance, if I type y, the program will go back to line 1 and repeat the entire...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT