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

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...
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)....
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 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?
.......Subject Java..... main() main() will ask the user for input and then call functions to do...
.......Subject Java..... main() main() will ask the user for input and then call functions to do calculations. The calculations will be returned to main() where they will be printed out. First function Create a function named computeBill that receives on parameter. It receives the price of an item. It will then add 8.25% sales tax to this and return the total due back to main(). Second function Create another function named computeBill that receives 2 parameters. It will receive the...
IN JAVA Write a MAIN METHOD that asks for user input of a positive integer and...
IN JAVA Write a MAIN METHOD that asks for user input of a positive integer and a negative integer validates the inputs using a loop and then calls the METHOD from Question 3 and prints the result. The MAIN should have two variables (appropriately typed), get the input from the user and store them in the variables after validating them, then call the method from question 3 (sending parameters, if necessary) and print the returned value with an appropriate descriptive...
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...
QUESTION: Add code so that if no parameter values are specified for method “main”, then the...
QUESTION: Add code so that if no parameter values are specified for method “main”, then the error message “file name expected” is printed out instead of the "Opening file " message. Hint: If no parameter values are specified for method “main”, then the length of the array “args” will be zero. If that error message “file name expected” is printed out, the program should stop. You can make any Java program stop using this line … System.exit(0); skeleton code: /**...
JAVA- How do I edit the following code as minimally as possible to add this method...
JAVA- How do I edit the following code as minimally as possible to add this method for calculating BMI? BMI Method: public static double calculateBMI(int height, int weight) { double BMI = (((double) weight) * 0.453592d) / ((((double) height) * 0.0254) * (((double) height) * 0.0254)); Format f = new DecimalFormat("##.######"); return (f.format(BMI)); } Code: import java.text.DecimalFormat; import java.util.Scanner; public class test2 { public static void main(String[] args) { DecimalFormat f = new DecimalFormat("##.0"); Scanner reader = new Scanner(System.in); System.out.printf("%10s...
Write a java method to swap between two values in a singly linked list
Write a java method to swap between two values in a singly linked list
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT