Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Topics

- Implementing classes & testing

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.

Part #1: Written Exercises (0 pts)
None

Part #2 - Programming (20 pts)
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 Geek's name and number of questions asked so far.
- public Geek(String name, int numQuestions) - Constructor - sets the Geek's name and the num- ber of questions asked.
- public String getName() - Takes no parameters and returns the Geek'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 ques- tions has been asked (don't count this request in the total).
- public boolean isEven(int num1, int num2) - It takes two integers and returns a boolean value indicating if the sum of the numbers is even or not (this counts as the Geek being asked one more question, so update the appropriate instance variable).

- public int sum(int num1, int num2) - Takes two integers 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.
- public boolean leapYear(int year) - It takes an integer and returns a boolean value indicating if the year is a leap year. A leap year is one with 366 days. A year is a leap year if:
- it is divisible by 4 (for example, 1980),
- except that it is not a leap year if it is divisible by 100 (for example 1900);
- however, it is a leap year if it is divisible by 400 (for example, 2000).
There were no exceptions before the introduction of the Gregorian calendar on October 15, 1582 (for example, 1500 was a leap year). You may NOT use Java's GregorianCalendar class. (This counts as the Geek being asked one more question, so update the appropriate instance variable).

Save the Geek class in a file called Geek.java. Write a test driver called Assignment5.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.

Assignment5.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 : get name
b: number of questions asked c: sum is even
d: sum between two integers e: leap year
?: display the menu again q: quit this program

Here is the description for each option:
a: asks for the Geek's name
b: returns the number of questions asked so far
c: asks for two integers and prints if the sum of the numbers is even
d: asks for two integers and returns the sum of all numbers between them, inclusive e: asks for an integer and returns if it is a leap year or not
?: displays the menu q: quits

Java, Programming

  • Category:- Java
  • Reference No.:- M92394980
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As