Project #1

CMSC 131

Due:  Wed., February 18 at 11:00 pm

Object-Oriented Programming I

Type of project: Open

Spring 2009


Determining Properties of Integers

Objective

This project will allow you to practice using variables, final string variables, input/output facilities, conditional statements, logical operators, and the Eclipse IDE.

 

Overview

You will write an application which will output the properties of a sequence of three numbers the user types as input.  It will determine features such as if they are all unique and positive in addition to if they were in ascending or descending order.  Beyond that, there are other properties as listed below. 

This project is considered "open". Please visit the course web page for information regarding the open/closed policy for projects of this course.

Specifications

The project will request and read up to three integers.  Each will be requested by displaying the prompt:

 

give a positive integer:

 

If the user does not follow directions and types in a non-positive integer, the program should terminate immediately after the error message that says:

 

error stopping now - bad because: 

 

This message must be followed on the same line by the integer that was typed by the user.  In addition, the program must make sure the three integers given by the user are unique (no two are the same value).  As soon as two are given which have the same value, the program should terminate immediately after an error message that says:

error stopping now - bad because: 

This message must be followed on the same line by the integer that was typed by the user, and then it must be followed on the next line by the words:

not unique

Assuming all three values are typed with neither of these two error messages printing, the next task is to determine if the three numbers are majority odd or majority even.  (Notice that since there are three values – one and only one of these must be true.)

The next line of output will be exactly the following if two or more of the numbers given were even:

majority even

or the following if two or more of the numbers given were odd:

majority odd

The last part will determine if the numbers (in the order given) were ascending (each larger than the one before), descending (each smaller than the one before) or neither ascending nor descending.   This one line of output will be one and only one of the following (because again one and only one can be true for any given sequence of numbers):

ascending

descending

no order

If the numbers given are neither ascending or descending, there is no further testing and therefore no further output to this run of the program.  If the numbers appeared in either ascending or descending order, they must be further tested to see if they are a special pattern of ascending or descending.  The types are described below:

linear: this means the difference between the lower two numbers is exactly the same as the difference between the upper two numbers.  If this is the case, the single line of output must be added that says: linear progression

times two: this means that it is not linear and that the middle value is exactly double the smallest and the largest value is exactly double the middle value.  If this is the case, the single line of output must be added that says: halfs progression if it is descending or doubling progression if it is ascending.

times three: this means that it is not linear nor a times two and that the middle value is exactly three times the smallest and the largest value is exactly three times the middle value.  If this is the case, the single line of output must be added that says: thirds progression if it is descending or tripling progression if it is ascending.

Getting Started

In order to help you get started, we have defined an NumberProperties class with a main( ) method in a file named NumberProperties.java. This file can be retrieved by checking out the project called Spring09Proj1 from the CVS repository. Remember that you must have set up your repository in order to check out and submit projects.  (Refer to Project #0 for more specific instructions.)   After checking out the project, switch over to Java perspective to open the source-code file and begin working on it.

If you write the project from scratch, without checking out the "Spring09Proj1" files from your CVS repository, you will not be able to submit your work.

 

Requirements

 

Sample Runs

The following examples show how your program should behave.  Note that items underlined represent the things that are entered by the user.  Keep in mind these are just examples and not the only scenarios that your program is expected to handle.  You should run all of these and make sure they appear in the console exactly as shown here (except for the italics).

 

Example1:

give a positive integer: 3

give a positive integer: 1

give a positive integer: 5

majority odd

no order

 

Example2:

give a positive integer: 2

give a positive integer: 4

give a positive integer: 5

majority even

ascending

 

Example3:

give a positive integer: 16

give a positive integer: 8

give a positive integer: 4

majority even

descending

halfs progression

 

Example4:

give a positive integer: 2

give a positive integer: 2

error stopping now - bad because:  2

not unique

 

Example5:

give a positive integer: 5

give a positive integer: 2

give a positive integer: 1

majority odd

descending

 

Example6:

give a positive integer: 3

give a positive integer: 2

give a positive integer: -1

error stopping now - bad because:  -1

 

 

Example7:

give a positive integer: 0

error stopping now - bad because:  0

 

Example8:

give a positive integer: 2

give a positive integer: 3

give a positive integer: 3

error stopping now - bad because:  3

not unique

 

Example9:

give a positive integer: 1

give a positive integer: 3

give a positive integer: 9

majority odd

ascending

tripling progression

 

Submission

Submit your project from Eclipse by right-clicking the project folder and selecting "submit".  You may submit as many times as you want -- we will only grade your submission that receives the highest number of points on our tests.  After you have submitted your project, you should visit the submit server.  There you can obtain limited feedback about how well your project is performing.  The number of times you can run our tests on your project (before the due date) is limited.  The earlier you begin working on the project, the more opportunities you will have to see how your project performs on our tests before the due date!

Grading

There are two public tests (corresponding to example 1 and example 2 above) and seven release tests which will be run on your project.  Together, these tests will dictate 90% of the grade on the project.  The remaining 10% will be based on your use of correct programming style.

Web Accessibility