Assignment 17
Due Tuesday, June 12 at 1:20pm on Canvas

Assignment 17.1: Getting More Methodical (10 pts)

  • Copy and paste the starter code into a new file called More.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 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***");

       
    }
   

}



Assignment 17.2: Valid Email Address? (10 pts)
  • Let's write a program, in a file named Email.java, to check an email address to see if it is valid.
  • For the purposes of this assignment, we will use three criteria to determine if an email address is valid:
    • The address must end with one of the following extensions: .com, .org or .edu
    • The address must not contain a space
    • The address must have an @ character contained somewhere in the String
  • You will write 3 methods and 3 Javadoc comments. Each method will check each of the above conditions.
  • Your first method signature should look like this:

public static boolean validExtension(String address) {

    //method body will go here

}

  • The second method signature should look like this:

public static boolean containsSpace(String address) {

    //method body will go here

    }

  • The third method signature should look like this:

public static boolean containsAt(String address) {

    //method body will go here

    }
  • Hint: Do not alter the starter code, given below, in any way. Your job is only to add to it where indicated:
/**
* @author Name
* section info
*/

import java.util.Scanner;

public class Email {
    public static void main(String[] args) {
        String address;
        Scanner input = new Scanner(System.in);
        System.out.print("Enter your email address: ");
        address = input.nextLine();

        if (!containsAt(address)) { // the method will return true or false so
                                    // we can check in an if statement
            System.out.println("Invalid email. Your email address must contain an @ symbol");
        } else if (false) { // replace false with method call here
            System.out.println("Invalid email. Your email address cannot contain a space");
        } else if (false) { // replace false with method call here
            System.out.println("Invalid email. Your email must contain a .com, .edu or .org extension");
        } else {
            System.out.println("Your email address is valid.");

        }
    }
   
    //Write JAVADOC comment here for validExtension
    public static boolean validExtension(String address) {
        // write method body here
        return false;
    }
   
   
    //Write JAVADOC comment here for containsSpace
    public static boolean containsSpace(String address) {
        // write method body here
        return false;
    }


    //Write JAVADOC comment here for containsAt
    public static boolean containsAt(String address) {
        // write method body here
        return false;
    }

}