Assignment 19
Due Thursday, June 14 at 1:20pm on Canvas

Assignment 19.1: Getting Even More Methodical (10 pts)

  • Copy and paste the starter code into a new file called EvenMore.java
  • 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 EvenMore {
   
    /*
         Given a String, return true if the String starts
        with "hi" and false otherwise.
        startHi("hi there") → true
        startHi("hi") → true
        startHi("hello hi") → false
     */

    public static boolean startHi(String str) {
        return false;
    }
   
    /*
         Given a String and a non-negative int n,
        the front of the String is the first 3 chars,
        or whatever is there if the string is less than length 3
        Return n copies of the front;
        Hint: use a for loop and string concatenation
        frontTimes("Chocolate", 2) → "ChoCho"
        frontTimes("Abcd", 3) → "AbcAbcAbc"
        frontTimes("Oy", 4)  → "OyOyOyOy"
     */
    public static String frontTimes(String str, int n) {
        return "";
    }
   
    /*
        Given 2 int values, return whichever value is nearest to the value 10,
        or return 0 in the event of a tie.
        Hint: recall that Math.abs(n) returns the absolute value of a number.
        close10(8, 13) → 8
        close10(13, 8) → 8
        close10(13, 7) → 0
     */
   
    public static int close10(int a, int b) {
        return 0;
    }
   
    /*
         Given a String, return true if the first instance of "x" in
        the String is immediately followed by another "x".
        Hint: use a for loop and substring
        doubleX("axxbb") → true
        doubleX("axaxax") → false
        doubleX("xxxxx") → true
     */

    public static boolean doubleX(String str){
        return false;
    }
   

  

    public static void main(String[] args)
    {
        String value;
        boolean result;
        int num;
        System.out.println("***Testing startHi***\n");
        result = startHi("hi there");
        System.out.println("Should be true: " + result);
        result = startHi("hi");
        System.out.println("Should be true: " + result);
        result = startHi("hello hi");
        System.out.println("Should be false: " + result +"\n");
     
        System.out.println("***Testing frontTimes***\n");
        value = frontTimes("Chocolate", 2);
        System.out.println("Should be ChoCho: " + value);
        value = frontTimes("Abcd", 3);
        System.out.println("Should be AbcAbcAbc: " + value);
        value = frontTimes("Oy", 4);
        System.out.println("Should be OyOyOyOy: " + value + "\n");
         
        System.out.println("***Testing close10***\n");
        num = close10(8, 13);
        System.out.println("Should be 8: " + num);
        num = close10(13, 8);
        System.out.println("Should be 8: " + num);
        num = close10(13, 7);
        System.out.println("Should be 0: " + num + "\n");
     
        System.out.println("***Testing doubleX***\n");
        result = doubleX("axxbb");
        System.out.println("Should be true: " + result);
        result = doubleX("axaxax");
        System.out.println("Should be false: " + result);
        result = doubleX("xxxxx");
        System.out.println("Should be true: " + result + "\n");
     
        System.out.println("***End of Tests***");

      
    }
  

}



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

calculateBill
  • 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

addTax

  • 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

calculateTip

  • 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

formatPrice

  • 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.