Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sample Test Results. Note some of the testing files are not for this question, so just ignore them Main: package cp213; /** * Sample tests

image text in transcribed

Sample Test Results.

image text in transcribed

Note some of the testing files are not for this question, so just ignore them

Main:

package cp213;

/** * Sample tests for the Assignment 1 class methods. Not comprehensive - add your * own testing. * * @author Your name and id here * @version 2022-01-08 */ public class A01Main { // Constants private static final String LINE = "-".repeat(40); private static final String TEST_LINE = "=".repeat(80);

public static final String CIPHERTEXT = "AVIBROWNZCEFGHJKLMPQSTUXYD"; // for testing substitute method

public static void main(String[] args) { System.out.println("Assignment 1 Methods Tests"); System.out.println(); System.out.println("Tests are of the form:"); System.out.println(" Test Operation {expected value}: actual value"); System.out.println();

testIsLeapYear(); testIsPalindrome(); testIsValid(); testPigLatin(); testClosest(); testSumPartialHarmonic(); testAllDigits(); testValidSn(); testIsPrime(); testShift(); testSubstitute(); }

/** * Test isLeapYear. */ private static void testIsLeapYear() { System.out.println(TEST_LINE); System.out.println("Testing isLeapYear"); System.out.println(LINE);

int year = 1900; boolean result = LeapYear.isLeapYear(year); System.out.println("" + year + " {false}: " + result); year = 1996; result = LeapYear.isLeapYear(year); System.out.println("" + year + " {true}: " + result); year = 1999; result = LeapYear.isLeapYear(year); System.out.println("" + year + " {false}: " + result); year = 2000; result = LeapYear.isLeapYear(year); System.out.println("" + year + " {true}: " + result); System.out.println(); }

/** * Test isPalindrome. */ private static void testIsPalindrome() { System.out.println(TEST_LINE); System.out.println("Testing isPalindrome"); System.out.println(LINE);

String string = "a"; boolean result = Strings.isPalindrome(string); System.out.println("" + string + " {true}: " + result); string = "racecar"; result = Strings.isPalindrome(string); System.out.println("" + string + " {true}: " + result); string = "A man, a plan, a canal, Panama!"; result = Strings.isPalindrome(string); System.out.println("" + string + " {true}: " + result); string = "David"; result = Strings.isPalindrome(string); System.out.println("" + string + " {false}: " + result); System.out.println(); }

/** * Test isValid. */ private static void testIsValid() { System.out.println(TEST_LINE); System.out.println("Testing isValid"); System.out.println(LINE);

String string = "a"; boolean result = Strings.isValid(string); System.out.println("" + string + " {true}: " + result); string = "_a"; result = Strings.isValid(string); System.out.println("" + string + " {true}: " + result); string = "1a"; result = Strings.isValid(string); System.out.println("" + string + " {false}: " + result); System.out.println(); }

/** * Test pigLatin. */ private static void testPigLatin() { System.out.println(TEST_LINE); System.out.println("Testing pigLatin"); System.out.println(LINE);

String string = "David"; String result = Strings.pigLatin(string); System.out.println("" + string + " {Avidday}: " + result); string = "arrow"; result = Strings.pigLatin(string); System.out.println("" + string + " {arrowway}: " + result); string = "yard"; result = Strings.pigLatin(string); System.out.println("" + string + " {ardyay}: " + result); System.out.println(); }

/** * Test closest. */ private static void testClosest() { System.out.println(TEST_LINE); System.out.println("Testing closest"); System.out.println(LINE);

double target = 0; double v1 = -5; double v2 = 5; double result = Numbers.closest(target, v1, v2); System.out.println("" + target+", " + v1 +", " + v2 + " {-5.0}: " + result); target = 0; v1 = -10; v2 = 5; result = Numbers.closest(target, v1, v2); System.out.println("" + target+", " + v1 +", " + v2 + " {5.0}: " + result); System.out.println(); }

/** * Test isPrime. */ private static void testIsPrime() { System.out.println(TEST_LINE); System.out.println("Testing isPrime"); System.out.println(LINE);

int n = 7; boolean result = Numbers.isPrime(n); System.out.println("" + n + " {true}: " + result); n = 5; result = Numbers.isPrime(n); System.out.println("" + n + " {true}: " + result); n = 9; result =Numbers.isPrime(n); System.out.println("" + n + " {false}: " + result); System.out.println(); }

/** * Test sumPartialHarmonic. */ private static void testSumPartialHarmonic() { System.out.println(TEST_LINE); System.out.println("Testing sumPartialHarmonic"); System.out.println(LINE);

int n = 0; double result = Numbers.sumPartialHarmonic(n); System.out.println("" + n+ " {0.0}: " + result); n = 1; result = Numbers.sumPartialHarmonic(n); System.out.println("" + n+ " {1.0}: " + result); n = 8; result = Numbers.sumPartialHarmonic(n); System.out.println("" + n+ " {2.7178571428571425}: " + result); System.out.println(); }

/** * Test allDigits. */ private static void testAllDigits() { System.out.println(TEST_LINE); System.out.println("Testing allDigits"); System.out.println(LINE);

String string = "a"; boolean result = SerialNumber.allDigits(string); System.out.println("" + string + " {false}: " + result); string = "123"; result = SerialNumber.allDigits(string); System.out.println("" + string + " {true}: " + result); string = "12.3"; result = SerialNumber.allDigits(string); System.out.println("" + string + " {false}: " + result); System.out.println(); }

/** * Test validSn. */ private static void testValidSn() { System.out.println(TEST_LINE); System.out.println("Testing validSn"); System.out.println(LINE);

String string = "SN/1234-567"; boolean result = SerialNumber.validSn(string); System.out.println("" + string + " {true}: " + result); string = "SN/1234567"; result = SerialNumber.validSn(string); System.out.println("" + string + " {false}: " + result); string = "SN/123-4567"; result = SerialNumber.validSn(string); System.out.println("" + string + " {false}: " + result); System.out.println(); }

/** * Test shift. */ private static void testShift() { System.out.println(TEST_LINE); System.out.println("Testing shift"); System.out.println(LINE);

String string = "ABC"; String result = Cipher.shift(string, 0); System.out.println("" + string + " {ABC}: " + result); string = "ABC"; result = Cipher.shift(string, 3); System.out.println("" + string + " {DEF}: " + result); string = "ABC"; result = Cipher.shift(string, 30); System.out.println("" + string + " {EFG}: " + result); System.out.println(); } /** * Test substitute. */ private static void testSubstitute() { System.out.println(TEST_LINE); System.out.println("Testing substitute"); System.out.println(LINE);

String string = "ABC"; String result = Cipher.substitute(string, CIPHERTEXT); System.out.println("" + string + " {AVI}: " + result); string = "XYZ"; result = Cipher.substitute(string, CIPHERTEXT); System.out.println("" + string + " {XYD}: " + result); System.out.println(); }

}

