CSC1110 Homework 2

Complete the following CodingBat problems

Remainder
HelloName
MakeABBA

Compile and execute your program in the terminal

/*
 * Course: CSC1110
 * Assignment: Homework 2
 * Name: TODO: YOUR NAME HERE
 */

/**
 * Copy the code you have written for the CodingBat
 * questions and paste them into the corresponding
 * static methods. Once the code has been copied
 * compile and execute the program in the terminal
 * to verify the code was correctly copied.
 */
public class Homework2 {
    public static void main(String[] args) {
        final int[] remainderTests = {5, 3, 3, 2, 8, 4, 7, -2, 36, 25, -4, -2, -5, -2, 1024, 16};
        final String[] nameTests = {"Bob", "Alice", "X", "Dolly", "Alpha", "Omega", "Goodbye",
                "ho ho ho", "xyz!", "Hello"};
        final String[] abbaTest = {"Hi", "Bye", "Yo", "Alice", "What", "Up", "aaa", "bbb", "x",
                "y", "x", "", "", "y", "Bo", "Ya", "Ya", "Ya"};

        System.out.println("Starting tests...");
        System.out.println("Testing remainder...");
        for(int i = 0; i < remainderTests.length; i += 2) {
            System.out.println(remainderTests[i] + " % " + remainderTests[i + 1] + " = " +
                    remainder(remainderTests[i], remainderTests[i + 1]));
        }
        System.out.println();

        System.out.println("Testing helloName...");
        for (String nameTest : nameTests) {
            System.out.println(helloName(nameTest));
        }
        System.out.println();

        System.out.println("Testing makeAbba...");
        for(int i = 0; i < abbaTest.length; i += 2) {
            System.out.println(makeAbba(abbaTest[i], abbaTest[i + 1]));
        }
        System.out.println();

        System.out.println("Tests completed");
    }

    /**
     * Given two integers, numerator and denominator,
     * divide the numerator by the denominator and return
     * the remainder of the operation.
     *
     * @param numerator The first integer
     * @param denominator The second integer
     * @return The remainder from dividing numerator by denominator
     */
    private static int remainder(int numerator, int denominator) {
        // TODO: delete the contents of the method and copy your CodingBat code here
        return -1;
    }

    /**
     * A method that greets a given name with a loud, cheery Hello!
     * @param name The name of the person to be greeted
     * @return a String that greets the person in the form of "Hello *person*!"
     */
    private static String helloName(String name) {
        // TODO: delete the contents of the method and copy your CodingBat code here
        return null;
    }

    /**
     * A method that combines two strings in the form abba
     * e.g. If the two string were "a" and "b", the result would be "abba"
     * @param a The first String
     * @param b The second String
     * @return The resulting String in the form abba
     */
    private static String makeAbba(String a, String b) {
        // TODO: delete the contents of the method and copy your CodingBat code here
        return null;
    }
}

Sample Output

Starting tests...
Testing remainder...
5 % 3 = 2
3 % 2 = 1
8 % 4 = 0
7 % -2 = 1
36 % 25 = 11
-4 % -2 = 0
-5 % -2 = -1
1024 % 16 = 0

Testing helloName...
Hello Bob!
Hello Alice!
Hello X!
Hello Dolly!
Hello Alpha!
Hello Omega!
Hello Goodbye!
Hello ho ho ho!
Hello xyz!!
Hello Hello!

Testing makeAbba...
HiByeByeHi
YoAliceAliceYo
WhatUpUpWhat
aaabbbbbbaaa
xyyx
xx
yy
BoYaYaBo
YaYaYaYa

Tests completed

Submission Instructions:

Submit your Homework2.java file and a screenshot of the terminal window showing the output of the program after it has executed.