Question
Java programming

Create a simple tip calculator called TipCalcMethod. Your program should read in the bill amount from the command-line, then show 3 tip amounts: 15%, 20% and 25% of the bill. Dont worry about rounding the result to two decimal places, but make sure that the result includes cents (not just dollars). This program will be different than your first Tipcalc program because you will writea method to calculate the tip amount. program will have 2 methods: main) and tip) main( ) will be responsible for 1. converting the command-line value to the appropriate data type 2. calling the tip) method with the bill amount and each of the 3 tip percentages (you will call this method 3 times) 3. printing the results to the screern tip() will be responsible for 1. taking 2 values as input: the bill amount and the tip percentage 2. calculating the tip amount for the given input 3. returning the tip amount calculated name your method tip() as the grading script will be searching for this method to give you credit. Here is an example of what your program output should look like (assuming the command-line i nput was 19.98): 15%: $2.997 28x: $3.996 25%: $4.995
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,
Thank you for the opportunity to help you with your assignment.

The following is the code for your requirements as in the instructions.I have made sure to include all that is necessary for you to complete this assignment.

I have added comments in the code for your reference. The output and screenshot is at the end of this answer.

If you have any queries, need changes in the code or need help in following the code, leave me a comment.

I will reply within reasonable time.

If this answer helps you with your assignment, do upvote it.
Your vote will motivate me to work better.

The following is the code
//File: TipCalcMethod,java


public class TipCalcMethod {
//Method calculates the tip percentage for the bill amount
public static double tip(double billAmount, double tipPercentage) {
return billAmount * (tipPercentage/100);
}
//Main method to read user input from cmdline and calculate different tip percentages
public static void main(String[] args) {
if(args.length == 0) {
System.err.println("Usage: java TipCalcMethod <bill amount>");
return;
}
double billAmount = Double.parseDouble(args[0]);
//Calculate and display tip percentages
System.out.println("15%: $" + tip(billAmount, 15));
System.out.println("20%: $" + tip(billAmount, 20));
System.out.println("25%: $" + tip(billAmount, 25));
}
}


And finally, this is the output when the code is executed
//Output:

java TipCalcMethod 19.98

D TipCalcMethod.java 3 2 public class TipCalcMethod 4 5 public static double tip(double billAmount, double tipPercentage) //Method calculates the tip percentage for the bill amount return billAmount * (tipPercentage/100); 8 9 //Main method to read user input from cmdline and calculate different tip percentages 10 public static void main(String[] args) if(args.length= θ) { 12 13 14 15 16 17 18 19 System.err.println(Usage: java TipCalcMethod <bill amount>); return double billAmountDouble.parseDouble(args [0]); //Calculate and display tip percentages System . out.println(15%: $ + tip bilLAmount, System . out.println(20%: $ + tip(biuAmount, System . out.println(25%: $ + tip(biuAmount, 15)); 2 )); 25)); 23 24 Problems Javadoc Declaration Search ConsoCoverage terminated> TipCalcMethod Java Application] /usr/lib/jvm/java-8-oracle/bin/java (Sep 15%: $2. 997 29% : $3. 9960000000000004 25%: $4.995 10, 2018, 7:08:10 AM)

Add a comment
Know the answer?
Add Answer to:
Java programming Create a simple tip calculator called TipCalcMethod. Your program should read in the bill...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Specification Write a C program to implement a simple calculator that accepts input in the...

    1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...

  • Could you guys write an efficient java program to implement BST. Your java program should read...

    Could you guys write an efficient java program to implement BST. Your java program should read words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in xxxxx5.java file (5th java project), where xxxxx is the first 5 characters of your last name. To compile: javac xxxxx5.java To execute: java xxxxx5 < any data file name Your main method should...

  • Create a program named TipCalculation that includes two overloaded methods named DisplayTipInfo. One should accept a...

    Create a program named TipCalculation that includes two overloaded methods named DisplayTipInfo. One should accept a meal price and a tip as doubles (for example, 30.00 and 0.20, where 0.20 represents a 20 percent tip). The other should accept a meal price as a double and a tip amount as an integer (for example, 30.00 and 5, where 5 represents a $5 tip). Each method displays the meal price, the tip as a percentage of the meal price, the tip...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • In this assignment, you will write a Java program(s) to print the binary representation of a...

    In this assignment, you will write a Java program(s) to print the binary representation of a positive integer inserted from command line.  You must finish your assignment in 2 different ways: Using a recursive method Using an iterative method     Your main method must be: public static void main(String[] args) {      int input;         input = Integer.parseInt(args[0]);     print_recursion(input);     print_binary(input); }     You must implement a class and test your program by different input values, including 0. Comment your program properly Example of test...

  • I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according...

    I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...

  • Create a Java Program to calculate baggage charges. Here are the rules: A. Two bags per...

    Create a Java Program to calculate baggage charges. Here are the rules: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers on a ticket....

  • Create a class named Program10. Your program should have the following 4 methods (other helper methods...

    Create a class named Program10. Your program should have the following 4 methods (other helper methods are allowed, but these four methods must be implemented as specified). You need to define a global scanner object and only use it inside the main method and the getValues method, since other methods do not get any values from the input. getValues: This method does not have any input parameter and returns an array of integers. This method prompts the user with a...

  • Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start...

    Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start with the bolded comment section in the code below. Create a class that will take string input and process it as a multidimensional array You will modify the program to use a multi-dimensional array to check the input text. SudokuCheckApplication.java import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class SudokuCheckApplication extends Application { public void start(Stage primaryStage)...

  • Write a MARIE program to implement one round of rock paper scissors game. Your program should...

    Write a MARIE program to implement one round of rock paper scissors game. Your program should represent the three moves ‘rock’, ‘paper’ and ‘scissors’ with numbers 1, 2 and 3 respectively. When the program is run, there should be two input prompts, one after the other, to ask for player 1’s and player 2’s moves (a number 1, 2 or 3). Then the program would compare both numbers and apply the following rules to work out the winner. Paper beats...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT