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

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
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 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
Question: Conversion Program * This program will ask the user to input meters * After input,...
Question: Conversion Program * This program will ask the user to input meters * After input, a menu will be displayed: * 1. Convert to kilometers * 2. Convert to inches * 3. Convert to feet * 4. Quit * * The user will select the conversion and the converted answer will be displayed. * The program should redisplay the menu for another selection. * Quit program when user selects 4. Hi, my instructor requirement fix the bug in the...
The JAVA program should do the following: –Ask the user for how many lines of text...
The JAVA program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number supplied by the user, but...
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
write a program i java that ask the user to enter salary, user ID and username...
write a program i java that ask the user to enter salary, user ID and username and out put them
Task 2.5: Write a script that will ask the user for to input a file name...
Task 2.5: Write a script that will ask the user for to input a file name and then create the file and echo to the screen that the file name inputted had been created 1. Open a new file script creafile.sh using vi editor # vi creafile.sh 2. Type the following lines #!/bin/bash echo ‘enter a file name: ‘ read FILENAME touch $FILENAME echo “$FILENAME has been created” 3. Add the execute permission 4. Run the script #./creafile.sh 5. Enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT