Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the following Coding Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). Keep identifiers to a reasonably short

Use the following Coding Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). Keep identifiers to a reasonably short length. User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Assignments Documentation: At the beginning of each programming assignment you must have a comment block with the following information: /*------------------------------------------------------------------------- // AUTHOR: your name // FILENAME: title of the source file // SPECIFICATION: description of the program // YOUR Lab Letter and Name of the TA for your Closed lab // FOR: CSE 110- homework #- days and time of your class // TIME SPENT: how long it took you to complete the assignment //----------------------------------------------------------------------*/ Reasonably good amount of comments should be added in your program so that it is easy for other people to understand it. Please see the comment style in the textbook. Part 1: None Part 2: Programming (20 points): 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 is this string a palindrome?, what is the sum of all numbers between two numbers? 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 Geeks name and number of questions asked so far Methods Description of the methods public Geek (String name) Constructor-Sets the Geek's name and the number of questions asked public String getName() takes no parameters and returns the Geekss name as a String (dont count this request in the total questions) public int getNumberOfQuestions() It takes no parameters and returns as an int how many questions has been asked (dont count this request in the total) . public int smallest(int num1, int num2, int num3) It takes three integers and returns the smallest of the three integers. Count it as a request. public int sum (int num1, int num2) It takes two integers and computes and returns an int which is the sum of all numbers between the two inclusive (include the numbers in the sum) for full credit this method should work even if the two numbers are the same (the sum is just one of the numbers) or if the first number is larger than the second. Also, you cannot assume which number will be greater. Count it as a request. public String repeat(String str, int n) It takes a string and an integer count and returns the string str repeated n times. For example, repeat(ho,3) returns hohoho. Count it as a request. public boolean isPalindrome (String str) It takes a string and returns true if the str is palindrome, that is, a word that is the same when reversed. Example of palindrome are deed , racecar, rotor. Count it as a request. Public boolean overlap(String str1, String str2) String str1 is said to overlap String str2 if all of the characters in str1 also appear in str2. Write a method that will return true if str1 overlaps str2 and false otherwise. Count it as a request. Save the Geek class in a file called Geek.java. Write a test driver called Assignment6.java with the main method to create a new Geek object and to test the methods in the class Geek. A sample output is shown below. Assignment6.java will provide the following menu to the user. Based on the user's choice, the program needs to perform corresponding operation. This will be done by calling (invoking) one of the methods you defined in the Geek class. The program will terminate when the user enters 'q'. Command Options ----------------------------------- a : Geek's name b: Num Questions asked c: Smallest of three numbers d: Sum between two integers e: Repeat the string f: It is palindrome g: string 1 overlaps string 2 ?: Display q: Quit Here is the description for each option: a: asks for the Geeks name b: returns the number of questions asked so far c: asks for three integers and prints the smallest integer d: asks for two integers and returns the sum of the two e: asks for a string and an integer, repeats the string n times f: asks for a string and prints if the string is palindrome or not g: asks for two strings and finds out if it overlaps ?: displays the menu q: quits 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 (user input is in bold): Command Options ----------------------------------- a: Geek's name b: Num Questions asked c: All are the same d: Sum between two integers e: repeats a string f: Palindrome g: Overlapping strings ?: Display q: Quit Please enter a command or type? a Geek Please enter a command or type? b 0 Please enter a command or type? c Enter a number: 3 Enter the second number: -2 Enter the third number: 6 the smallest is -2 Please enter a command or type? b 1 Please enter a command or type? d Enter the first number: 4 Enter the second number: 7 The sum between 4 and 7 is 22 Please enter a command or type? b 2 Please enter a command or type? f Enter a string: madam The string madam is palindrome. Please enter a command or type? f Enter a string: hello The string hello is not palindrome. Please enter a command or type? e Enter a string: hi Enter an integer: 4 hihihihi Please enter a command or type? b 5 Please enter a command or type? g Enter a string: bcabcd Enter another string: abc The string abc overlaps with bcabcd Please enter a command or type? q

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago