Im having trouble with this assignment I do not seem to understand how to send a copy of the print out of my Budget() my teacher also wants us to use the split on "\t" for example s.split("\t")....im not sure how this works as well. Any help at all with this assignment would be greatly appreciated. Here is the assignment below as well as what I have so far.
You will be adding methods to the Budget class you created in Assignment 4. First of all, you will add two new data fields. One will contain the year when these expenses are incurred. This allows us to maintain annual objects for archival (and perhaps tax) purposes. The other field will be the name of the person incurring the expenses. Add necessary accessor and modifier methods.
Create an accessor method called getTotal. It will return the current year’s total expenses for a particular category. The category will be passed as a parameter.
Create a method called load. This method receives the path and name of a file as input. The referenced file will contain expense data. The first line of the file will be the year in which the expenses occurred. The remaining lines have the following format: Month Category Amount. A sample line might be this:
February Food $ 21.89
Create a method to send a copy of the budget report to a file named Personal Expenses yyyy.txt, where yyyy is the four-digit year that these expenses are for. The file will contain output that looks much like that created in Assignment 4, showing the current date, the total expenses in each category, and the total annual expenses. A sample is shown below:
Expenses as of Nov 4, 2011:
Tuition: $3200
Food: $2600
Clothes: $600
Books: $450
Total expenses: $6850
Code:import java.io.*;
public class Budget
{
//////////////////////////////////////////////FIELDS////////////////////////////////////////////////
private int[] food;
private int[] clothes;
private int[] gas;
private int[] tuition;
private int[] cable;
private int[] books;
private String[] month;
private int numFood;
private int numClothes;
private int numGas;
private int numTuition;
private int numCable;
private int numBooks;
private int numMonth;
private String totalExpense;
//////Fields for assignment 5////////
private String yearOfExpense;
private String namePerson;
private int total;
////////////////////////////////////////////CONSTRUCTORS/////////////////////////////////////////////
public Budget()
{
food = new int[12];
clothes = new int[12];
gas = new int[12];
tuition = new int[12];
cable = new int[12];
books = new int[12];
month = new String[12];
numFood = 0;
numClothes = 0;
numGas = 0;
numTuition = 0;
numCable = 0;
numBooks = 0;
numMonth = 1;
}
///////////////////////////////////////////////////METHODS////////////////////////////////////////////
/////////////accessors and modifiers
public String getYearOfExpense() {return yearOfExpense;}
public void setYearOfExpense(String yearOfExpense)
{
this.yearOfExpense = yearOfExpense;
}
public String getNamePerson() {return namePerson;}
public void setNamePerson(String namePerson)
{
this.namePerson = namePerson;
}
public int getTotal()
{
return total;
}
///////////////////recieves path and name of file as input////////////////////
public void load(String fileName)
{
String line = null;
try{
BufferedReader reader = new BufferedReader(new FileReader(fileName));
while((line = reader.readLine()) !=null)
{
System.out.println(line);
}
reader.close();
}
catch(FileNotFoundException ex)
{
line = "Could not fine " + fileName;
line = line + ". Please select one:";
SimpleOutput.showError(line);
fileName = FileChooser.pickAFile();
load(fileName);
}
catch(Exception ex){
SimpleOutput.showError("Error reading file " + fileName);
ex.printStackTrace();
}
}
///////////Method to send copy/////////
public void sendACopy()
{
Budget k = new Budget();
k.addFood(500);
k.addClothes(750);
k.addGas(670);
k.addTuition(430);
k.setMonth(3);
}
////////////////adds expense to food//////////////
public boolean addFood(int foodExpense)
{
if( numFood < 12)
{
numFood = numFood + 1;
food[numFood] = foodExpense;
foodExpense = total;
return true;
}
else
{
return false;
}
}
/////////////adds expense to clothes////////////
public boolean addClothes(int clothesExpense)
{
if( numClothes < 12)
{
numClothes = numClothes + 1;
clothes[numClothes] = clothesExpense;
clothesExpense = total;
return true;
}
else
{
return false;
}
}
////////////adds expense to gas////////////
public boolean addGas(int gasExpense)
{
if( numGas < 12)
{
numGas = numGas + 1;
gas[numGas] = gasExpense;
gasExpense = total;
return true;
}
else
{
return false;
}
}
//////////////adds expense to tuition///////////////
public boolean addTuition(int tuitionExpense)
{
if( numTuition < 12)
{
numTuition = numTuition + 1;
tuition[numTuition] = tuitionExpense;
tuitionExpense = total;
return true;
}
else
{
return false;
}
}
///////////////adds expense to cable/////////////
public boolean addCable(int cableExpense)
{
if(numCable < 12)
{
numCable = numCable + 1;
cable[numCable] = cableExpense;
cableExpense = total;
return true;
}
else
{
return false;
}
}
/////////////////adds expense to books//////////////////////
public boolean addBooks(int booksExpense)
{
if(numBooks < 12)
{
numBooks = numBooks + 1;
books[numBooks] = booksExpense;
booksExpense = total;
return true;
}
else
{
return false;
}
}
///////////sets month for expenses//////////////
public void setMonth(int monthinput)
{
month[0] = "Janurary";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
}
///////////////////////////////////REPORT//////////////////////////////
public String toString(String totalExpense)
{
//////////////////////////////////////////////////////Prints Total Food Expense////////////////////////
String totalFood = "Food: $";
for(int f = 0; f < numFood; f++)
{
totalFood = totalFood + food[f+1];
}
System.out.println(totalFood);
//////////////////////////////////////prints Total Clothes Expense////////////////////////////////
String totalClothes = "clothes: $";
for(int e = 0; e < numClothes; e++)
{
totalClothes = totalClothes + clothes[e+1];
}
System.out.println(totalClothes);
//////////////////////////////////////prints Total Gas Expense///////////////////////////////////////
String totalGas = "Gas: $";
for(int g = 0; g < numGas; g++)
{
totalGas = totalGas + gas[g+1];
}
System.out.println(totalGas);
///////////////////////////////////////prints Total Tuition Expense///////////////////////////////
String totalTuition = "Tuition: $";
for(int t = 0; t < numTuition; t++)
{
totalTuition = totalTuition + tuition[t+1];
}
System.out.println(totalTuition);
///////////////////////////////////prints Total Cable Expense/////////////////////////////
String totalCable = "Cable: $";
for(int c = 0; c < numCable; c++)
{
totalCable = totalCable + cable[c+1];
}
System.out.println(totalCable);
/////////////////////////////////prints Total books expense///////////////////////////////////////
String totalBooks = "Books: $";
for(int b = 0; b < numBooks; b++)
{
totalBooks = totalBooks + (books[b+1]);
}
System.out.println(totalBooks);
/////////////////Prints out total expenses per year according to month/////////////////////
for( int i = 0; i < month.length; i++)
{
System.out.println( "Total expenses as of " + month[i]);
for(int y = 0; y < numMonth; y++)
{
totalExpense = totalExpense + (food[y+1] + cable[y+1] + gas[y+1] + tuition[y+1] + books[y+1] + clothes[y+1]);
}}
return totalExpense;
}
public void output()
{
System.out.println(totalExpense);
}
}

