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 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...
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...
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...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user to enter a short sentence which ends in a period. Use Java String class methods to determine the following about the sentence and display in the console: • How many total characters are in the sentence? • What is the first word of the sentence? Assume the words are separated by a space. • How many characters are in the first word of the...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT