Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: Programming (20 points) For this assignment, you will implement a class named Geek in a file named Geek.java. For our purposes, a geek

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Part 2: Programming (20 points) For this assignment, you will implement a class named Geek in a file named Geek.java. For our purposes, a geek is someone who delights in answering all sorts of questions, such as Is the number 381 evenly divisible by 3? Which of these numbers is closes to Pi, 2.91 or 3.29? How many times does the letter'a' appear in the statement "an apple a day keeps the doctor away."? .Is the number 7 between the numbers 9 and 6? What number do you get if you reverse the digits of the number 38714? In addition to being able to answer questions like these, a Geek will keep track of their name and the number of questions he or she has been asked. you are given the following driver file named Assignment5.java . This file contains a main method and some supporting methods. This driver file will be used to test the Geek class that you implement. Make no changes to this driver file. Your Geek class must have only two instance variables - one for the Geek's name and one for the numberOfQuestions asked so far. Method Description This constructor method will take a String argument with the name of a new Geek. This method must initialize the Geek's name to the value of this argument, and will initialize the Geek's numberOfQuestions to 0 public Geek(String name) This method will return a copy of the value stored in the Geek' name variable. This method will return a copy of the value stored in the Geek' numberOfQuestions variable This method will return the boolean value true if the argument is evenly divisible by 3. Other wise the method will return false. This method will also increment the value of the numberOfQuestions variable by one This method will return the the value of the first argument if the first argument is closer to 3.1415927 than the second argument value. Other wise the method will return the second argument value. This method will also increment the value of the numberOfQuestions variable by one. this method will count the number of times that the char letter appears in the String statement. The method will return that count. This method will also increment the value of the numberOfQuestions variable by one public String getName0) public int getNumberOfQuestions) public boolean divisibleBy3(int value) public float closerToPi(float value1, float value2) public int countln(String statement, char letter) This method will return the boolean value true if the argument value b is numerically between the values of a and c. Other wise the method will return false. This method will also increment the value of the numberOfQuestions variable by one. This method will return an int where the digits from the argument number are reversed. For example, called with the argument value 43125, this method would return the int 52134. This method will also increment the value of the numberOfQuestions variable by one. public boolean isBetween(int a, int b, int c) public int reverseNumber(int number) Important Notes: Your Geek class should have the exact method headers that are described above otherwise your class will not work with the test driver program (Assignment5.javathat is provided. You should never make any changes to the test driver program if the test driver is provided. Helpful hints for doing this assignment: work on it in steps- write one method, test it with a test driver and make sure it works before going on to the next method always make sure your code compiles before you add another method your methods should be able to be called in any order Sample Output, with user input in red Command Options a) Display Geek's name b) Display Number of questions asked so far C) Is number evenly divisible by 3 d) Which of two numbers is closer to Pi e) Count number of times a letter appears in a string f) Is number between two other numbers g) Reverse a number ?) Display this menu q) Quit Please enter a command: a Geek's name: Bob Smith Please enter a command: b Number of questions asked so far: 0 Please enter a command: c Enter an integer: 123 123 is evenly divisible by 3 Please enter a command: c Enter an integer: 124 124 is not evenly divisible by 3 Please enter a command: d Enter the first number: 1.11 Enter the second number: 9.99 1.11 is closer to Pi Please enter a command: e Enter a statement: over the river, and through the wood Enter a letter to search for: o o appears 4 times Please enter a command: f Enter three integers: 2 is between 1 and 3 Please enter a command: f Enter three integers: 5 3 5 is not between 1 and 3 Please enter a command: g Enter an integer: 123456 The digits in reverse are 654321 Please enter a command: ? Command Options a) Display Geek's name b) Display Number of questions asked so far C) Is number evenly divisible by 3 d) Which of two numbers is closer to Pi e) Count number of times a letter appears in a string f) Is number between two other numbers g) Reverse a number ?) Display this menu q) Quit Please enter a command q Note: Do not use any Java language or library features that we have not already covered in class. For example, do not use arrays or ArrayLists. Submit your Assignment by following the instructions below: 1. Upload and submit your Geek.java file here. import java.uti1.Scanner public class Assignment5 public static void main(String[] args) Scanner console new Scanner(System.in); String menuChoice "none" char command x' int intInputA0, intInputB 0, intInputC-0; float floatInputA-0.0f, floatInputB 0.0f String stringInput char cha rinput = X'; // instantiate an object of type Geek Geek myGeek new Geek("Bob Smith"); displayMenu(); 0 // ask a user to choose a command System.out.print("InPlease enter a command: "); menuChoice console. nextLine( ) . toLowerCase() ; command menuChoice.charAt (0); switch (command) case 'a': // display the Geek's name System.out.println( "Geek's name: "myGeek.getName ()); break; case 'b':// Display Number of questions asked so far System.out.println( "Number of questions asked so far: "myGeek.getNumberOfQuestions)) break; case "c': // Is number evenly divisible by 3 System.out.print("Enter an integer: "); intInputA = Integer.parseInt (console. nextLine()); if (myGeek.divisibleBy3(intInputA)) System.out.println (intInputA " is evenly divisible by 3") else System. out.println(intInputA + .. s not evenly divisible by 3"); break; case 'd:// Which of two numbers is closer to Pi System.out.print("Enter the first number: ") floatInputA Float.parseFloat(console.nextLine)) System.out.print("Enter the second number:") floatinputB = Float.parseFloat (console.nextLine()); System.out.println(myGeek.closerToPi(floatInputA, floatInputB) "is closer to Pi"); break; case 'e':// Count number of times a letter appears in a string System.out.print("Enter a statement: "); stringInput console.nextLine(); System.out.print("Enter a letter to search for: "); charInput = console. nextLine(), charAt (0); myGeek.countIn(stringInput, charInput); System.out.println(charInputappears "+myGeek.countIn(stringInput, charInput) + " times"); break; case 'f:I/ Is number between two other numbers System.out.println("Enter three integers: ") intInputAInteger.parseInt(console.nextLine)); intInputB Integer.parseInt(console.nextLine)) intInputc Integer.parseInt(console.nextLine()) if (myGeek.isBetween (intInputA, intInputB, intInputc)) System.out.println (intInputB else is between "intInputAand "intInputC) System.out.println (intInputB break; is not between "intInputA " andintInputC); case 'g':// Reverse a number System.out.print("Enter an integer: "); intInputA = Integer.parseInt (console.nextLine()); System.out.println("The digits in reverse are "+ myGeek.reverseNumber(intInputA)); break; case '?':// Display the menu displayMenu) break; break; System.out.printIn("Invalid input!!!"); case 'q': // quit the progem default: // invalid choice // end of switch while (command'q) // end of the main method public static void displayMenu() System.out.println("Command Options"); System.out.println(" System.out.println("a) Display Geek's name") System.out.println("b) Display Number of questions asked so far"); System.out.print1n(") Is number evenly divisible by 3"); System.out.println("d) Which of two numbers is closer to Pi") System. out.println("e) Count number of times a letter appea rs in a string"); System.out.println("f)Is number between two other numbers"); System.out.println("g) Reverse a number"); System.out.println("?) Display this menu") System.out.println("q) Quit"); // end of the displayMenu method // end of class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

Students also viewed these Databases questions

Question

Describe new developments in the design of pay structures. page 475

Answered: 1 week ago