Assignment 18
Due Wednesday, November 29 at 9:20am on Canvas

Assignment 18.1: Calculating The Bill (10 pts)
  • Write a program to help you calculate your bill at a pizza restaurant.
  • Name your program
  • For this program, you will need to write 4 methods, as follows:

  • Takes in a double parameter for the price of the food.
  • calls the add_tax method to add taxes to the price.
  • calls the calculate_tip method to add the tip to the price.
  • calls the format_price method to print out the price
  • returns nothing


  • Takes in a double parameter for the price of the food.
  • adds the tax onto the the total price, assuming the tax rate is 8.5%
  • returns the update price


  • Takes in a double parameter for the current bill (price of food + tax).
  • adds the tip onto the the total price, assuming a tip of 15%
  • returns the updated price


  • Takes in a double parameter for the price.
  • prints the price in the form $X.XX
  • (Hint: How do you get the price to have only 2 decimal values?)
  • Also prints a message about the final price: "With tax and tip, your total comes to $<price>"
  • returns nothing

Additional Specifications

  • Each method must also have a full Javadoc comment in the style described in class.
  • Important: You should call the calculateBill method inside of main, not the other three methods.
  • The other 3 methods should be called inside of the calculateBill method.
  • Note that calculateTip will work very similarly to the addTax method
Sample Output
  • Your program should work identically to the following:

Welcome to Mama Domino's Pizzaria!

Enter the price of the pizza: 12.99

With taxes and tip, your total comes to $16.21

  • When you are finished, upload your program to Canvas.

Assignment 18.2: Getting More Methodical (10 pts)

  • Copy and paste the starter code into a new file called
  • Write the required methods as described by the comments (i.e. you fill in the body of the method).
  • Then, run the code when you are finished to see if you wrote the methods correctly.
  • Check the test results and make any alterations to your methods as necessary.
  • When all of the tests pass, upload your code to Canvas.

 * @author
 * CIS 36A
import java.util.Scanner;

public class More {
     * Given a string, take the last char and return a new string with the last char added at the front and back,
     * so "cat" yields "tcatt". The original string will be length 1 or more.
     * backAround("cat") → "tcatt"
     * backAround("Hello") → "oHelloo"
     * backAround("a") → "aaa"
    public static String backAround(String str) {
        return "";
     * Given 2 strings, a and b, return a string of the form short+long+short,
     * with the shorter string on the outside and the longer string on the inside.
     * The strings will not be the same length, but they may be empty (length 0).
     * comboString("Hello", "hi") → "hiHellohi"
     * comboString("hi", "Hello") → "hiHellohi"
     * comboString("aaa", "b") → "baaab"
    public static String comboString(String a, String b)
        return "";
     * Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri".
     * The string length will be at least 2.
     * middleTwo("string") → "ri"
     * middleTwo("code") → "od"
     * middleTwo("Practice") → "ct"
    public static String middleTwo(String str){
        return "";

     * Given a string, return a new string made of 3 copies of the last 2 chars of the original string.
     * The string length will be at least 2.
     * extraEnd("Hello") → "lololo"
     * extraEnd("ab") → "ababab"
     * extraEnd("Hi") → "HiHiHi"
    public static String extraEnd(String str) {
        return "";

    public static void main(String[] args)
        String value;
        System.out.println("***Testing backAround***\n");
        value = backAround("cat");
        System.out.println("Should print tcatt: " + value);
        value = backAround("Hello");
        System.out.println("Should print oHelloo: " + value);
        value = backAround("a");
        System.out.println("Should print aaa: " + value +"\n");
        System.out.println("***Testing comboString***\n");
        value = comboString("Hello", "hi");
        System.out.println("Should be hiHellohi: " + value);
        value = comboString("hi", "Hello");
        System.out.println("Should be hiHellohi: " + value);
        value = comboString("aaa", "b");
        System.out.println("Should be baaab: " + value + "\n");
        System.out.println("***Testing middleTwo***\n");
        value = middleTwo("string");
        System.out.println("Should be ri: " + value);
        value = middleTwo("code");
        System.out.println("Should be od: " + value);
        value = middleTwo("Practice");
        System.out.println("Should be ct: " + value + "\n");
        System.out.println("***Testing extraEnd***\n");
        value = extraEnd("Hello");
        System.out.println("Should be lololo: " + value);
        value = extraEnd("ab");
        System.out.println("Should be ababab: " + value);
        value = extraEnd("feet");
        System.out.println("Should be etetet: " + value + "\n");
        System.out.println("***End of Tests***");