Question

In: Computer Science

.......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 price of an item and the quantity ordered. It will calculated the total and then add 8.25% sales tax to that and return total due back to main().

Third function

Create a third function names computeBill that receives 3 parameters. It will receive the price of an item, the quantity ordered, and a coupon value. It will then calculate the total, then deduct the coupon amount, and add 8.25% sales tax. It will then return the total due to main().

Can you please use simple code  - Thank you

Solutions

Expert Solution

import java.util.*;
public class Main
{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   double price,coupon;
   int quantity;
       System.out.print("Enter price of item: ");
       price=sc.nextDouble();
           System.out.print("Enter quantity of item: ");
       quantity=sc.nextInt();
           System.out.print("Enter coupon price of item: ");
       coupon=sc.nextDouble();
   double res1   =computeBill(price);
       System.out.println("Total: "+res1);
   double res2 = computeBill(price,quantity);
       System.out.println("Total: "+res2);
   double res3 =computeBill(price,quantity,coupon);
   System.out.println("Total: "+res3);
   }
   public static double computeBill(double price)
   {
   double res1= price + price*8.25/100;
   return res1;
   }
       public static double computeBill(double price,int quantity)
   {
   double res2= price*quantity;
   return (res2+res2*8.25/100);
   }
       public static double computeBill(double price,int quantity, double coupon)
   {
   double res3= price*quantity-coupon;
   return (res3+res3*8.25/100);
   }
}


Related Solutions

USING JAVA (netbeans) In your main, ask the user for an int. Do this by first...
USING JAVA (netbeans) In your main, ask the user for an int. Do this by first printing a request for the int, then creating an int x, and using the Scanner to read an int from the user and put it in x, like this: int x = scan.nextInt(); ☑ Next read in two doubles d1 and d2 from the user. This will look a lot like what you did for the int, but the scanner reads doubles using scan.nextDouble();...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Write a program to find the prime numbers IN JAVA Ask user to input the integer...
Write a program to find the prime numbers IN JAVA Ask user to input the integer number test the number whether it is a prime number or not Then, print “true” or “false” depending on whether the number is prime or isn’t. Hint: number is prime when is has exactly 2 factors: one and itself. By this definition, number 1 is a special case and is NOT a prime. Use idea of user input, cumulative sum, and loop to solve...
In Java, I need a program that will ask a user to input how many tests...
In Java, I need a program that will ask a user to input how many tests they want the average of. For example, It needs to ask the user how many tests would you like the average of? When the user enters the amount of tests they want the average score of, the program needs to give them that many test scores to input. Then with the average, determine what their grade is, if 90-100=A if 80-90 = B etc....
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...
2. Write a program to do the following: • ask the user to input the size...
2. Write a program to do the following: • ask the user to input the size of an array of integers and allocate space for the array • ask the user to input the integer values for the array and store these values into the array • calculate and display the sum and the average of elements of the array
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be...
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be between 1500 and 2019, inclusive). 2. If the year input is not between 1500 and 2019, do not check for leap year, rather print that this year cannot be checked. 3. Take a year input from the user (should be between 1500 and 2019) 4. If the input year is a leap year, print that year is a leap year; otherwise, print that the...
Java Ask the user to input a letter grade in either upper or lower case. You...
Java Ask the user to input a letter grade in either upper or lower case. You are to output a message depending on the grade. When the input is A or a, output the word "Excellent!" When the input is B or b, output "Very Good" When the input is C or c, output "Satisfactory" For any other input you must output the word "Fail".
IN JAVA PLEASE ASAP !!! I just need the main and mergesort function Ask the user...
IN JAVA PLEASE ASAP !!! I just need the main and mergesort function Ask the user for the number of elements, not to exceed arraySize = 20 (put appropriate input validation) Ask the user for the type of data they will enter - EnglishGrade or MathGrade objects. Use your EnglishGrade and MathGrade classes Based on the input, create an appropriate array for the data to be entered. Write a helper function called recursionMergeSort such that: It is a standalone function...
Write a Python function that will do the following:1. Ask the user to input an integer...
Write a Python function that will do the following:1. Ask the user to input an integer which will be appended to a list that was originally empty. This will be done 5 times, meaning that when the input is complete, the list will have five elements (all integers).2. Determine whether each element is an even number or an odd number3. Return a list of five-string elements "odd" and "even" that map the indexes of the elements of the input list,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT