Geek Even and Old Answers to the Questions

Introduction:
Write a class definition (not a program, there is no main method) named Geek (saved in a file Geek.java) that models a person who is a geek. For our purposes, a geek is someone who delights in answering all sorts of questions, such as “if a number is even or odd?”, “what is the factorial of a number?”, among other things. A Geek has a name and also keeps track of how many questions s/he has answered. Your Geek class must have only two instance variables – the Geek’s name and number of questions asked so far

Methods:

  • public Geek (String name): the Geek's name, the number of questions is assigned to zero

  • public String getName(): takes no parameters and returns the Geeks’s name as a String (don’t count this request in the total questions)

  • public int getNumberOfQuestions(): takes no parameters and returns as an int how many questions has been asked (don’t count this request in the total)

  • public boolean isEven (int num): takes an integer and returns a boolean value indicating if the num is even or not

  • public boolean isVowel(char input): takes a character and returns true if the input character is a vowel (a, e, i, o or u). The method should be case-insensitive

  • public int factorial(int num): takes an integer and computes the factorial of it. The factorial of a positive integer n (written n!) is equal to the product of the positive integers from 1 to n.

  • public String printBinary(int num1): takes an integer as parameter and returns a string containing that integer’s binary representation. For example, the call of printBianry(44) should return 101100

  • public int gcd(int num1, int num2): takes two integers and returns the greatest common divisor (GCD) of the two numbers. The GCD of two integers a and b is the largest integer that is a factor of both num1 and num2.


Save the Geek class in a file called Geek.java and use the following program stored in Assignment5.java, which has the main method to create new Geek object and to test the methods in the class Geek. A sample output is shown below
Important Notes: Your class should have exactly the method headers that are described or otherwise your class will not work with the test driver program (Assignment5.java) that is provided. You should never change the test driver program if the test driver is provided but instead make changes to Geek class to make it work.

Assignment5.java will ask a user to enter one of the following commands. Based on the user's choice, the program needs to perform corresponding operation. This will be done by using a method you defined in the Geek class. The program will terminate when the user enters 'q'. Here is a sample output:
Command Options
-----------------------------------
a: get name
b: number of questions asked
c: is even
d: is it a vowel
e: factorial
f: print Binary
g: find GCD
?: display the menu again


Powered by