Initial submission due Tuesday, October 26, 11:59:59pm
This assignment will assess your mastery of the following objectives:
if
) statements to conditionally excecute code.Scanner
to accept and process user input.This program prompts a person for income and expense amounts, then calculates their net monthly income. Like Assessment 3, this program's behavior is dependent on input from a user (user input is bold and underlined in the examples below). Your output should match our examples exactly when given the same input, but if the input changes, the output will also. Additional execution logs will be posted on the course website, and you can use the Mark button in Ed to check your output for various inputs.
The program begins with an introductory message that briefly explains the program, then prompts the user for the number of income categories and reads in that many income amounts. Next, the program asks whether the user would like to enter monthly or daily expenses. (The user enters 1 for monthly and 2 for daily.) When entering monthly expenses, the amounts input are the total amount for the month. When entering daily expenses, the amounts input are for a single day, and should be multiplied by the number of days in a month to get the monthly total (see below). The program will then read in a number of expense categories and an amount for each category, similar to how income was read.
After reading all the user input, the program should then print out the total amount of income and expenses for the month, as well as the average income and expense per day. You may assume a month has exactly 31 days, though you should use a class constant so that your program can be easily modified to change this assumption (see below). The program should print out whether the user spent or earned more money for the given month and by how much. If income and expenses were exactly equal, the user is considered to have spent $0 more than they earned (as opposed to earning $0 more than they spent).
Finally, the program should print out which category the user falls into based on their net income for the month, where the net income is the result of subtracting the user's expenses from their income. The category should be followed by a custom message of your choice about the user's spending habits. This message must be different for each of the four ranges shown below, and should consist of one line of any non-offensive text you choose. Each category must have a separate, unique message. The categories are defined below.
Net income range | Category |
---|---|
More than +$250 | big saver |
More than +$0 but not more than +$250 | saver |
More than -$250 but not more than $0 | spender |
-$250 or less | big spender |
You may find this graphic helpful in understanding the boundaries of the various categories:
All monetary values in output should be rounded to two decimal places using a rounding method (as shown in lecture). If the second digit after the decimal point (the "hundredths" digit) is a zero, your program should not print out this zero. (e.g. your program will print $3.5 instead of $3.50) This is acceptable and expected, and you should NOT attempt to fix this. However, you MUST print out two digits if the second digit is not a zero.
As usual, we suggest you approach the program in stages rather than trying to implement everything at once. Specifically, we recommend implementing funcionality in the following order:
This assignment is somewhat more complex than previous ones. The following suggestions and hints may help you be more successful:
int
can be used when a double
is expected,
but to use a double
where you need an int
you will need to
use a cast, such as:double d = 5.678;
int i = (int)d; // i = 5
Cannot find symbol
" errors from the compiler, look carefully at your parameters and return values
and ensure they are all included and named correctly.Like all CSE 142 assessments, this assessment will be graded on all four dimensions defined in the syllabus. Be sure to adhere to the following guidelines:
This program requires you to process user input, which you must do using a Scanner
.
You may assume that all monetary inputs will be real numbers, and that all other input will be integers. You may also
assume the user always enters valid input. Specifically, you may assume that:
public static final
, in that order.
As described above, your program should assume there are 31 days in a month by default, but this
value should be able to be easily changed. You must introduce a class constant for the number of days
in a month, and use this constant throughout your program. See the example logs for sample executions
with alternate values for the constant. The Mark button in Ed will test your program with different
constant values. To ensure our testing and grading scripts work correctly, you must name your constant
DAYS_IN_MONTH
. In addition, please set the value of the constant to
31 before submitting your work.
For all numerical values in your program, you should use the type (int
or
double
) that is more appropriate for the value. In particular, you should NOT
simply use double
for all values. In addition, you must not round values until
they are output; all calculations should be performed using the full values.
For this assessment, you are restricted to Java concepts covered in chapters 1 through 4 of the textbook.
In particular, you MUST use parameters and return values. You are NOT permitted to use the printf
method or arrays on this assessment.
In addition to producing the desired behavior, your code should be well-written and meet all expectations described in the grading guidelines and the Code Quality Guide. For this assessment, pay particular attention to the following elements:
You should attempt to eliminate all redundancy in your program, and your main
method should be a
concise summary of your program's structure. You should not produce any output in your main
method,
though you may have more code in main
than you have on previous assessments. In addition, each
method should perform a single, coherent task. To receive the highest grades, your program must include
at least four (4) non-trivial methods other than main
. (For reference, our solution consists of 86 lines of
code, 58 of which are "substantive", and 7 methods besides main
.)
Your program should utilize parameters and return values effectively to produce a well-structured program
as described above. Your methods should not accept any unnecessary parameters. For this assessment,
a parameter is considered unncessary if its value is unused, is always the same as the value as another
parameter, or can be directly computed from the values of other parameters. In particular, your program
should include only a single Scanner
which is passed as a parameter to all required methods. You should
NOT declare your Scanner
as a constant; you must pass it as a parameter. Your program should also
utilize return values to avoid "chaining" (where each method calls the next without returning to main
).
Your program will need to utilize conditionals (if
statements) at various points to achieve the correct
behavior. You are expected to use the most appropriate form of these statements (if
,
if-else
, and/or if-else if
) for each situation and to factor common
code out of each branch.
Your code should be properly indented, make good use of blank lines and other whitespace, and include
no lines longer than 100 characters. Your class, methods, variables, parameters and constants should all have
meaningful and descriptive names and follow the standard Java naming conventions. (e.g.
ClassName
, methodOrVariableName
,
CONSTANT_NAME
) See the Code Quality Guide for more information.
Your code should include a header comment at the start of your program, following the same format described in previous assessments. Your code should also include a comment at the beginning of each method that describes that methods behavior. Method comments should also explicitly name and describe all parameters to that method and describe the method's return value (if it has one). Comments should be written in your own words (i.e. not copied and pasted from this spec) and should not include implementation details (such as describing loops or expressions included in the code). See the Code Quality Guide for examples and more information.
If you find you are struggling with this assessment, make use of all the course resources that are available to you, such as:
Remember that, while you are encouraged to use all resources at your disposal, including your classmates, all work you submit must be your own. In particular, you should NEVER look at a solution to this assessment from another source (a classmate, a former student, an online repository, etc.). Please review the full policy in the syllabus for more details and ask the course staff if you are unclear on whether or not a resource is OK to use.
In addition to your code, you must submit answers to short reflection questions. These questions will help you think about what you learned, what you struggled with, and how you can improve next time. The questions are given in the "Reflection" slide in the Ed assessment.
Running and Submitting You can run your program by clicking the "Run" button in Ed. This will compile and execute your code and show you any errors, or the output of your program if it runs correctly. If you believe your output is correct, you can submit your work by clicking the "Mark" button in the Ed lesson. You will see the results of some automated tests along with tentative grades. This grade is not final until you have received feedback from your TA.
You may submit your work as often as you like until the deadline; we will always grade your most recent submission. Note the due date and time carefully—work submitted after the due time will not be accepted.