- Parent Category: Programming Assignments' Solutions
We Helped With This JAVA Programming Assignment: Have A Similar One?
|More Info||Java Assignment|
ISM3230 Individual Assignment 3 – Conditional Logic Fall 2017
You are developing an application for an insurance company that needs to categorize insurance quote requests based on some questions about the insured property. The inputs into the application are property data, the output is either an error message when insurance is not available, or a categorization of the property into one of six categories. Your classification routine will be only a small part of a larger program, so you may not use System.exit() method to terminate any of the branches. The relevant decision tree is given in the figure below:
Your task is to collect relevant data in the proper sequence and either finish the classification with a category number (an integer from 1 to 6) or with an error message that contains the appropriate status. All System.out.println() methods, either for the category or for the error, must occur at the end of the routine, after all the classification tree has been processed. Follow the requirements below. Make sure your prompts and error messages match the sample output.
1. Define two named constants for the two values of house age that are used in one of the tests. This way any hard-coded values are consolidated at the top of the program and are easy to change in the future. The MAX_AGE is 90 years, the SAFE_AGE is 35 years. Use the named constants in the tests, not the values of 35 and 90.
2. Declare a category variable as an integer. Declare an errorMessage variable as a string. Initialize both variables to their respective default values: 0 for category and “no error” for errorMessage.
3. Create a scanner object for reading values from the keyboard. You can reuse the same object for reading all the values - you don't have to be creating multiple scanner objects.
Hint: When reading user data, use only nextLine(). If the data is numeric, convert it to a number with Integer.parseInt(). This will avoid the issue with the extra new line character when reading text after numbers with nextInt().
4. Prompt user for property information, store it in appropriate variables, and use the values to make decisions. To simplify things, you can make your decisions on the basis of the first letter of the input. For example, if the prompt is “Own or rent?" you only need to check whether the input started with "O" or "o" to mean own.
Hint: extract the first letter and convert it to one case and check against that.
5. For simplicity, you don't have to do error checking of user input. The prompts were chosen so that the words start with different letters. That allows you to assume that if it is not the option you're checking for, it must then be the other option. So in the case of "Own or rent?", if the input is not starting with "o" or "O", it must be rent. Alternatively, you could check the input for "r" or "R" to mean rent, and anything else would mean own.
6. The information should be entered in the following order. Ask for the input only if it is relevant to the situation, for example, do not ask for the age of the house if we are renting:
a. Prompt for "Own or rent? " and read the input. Store in a variable and make a classification decision.
b. When appropriate, prompt for "Apartment or mobile home or house? " and read the input. Store in a variable and make a classification decision.
Hint: check for 2 of the 3 options, assume the 3rd option if the input does not match the other 2.
c. When appropriate, prompt for "Enter house age in years:" and read the input. Store in a variable and make a classification decision. Hint: use nextLine() and Integer.parseInt() for input.
d. When appropriate, prompt for "Passed inspection: yes or no?" and read the input. Store in a variable make a classification decision.
e. When appropriate, prompt for " Windows: impact or regular or jalousie?" and read the input. Store in a variable make a classification decision.
f. After the classification is done, your category variable should equal to a value from 1 to 6 or it should have its default value and the errorMessage variable should contain the message. In the first case, print out the category number, in the second case, print out the error message.
• Do not use System.exit()
• Use only one println to print the category value or one println to print the error message
• Use nesting as appropriate. Do not test for the same thing more than once. Do not use a boolean flag to indicate an error condition
• For string options, test only on the basis of the first letter of each choice.
• This is not required but if you decide to test against all string options, then handle the incorrect input by setting the errorMessage variable to some sensible value that describes the error.