7 public class Strings 8 // Constants 9 public static final String VOWELS - "sciousnou"; 12 2 * Determines if string is a "palindrome": a word, verse, or sentence (such as "Able 3 * was I cre I saw tha") that reads the same backward or forward. Ignores case, * spaces, digits, and punctuation in the string parameter s. 5 * Oparan string a string 7 * return true if string is a palindrome, false atherwise */ public static boolean ispalindrome(final String string) { ca 1 1/ your code here return false; } es 1 12 3 * Determines if name is a valid Java variable name. Variables names must start * with a letter or an underscore, but cannot be an underscore alone. The rest of the variable name may consist of letters, numbers and underscores. param name a string to test as a Java variable name * Breturn true if name is a valid Java variable name, false otherwise public static boolean isvalid(final String name) { 1/ your code here 15 27 return false; } 16 -2 -3 -5 * Converts a word to Pig Latin. The conversion is: + culs + cli>if a word begins with a vowel, add "way" to the end of the word. + cli>if the word begins with consonants, move the leading consonants to the * end of the word and add "ax" to the end of that. "y" is treated as a * consonant if it is the first character in the word, and as a vowel for * anywhere else in the word. + * Preserve the case of the word - i.c. if the first character of word is upper case, then the new first character should also be upper case. a 1 * @param word the string to convert to Pig Latin + return the Pig Latin version of word -5 27 public static String piglatin(String word) { 1/ your code here return null; ) 1 } Assigt 1 Methods Tests Tests are of the for: Test Operation (expected value actual value Testing islespear 1980 (false): false 1996 true true 1999 false false 2980 (true): true Testing IsPalindrome a true true racecar true true Asan, a plan, a canal, Panama! (true): true David [false): false Testing isvalid a true true a (true): true ia (false): false Testing pigLatin David Avidday) Avidday arrow Carroi arrow yard ardyay) andyay Testing closest 2.2, -5.2, 5.a 1-5.6): -5.6 2.8, -18., 5. (5.0): 5.8 Testing supartialarmonic @fe.e): 2.0 1 (1.0): 1.a 8 [2.7178571428571425): 2.7178571428571425 Testing allDigits a false false 123 (tre): true 12.3 (false): false Testing valide SN/1234-567 (true true SN/1234567 (false): false SN/123-4567 (false): false Testing Prime 7 true): true s true true 9 false false Testing shift ABC (ABC) ABC ABC DEF): DEF ABC EFG) : ERG Testing Substitute ABC AVI): AVI XYZ XYD): XYD

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions