You have 80 minutes to complete this test.
This is a closed book test (you may use resources linked below).
Follow the instructions below carefully!!
The test will begin at 11.30am and will end at 12:50pm (you will have a 5 minute warning to submit your work)
cd
cd eclipse-workspace/labtest
submit 1710 lab5 Question*.java
submitted: Question1.java (61 bytes)
submitted: Question2.java (61 bytes)
submitted: Question3.java (61 bytes)
All files successfully submitted.
During the test, please keep this terminal open, and use it to submit regularly. Do this by simply clicking into the open terminal window, press the up arrow key to find your previous submit command, and hit enter to re-submit.
submit -l 1710 lab5
For each of the following questions, open the corresponding QuestionX.java
file in Eclipse,
and complete the program/method(s) as per the given instructions below. As you complete each, do a submit
(remember repeated submits will just overwrite older submissions - be sure to submit regularly)
In Question01.java, write a simple program (main method) that determines the total cash value held in a piggy bank jar full of small Canadian coins. The jar may contain only three types of coin within: nickels (worth 5 cents), dimes (worth 10 cents), and quarters (worth 25 cents).
Setup your own variables, assign them values and ensure that your code so follows all appropriate STYLE conventions discussed in lectures (i.e. so that it is readable, has no magic numbers, compiles). YOU DO NOT NEED TO GET INPUT FROM THE USER!!
Format your output so that it displays the result in the following way:
Example 1: nickels=10, dimes=4, quarters=62 would give the following output:
nickels dimes quarters total ========== ========== ========== ========== 10 4 62 $16.40
Example 2: nickels=150, dimes=456, quarters=380 would give the following output:
nickels dimes quarters total ========== ========== ========== ========== 150 456 380 $148.10
Example 3: nickels=150, dimes=456, quarters=380 would give the following output:
nickels dimes quarters total ========== ========== ========== ========== 3055 5809 6670 $2401.15
In Question2.java complete a simple static method love6(a, b)
that,
given two integer values (a and b), will return true if either input (a or b) is 6, or
their sum or difference is 6. Otherwise, it returns false
Note: the function Math.abs(num)
computes the absolute value of a number (and may be used)
Examples of calling love6(a,b)
with resulting output are shown below:
love6(6, 4)
returns true
love6(4, 5)
returns false
love6(1, 5)
returns true
love6(a, b)
in the Question2.java fileIn Question03.java, complete the static method stringSplosion(str)
that takes the String
str
as an input, and returns a new String as its result (formatted according to the following):
The returned String should be made up of several substrings joined together, each created from the input
by progressively including the first 1,2,3, ... up to N characters of the original string str
. Where N is the length of str
.
For example, given a non-empty string like "Code" return a string like "CCoCodCode":
Other example input/outputs include:
stringSplosion("Code")
returns "C"+"Co"+"Cod"+"Code" = "CCoCodCode"
stringSplosion("abc")
returns "a"+"ab"+"abc" = "aababc"
stringSplosion("ab")
returns "a"+"ab" = "aab"
Hint: you will likely need to use the substring method from java.lang.String
Again, there are tests included which you can run from the main method to check your output
To submit, again, copy and paste the following into the terminal window you opened earlier, and hit enter:
submit 1710 lab5 Question*.java