In this assignment you'll be using what you've learned about Java to implement a library of unrelated methods. Please read and follow the directions carefully! In your assignment project, add a...


In this assignment you'll be using what you've learned about Java to implement a library of unrelated methods. Please read and follow the directions carefully!


In your assignment project, add a package a2. Add a new class SmallMethods to the a2 package.


Below, a number of methods are described. You should exactly use the provided method name and return type and then add the required parameters. Implement the method to match the specification. Comment the method using a Javadoc. Finally, you will write code in main to test the method and provide output showing these tests.


Javadoc Comments


The comment on each method you implement should have a formal Javadoc comment using @param and @return tags. In the Javadoc comment, make a short description of what the method does followed by the tags, each with a few words describing what each tagged item does. Look in the code at the makeLine method for an example of a Javadoc method comment. In addition, use single line comments to clarify anything that might be tricky to understand.


Testing


Add code to main to call the different methods as a testing mechanism. Provide output and descriptions that explain what is going on. For example, your main method might call want to test a pretend method countWords("I am David");. Your code might have


String testString = "I am David";
int numberOfWords = countWords(testString);
System.out.println("countWords found " + numberOfWords + " 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 behavior. Additional examples of testing are in the recitation code and Lecture 5.


You should test each method with a few different values to make sure different cases in the code is checked. Keep all your tests in main - copy and paste a test and change the values rather than running the program, modifying the test, and running it again. Your main should show a comprehensive record of all the ways you tested your methods.


Style


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.


You should make sure your code is nicely formatted. There should be consistent spacing and indenting. (If you type ControlOrCommand-Shift-F Eclipse will format your code for you.)


Please start early so that you'll have time to think and ask questions when you get stuck. Starting on Wednesday is a recipe for failure.



WARNING: No method except for main may print anything. Printing in a method may cause the autograder to fault. You are encouraged to add println to method while you develop the code, as a way to check on the computation. These must all be removed before submitting the assignment.


Required Methods


1.


Name: isZero
Return type: boolean
Parameter(s): an int number
Specification: Returns true if the number is equal to zero and false otherwise.


2.


Name: describeNumber
Return type: String
Parameter(s): an int number
Specification: Returns "Zero" if the number is equal to zero and "Not Zero" otherwise. This method must call isZero to check if the number is zero or not.


3.


Name: classifyNumber
Return type: String
Parameter(s): an int number
Specification: Returns "Zero" if the number is equal to zero, "Positive" if the number is greater than zero, and "Negative" if the number is less than zero. You do not need to use isZero in this method.


4.


Name: isEvenlyDivisibleByThreeOrFive
Return type: boolean
Parameter(s): an int number
Specification: Returns true if the parameter value is evenly divisible by 3 or by 5 and false otherwise. You must test for divisibility using the modulus operator x%y, which evaluates to the remainderof x/y. When the remainder is 0, x is evenly divisible by y.A starting point for learning about modulus ishttps://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/what-is-modular-arithmetic(Links to an external site.)and it was also described in Chapter 1 of the Runestone book reading.


5.


Name: chooseSmaller
Return type: double
Parameter(s): two double numbers
Specification: Returns the smaller of the two parameters. You maynotuse any existing Java capabilities, like min, to find the smaller number. In case of a tie, either one can be returned.


6.


Name: firstDoublingPastOneHundred
Return type: int
Parameter(s): an int number
Specification: Using the parameter as a starting value, repeatedly double (times two) this number until it is larger than 100. Return this final doubled value. For example, firstDoublingPastOneHundred(5) would return 160. The internalsequence of numbers produced would be 5, 10, 20, 40, 80, 160. If theparameter value is zero or negative, just return 0.


7.


Name: skipLetters
Return type: String
Parameter(s): A String
Specification: Return a String starting with the first letter in the parameter String and then skipping every other letter. Return the empty String if the input String is empty. You must use a while loop to do this and not some existing Java functionality, like a regular expression or the replace method. Work out this problem by hand before trying to code it. As a hint, you want a number that can be used as an index into the string to get a letter. Loop over the length of the string. Build up a new string from the letters you find in the old string. As an example, "David" would turn into "Dvd".


8.


Name: makeSquare
Return type: String
Parameter(s): an int value determining the size of the square
Specification:Returns a string which, when printed out, will be a square shaped like this, but of varying size (note - even though there are the same number of characters side-to-side as up-and-down, the way text is drawn makes this look not like a square. We will consider it a square.):


+-----+ |     | |     | |     | |     | |     | +-----+



The returned string should consist of size lines, each ending with a newline. In addition to the newline, the first and last lines should begin and end with '+' and should contain size-2 '-' symbols. In addition to the newline, the other lines should begin and end with '|' and should contain size-2 spaces. A newline ('\n') is a special character use to force one string to be on multiple lines. System.out.println("Hi\nThere"); will produce output like Hi
There


The method does not print anything. You may assume that the size parameter will be greater than or equal to 1. For a size of one, the method should return a String with a single + followed by the newline.


IMPLEMENTATION NOTE: For full credit (and for easier implementation), make use of the makeLine method provided below in your implementation of makeSquare. You'll need to use a loop to call makeLine the correct number of times. You should copy and paste the makeLine code and comment into your file. Study the method as a guide to how you might structure the makeSquare method.




/** * Produces a String starting and ending with the edge character and having the * inner char repeated in-between. The total number of characters in the string * is width. As an example makeLine('+', '-', 8) would return the string * "+------+". * * NOTE: This method is already completely implemented and must not be modified * for the assignment. * * @param edge The character used at the start and end of the returned string. * @param inner The character repeated in-between the edge char. * @param width The total number of characters in the returned string. Width * must be greater or equal to 2. * @return A string with width characters. */ public static String makeLine(char edge, char inner, int width) { String line = ""; int currentLocation = 0; // Make the middle part of the line first. while (currentLocation


Important Note: In general, for all our assignments, you need to solve them using the Java we have covered in class. For example, you might be able to search the internet for how to solve a particular problem and you might see some curious one line piece of code that does what is needed. Using that in place of solving the problem yourself is plagiarism, especially when the code you use is one we have not discussed and you do not understand the internet solution.

Sep 08, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here