Due (electronically): Tuesday October 10, 5:30 pm
This assignment gets you defining methods, both instance and static, with return values and without, with arguments and without. It also has you use (call) these methods. It uses various primitive types, which will be covered by the end of the week and which you can also read about in the textbook. You may not use conditional statements (if, switch nor ?: ).
Submit all your files electronically. If you don't finish the whole assignment, submit what you do have done so it can be considered for part marks.
We begin with a method midpoint which returns the midpoint (the value halfway inbetween) of two integers. Inspired by Java's Math class, we make a class MoreMath to hold this one method.
The method has been started for you. Your job is to download the code and replace the two comments /* REPLACE ME */ with an appropriate return type (choose it carefully) and body. Submit (electronically) your modified file MoreMath.java.
Next we make a static method exclusiveOr which returns whether one but not both of two booleans is true. We make a class booleanHelper to hold this one method (the class name violates our naming convention slightly, but we've chosen it to emphasize that this class works with the boolean primitive type and not the class Boolean).
Here's a code fragment illustrating the expected behaviour, contrasting it with Java's or (||):
System.out.println(false || false); System.out.println(booleanHelper.exclusiveOr(false, false)); System.out.println(booleanHelper.exclusiveOr(false, true)); System.out.println(booleanHelper.exclusiveOr(true, true)); System.out.println(true || true);The output would be:
false false true false true
Your job is to download the code and define the method exclusiveOr inside the class booleanHelper that's been started for you. Submit your modified file booleanHelper.java.
Next, we put three static methods into a class Interactions. The description of these methods follows. Your job is to make a new file Interactions.java and define the class and its methods. Submit your created file Interactions.java.
This method prints the text
Press Enter/Return when you're ready to continue.to the standard output.
Then, using a BufferedReader given to it, waitForGo reads a line of input and returns. The line of input isn't used in any way after being read.
This method takes a String and a char (in that order) and determines whether the String begins with the char, ignoring the case.
E.g., begins produces true if given "hello" and 'H', or "hello" and 'h', but produces false if given "hello" and 'e'.
This method takes a String and returns whether it starts with one of 'y' or 'Y'.
Use (i.e. call) the method begins to implement isAffirmative.
This puts some of our work together. The class GetAWish has a main method which asks the user about whether they want a motorcycle and/or a car. This information is then stored in a Wish object. Wish objects can render judgement on the wish.
Your job is to implement the main method of GetAWish, the constructor of Wish and the judgement method of Wish. Download the code (there are two files) and look at the comments inside for more specific details about the code to write. Where appropriate, use (call) methods from parts two and three instead of copying the code from the method bodies. Submit your modified files GetAWish.java and Wish.java.