Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment you'll be using what you've learned about Java to implement a library of static methods. Please read and follow the directions carefully!
In this assignment you'll be using what you've learned about Java to implement a library of static methods. Please read and follow the directions carefully! In your assignment project, add a package a2. Import starter code from this Google Drive file https://drive.google.com/file/d/1dP9r4RlvlwlXEX4kXbwrKxFBXB3S7CNp/view?usp sharing e It contains method stubs (the signature and a method body which returns some default result) and comment descriptions of several methods for you to implement as well as an already implemented method to help you for one problem. The method stubs are precisely specified in their comments and/or method headers. Your job is to implement the methods so that they adhere to their specifications. These methods will exercise much of what you've learned about Java. You will be using primitive values (such as ints, booleans, and chars) and objects (such as Strings and Scanners). You'll be using lots of different kinds of expressions. You'll be using a variety of statements, such as variable declarations, assignments, while loops, conditionals, and returns Be sure to add your name as the author to the Javadoc comment associated with the class. The comment on each method you implement should be replaced with a more formal Javadoc comment using @param and @return tags. Notice how I have chosen descriptive names for all classes, methods, and variables. If you want full credit, you should do the same with your code. Notice how my code is nicely formatted. Your code should be nicely formatted too. (If you type ControlOrCommand-Shift-F Eclipse will format your code for you.) You will almost certainly find this more challenging than A1. Some of the methods require you to be very comfortable with things like substring and joining strings together with +. Some of them are quite short but you will need to be clever about how to solve the problem. Others will need you to look up certain Java operations so that you can use them comfortably. Please start early so that you'll have time to think and ask questions when you get stuck. Starting on Wednesday or Thursday is a recipe for failure. You will also notice from reading the comments that you need to add code to main. This is mostly for your benefit - you need to call your implemented methods to see if they work. But, provide output and descriptions that explain what is going on. For example, your main method might call want to test countTokens("l am David"). Your code might have String testString-"I am David"; int numberOfTokens countTokens(testString); System.out.println("countTokens found" numberOfTokens+"on test input: " + testString); When you run your program with more of these tests, you would see a sequence of these reports on the method behavion Submitting To turn in your program for grading, upload the .java file to assignment 2 in Gradescope. You will see a number of tests pass or fail. Additional tests and TA evaluate will happen after the due date You can upload a solution as many times as you like, but we will only grade your most recent submission. his tool needs to be loaded in a new browser window package a2; *A collection of methods for the second assignment of CS 1410. * author Your name goes here *Instructions for students: Use the main method only to make calls to the * other methods and to print some testing results *The correct operation of your methods should not depend in any way on the * code in main Do not do any printing within the method bodies, except the main method *Leave your testing code in main - you will be graded on this. You can remove * this comment from your submission public class MethodCollection [ *In main, write code that exercises all the methods you write. This code *should call the methods with different arguments and print out results. You should think about different arguments to try that tests different cases. For example, if the method returns a true or false, write code that creates a true result and other code that produces a false result. Use print statements *to explain what each test is checking and the result that was obtained. The assignment gives a small example of this *Running this program should output a small report on examples of using the * different methods. * Replace this comment with your own Javadoc comment public static void main (String[] args) Returns the number of tokens (as identified by the s.next method on a *Scanner s) that appears in the parameter sentence For example, countTokens ("this is a test" should return , and *countTokens("") should return D IMPLEMENTATION NOTE: This will require a while loop. Use a Scanner to split the string into individual words You may not use more advanced Java functions that do the token counting for you *Replace this comment with your own Javadoc comment public static int countTokens (String sentence) // Change or modify the return. This is here for now to prevent compiler errors. return 0 *Returns the number of tokens (as identified by the s.next method on *Scanners s) in the parameter sentence that are not an int, as identified by s"hasNext Int(). For example, countTokensThatAreNotint("this is 12 a test") *should return 4, and countTokensThatAreNotInt ("12") should return 0 IMPLEMENTATION NOTE: This will require a while loop. Use a Scanner to split the string into individual words. Use an if statement to figure out whether *to count the token or not. *Replace this comment with your own Javadoc comment public static int countTokensThatAreNotInt (String sentence) // Change or modify the return. This is here for now to prevent compiler return 0; Returns a string literal "negative" if the parameter is less than zero and equal to zero For example, the method call deacribeSign should return "non-negative" You should use an if statement You must return these strings exaczly (all lower case letters, spelled denote a string literal, they do not appear in the actual string Do not print the string return value * returns the string literal "non-negative" if th value is greater than or *correctly, no extra spacesAlso note that the double quotes are used to * Replace this comment with your own Javadoc comment public static String deacribeSign (int value // Chang or modify the return. This is her' for now to prevent comp iler errors return ""; Returns irue if the value parameter is evenly divisible by7 and false *otherwise For example, the method call isEvenlyDivisibleBySeven (14) should return true *The method call isEvenlyDivisibleBySeven 16) should return false * You will want to use the modu-u8 operator , which evaluates to the remainder of x/y. When the remainder is 0. x is evenly divisible by y *A starting point for learning abou: modulus is * https:/ww.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/what-is-modular-arithmetic * Replace this met with your own Javaiac comment public static boo1ea n sRvenlyDivisibleBySeven(int value) / Change or modify the return. This ia here for now to prevent compiler errora return true; *Returns a String of length width that begins and ends with the character edge *and contains width-2 copies of the character inner in between. For example, * if edge is +inner is '-*, and width is 8, the method should return The method does not print anything. The parameter width must be greater than or equal to 2 IMPLEMENTATION NOTE: This method is already completely implemented. There is dd your ow Javadoc comment * no need for you to change anything in the code public static String make. ine(Cha r edge, cher inner, int width) { String line - " int i =0; while (i The returned string should consist of width linea, each ending with a while i /pre> * The returned string should consist of width lines, each ending with a *newline. In addition to the newline, the first and last lines should begin *and end with and should contain width-2'-' symbols. In addition to the newline, the other lines should begin and end with '1' and should contain *width-2 spaces A newline is a special character use to force one string to be on multiple * lines. System.out .println("Hi There''); will produce output like Hi There The *' character is a newline *The method does not print anything. The width parameter must be greater than *o equal to 2. You do not need to check this, you can assume it IMPLEMENTATION NOTE: For full credit (and for easier implementation), make *use of the makeLine method in your implementation of makeSquare. You'1l *need to use a loop to cal1 makeLine the correct number of tines Replace this comment with your own Javadoc comment public static String makeSquare (int width) return *Returns the string that results from capitalizing the last character of word, *which is required to have at least one character. For example, * capitalizeLastCharacter("hello") is "hello" and capital izeLastCharacte r { "JACK" S "JACK" * IMPLEMENTATION NOTE: The static method Character.toUpperCase() will be helpful. The methods s.charAt and s.substring [where s is a String] will * also be helpful. * Since Strings are immutable, you cannot just change the last character. Think *about breaking the given string into pieces, modifying the last part and then * building up a new String in the correct form *Replace this comment with your own Javadoc comment public static String capitalizeLastCharacter(String word) I Change or remove this statement as needed return"; Returns the string that results from capitalizing the last character of every * word in the input parameter sentence, which is required to have at least one * character. For example, capitalizeLastcharactersInSentence ("Hello there" * would retun "Hello therE". You can assume that the sentence is a basic * English-style sentence with a singie space between words Replace this corment with your ow Javadoc coment public static String capitalizeLastcharactersInSentence (String sentence) 1 Change or remove this statement as needed return
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started