Vous êtes sur la page 1sur 3

CISS 110 Programming & Logic I

Fall 2017
Project 1
Due Date: Sunday, November 12, 2017

Write a program called Budget. Name your file <yourLastName>Budget.java

This program will use nested loops to calculate whether an individual is over or
under their budget each month. It will read data from an input file and write the
results to an output file.

The outer loop will run as as long as there is more data in the file. This outer loop
should be a while loop and use the Scanner method hasNext() to determine
whether it should continue. Within the outer loop, acquire the month and the total
budgeted for the month.

The month will be the first line of each data set contained in the input file and it
should be read and stored in a String variable.

The amount budgeted for the month will be the second line of each data set and it
should be read and stored in a double variable.

Then, an inner loop will iterate six times, one per budget category. The six
categories are: food, rent, utilities, clothing, entertainment, personal care. The file
will contain the amount spent for each category, one amount per line. The program
will keep track of the total amount spent. This running total will be stored in an
accumulator variable. This variable will have to be initialized to zero outside the
inner loop but inside the outer loop. The inner loop will be a for loop that will
iterate six times, from 0 to 5. When the for loop has completed execution, the
accumulator variable will contain the total expenses.

After the inner loop completes, write the specified output to the output file: the
month, the amount budgeted and the total amount spent (accumulated in the for
loop) for the month. Then, calculate whether the user went over or under the
budget for that month and write this data to the file.

The input file, the file you will read from, is called budgetInput.txt. Hard code the
name of this input file in your program. The File and Scanner classes can be used
to read from the file. You can assume this file exists. A sample file has been
provided to you, but it will not be the file used to grade your project.
The input file will have the following format:

Month (String)
Total Budgeted for month (double)
Food expense (double)
Rent expense (double)
Utilities expense (double)
Clothing expense (double)
Entertainment expense (double)
Personal care expense (double)

Example of one months data:

January
500
100
200
200
10
50
40

These eight lines will repeat for however many months the user has chosen to
create. The first line is the month, January. The second line contains the total
budgeted for January, and the six lines of numbers represent the expense for each of
the categories.

The summary will be written to a file called <yourName>budgetOutput.txt. Hard


code the name of this output file in your program. You can use the PrintWriter
class to write to the output file.

The output file will have the following format:

Total budgeted for <month>: $<amount>


Total spent for <month>: $<amount>
You went (over/under) your budget for <month> by $<amount>

These lines will be repeated for each months data contained in the input file. Add
newlines to separate the months from each other.

Example of one months summarized data in the output file:

Total budgeted for January: $500


Total spent for January: $600
You went over your budget for January by $100
Notes:
Your code must attempt to solve the stated problem, compile and run
without runtime errors.
Because each item of data is one token (including the String, month), you can
use next() and nextDouble() to acquire the data.
The user will not enter any values and there will be nothing displayed to
standard output.
Submit only work you have created. Do not share code or files with
classmates. Do not submit work you have found on the Internet. This will
result in a grade of 0 for the project.
This project is NOT to be done during classtime.
No late submissions will be accepted.

Vous aimerez peut-être aussi