The objective of this assignment is to get familiar with Java syntax and writing simple java methods.
As practice for writing code by hand on exams, you are to write the code for each question in hand writing. You can practice writing and testing the code on a computer, but I suggest you write your solution from scratch as practice for exams.
Use precise syntax for Java. 1 mark off per compiler and/or run-time error.
All methods should be commented with correct javadoc syntax. 1 mark off per missing/bad comment.
Marking
- ( /5)
- ( /10)
- ( /5)
- ( /5)
- ( /5)
- ( /10)
Total ( /40)
This is an individual assignment. You are encouraged to discuss the general concepts of Java syntax, types, variables, methods, arrays, Strings, ifs, loops, etc. with your classmates, but the specifics for the applications in this assignment should be done completely individually. Students that copy / share work will be penalized.
Question 1: [5 marks]
Write a class named ArrayAverager that implements a method named average to return the average value of an array of type double, as done in this python snippet:
Write your class based on this provided main method:
Question 2: [10 marks]
Write a class named Gambler that implements the following code in its main method. Hint: use Math.rand() and Math.round(). Note: the console output should be formatted exactly as shown on the right:
Question 3: [5 marks]
Write a class named Greeter that implements a method named introductions, that prompts the user for their name (using the java.util.Scanner class), displays a greeting, and returns the name as a String, as done in this python snippet:
Write your class based on this provided main method:
Question 4: [5 marks]
Write a class named CapitalsCounter that implements a method named countCaps to return the number of capital letters within a String, as done in this python snippet (hint: use Character.isUpperCase()):
Write a main method to check whether or not the countCaps method correctly returns 5 when given the the string IHaveFiveCaptialLetters. It should print 🙂 if successful, or 🙁 if failed.
Question 5: [5 marks]
Write a class named NumberGuesser that implements the following code within its main method by using a do loop and the java.util.Scanner class:
Question 6: [10 marks]
Write a class named PositiveEvenFinder that implements a method named findPositiveEvens to return an int array containing all of the positive and even numbers from the provided int array, as done in this python snippet:
Use the provided main method to test your code same as this python snippet:
Reviews
There are no reviews yet.