EssaysForStudent.com - Free Essays, Term Papers & Book Notes
Search

Ciss 110 Programming

Page 1 of 3

CISS 110 Programming & Logic I

Fall 2017

Project 1

Due Date: Sunday, November 12, 2017

Write a program called Budget.  Name your file 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 month’s 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.  

Download as (for upgraded members)  txt (4.1 Kb)   pdf (79.3 Kb)   docx (12.1 Kb)  
Continue for 2 more pages »