I am struggling with Java. Please help. I was not sure what was wrong. Tried to
ID: 3881743 • Letter: I
Question
I am struggling with Java. Please help. I was not sure what was wrong. Tried to execute and there was the error at line 310.
This is the output.
MyBills class
package Client.Services.Classes; //Package
import Client.Services.BillsType;
public class MyBills {
private String monthExpenses;
private BillsType expenseType;
private double []expenseAmount;
private int numberDays;
private static int idCounter = 0;
private int id;
public MyBills() {
this.setMonthExpenses("any month");
this.setExpenseType(null);
this.setExpenseAmount(null);
this.setNumberofDays(0);
this.setID();
}
public MyBills (String monthExpenses, BillsType expenseType, double []expenseAmount, int numberDays) {
this.setMonthExpenses(monthExpenses);
this.setExpenseType(expenseType);
this.setExpenseAmount(expenseAmount);
this.setNumberofDays(numberDays);
this.setID();
}
public String getMonthExpenses() {
return this.monthExpenses;
}
public BillsType getExpenseType() {
return this.expenseType;
}
public double[] getExpenseAmount() {
return this.expenseAmount;
}
public int getNumberofDays() {
return this.numberDays;
}
public int getID() {
return this.id;
}
public void setMonthExpenses (String monthExpenses) {
this.monthExpenses = monthExpenses;
}
public void setExpenseType (BillsType expenseType) {
this.expenseType = expenseType;
}
public void setExpenseAmount (double[] expenseAmount) {
this.expenseAmount = expenseAmount;
}
public void setNumberofDays (int numberDays) {
this.numberDays = numberDays;
}
public void setID() {
this.id = ++idCounter;
}
public String toString() {
String expenses = "";
int i = 0;
while (i < this.getExpenseAmount().length) {
expenses = expenses + " " + this.getExpenseAmount()[i];
++i;
}
String str = " The month is: " + this.getMonthExpenses() + " The type of expenses is: "
+ this.getExpenseType() + " The amounts are: " + expenses + " The number of days is: "
+ this.getNumberofDays() + " The expense object ID is: " + this.id
+ " And the static ID value is: " + this.idCounter;
return str;
}
public boolean equals (MyBills bills) {
if ((bills.getExpenseType() == this.getExpenseType())
&& (bills.getNumberofDays() == this.getNumberofDays()))
return true;
else
return false;
}
}
BillsType Class
MyBillsClient Class
package Client;
import Client.Services.BillsType;
import Client.Services.Classes.MyBills;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.StringTokenizer;
class MyBillsClient {
public String[] totalExpensesPerMonth (MyBills[] bills) {
String[] totalperMonth = null;
MyBills[] newbills = new MyBills[bills.length];
NumberFormat n = NumberFormat.getCurrencyInstance();
double sum = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0, sum7 = 0, sum8 = 0, sum9 = 0, sum1a = 0, sum1b = 0, sum1c = 0;
int cnt = 0; int x = 0;
for (int m = 0; m < bills.length; ++m) {
newbills[m] = bills[m];
}
for (int i = 0; i < newbills.length-1; i++) {
String month = newbills[i].getMonthExpenses();
/* EQUAL METHODS */
if (month.equals ("JANUARY")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum1 = sum1 + sum;
sum = 0;
if (cnt == 0) {
cnt++;
}
}
else if (month.equals("FEBRUARY")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum2 = sum2 + sum;
sum = 0;
if (cnt == 1) {
cnt++;
}
}
else if (month.equals("MARCH")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum3 = sum3 + sum;
sum = 0;
if (cnt == 2) {
cnt++;
}
}
else if (month.equals("APRIL")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum4 = sum4 + sum;
sum = 0;
if (cnt == 3) {
cnt++;
}
}
else if (month.equals("MAY")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum5 = sum5 + sum;
sum = 0;
if (cnt == 4) {
cnt++;
}
}
else if (month.equals("JUNE")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum6 = sum6 + sum;
sum = 0;
if (cnt == 5) {
cnt++;
}
}
else if (month.equals("JULY")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum7 = sum7 + sum;
sum = 0;
if (cnt == 6) {
cnt++;
}
}
else if (month.equals("AUGUST")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum8 = sum8 + sum;
sum = 0;
if (cnt == 7) {
cnt++;
}
}
else if (month.equals("SEPTEMBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum9 = sum9 + sum;
sum = 0;
if (cnt == 8) {
cnt++;
}
}
else if (month.equals("OCTOBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum1a = sum1a + sum;
sum = 0;
if (cnt == 9) {
cnt++;
}
}
else if (month.equals("NOVEMBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum1b = sum1b + sum;
sum = 0;
if (cnt == 10) {
cnt++;
}
}
else if (month.equals("DECEMBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum1c = sum1c + sum;
sum = 0;
if (cnt == 11) {
cnt++;
}
}
else if (month.equals("SEPTEMBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length-1; x++) {
sum = sum + amount[x];
}
sum9 = sum9 + sum;
sum = 0;
if (cnt == 8) {
cnt++;
}
}
} // END OF WHILE LOOP
totalperMonth = new String [cnt];
for (int y = 0; y < totalperMonth.length; y++) {
if (y == 0) {
String av1 = n.format(sum1);
String str1 = "The total of all the expenses for the month of January is: " + av1;
totalperMonth[0] = str1;
}
else if (y == 1) {
String av2 = n.format(sum2);
String str2 = "The total of all the expenses for the month of February is: " + av2;
totalperMonth[1] = str2;
}
else if (y == 2) {
String av3 = n.format(sum3);
String str3 = "The total of all the expenses for the month of March is: " + av3;
totalperMonth[2] = str3;
}
else if (y == 3) {
String av4 = n.format(sum4);
String str4 = "The total of all the expenses for the month of April is: " + av4;
totalperMonth[3] = str4;
}
else if (y == 4) {
String av5 = n.format(sum5);
String str4 = "The total of all the expenses for the month of May is: " + av5;
totalperMonth[4] = str4;
}
else if (y == 5) {
String av6 = n.format(sum6);
String str4 = "The total of all the expenses for the month of June is: " + av6;
totalperMonth[5] = str4;
}
else if (y == 6) {
String av7 = n.format(sum7);
String str4 = "The total of all the expenses for the month of July is: " + av7;
totalperMonth[6] = str4;
}
else if (y == 7) {
String av8 = n.format(sum8);
String str4 = "The total of all the expenses for the month of August is: " + av8;
totalperMonth[7] = str4;
}
else if (y == 8) {
String av9 = n.format(sum9);
String str4 = "The total of all the expenses for the month of September is: " + av9;
totalperMonth[8] = str4;
}
else if (y == 9) {
String av10 = n.format(sum1a);
String str4 = "The total of all the expenses for the month of October is: " + av10;
totalperMonth[9] = str4;
}
else if (y == 10) {
String av11 = n.format(sum1b);
String str4 = "The total of all the expenses for the month of November is: " + av11;
totalperMonth[10] = str4;
}
else if (y == 11) {
String av12 = n.format(sum1c);
String str4 = "The total of all the expenses for the month of December is: " + av12;
totalperMonth[11] = str4;
}
}
return totalperMonth;
}
public static void main (String [] args) {
/* FIND THE NUMBER OF LINE IN THE .TXT FILE */
/* SCOPE OF VARIABLES */
MyBills []bills = null;
String l;
String month = " ";
String numline = " ";
String []tokens;
BillsType type = null;
double []expenseAmount = null;
int count = 0; int days = 0; int index = 0;
int oai = -1;
/* READ DATA FROM A FILE */
try {
File myFile = new File ("myexpenses.txt");
Scanner sc = new Scanner (myFile);
while (sc.hasNextLine()) {
l = sc.nextLine();
StringTokenizer stk = new StringTokenizer (l, ":");
if (stk.nextToken().equals("MONTH")) {
count++;
}
}
bills = new MyBills[count];
Scanner scan = new Scanner (myFile);
while (scan.hasNextLine()) {
String line = scan.nextLine();
if (line.charAt(0) == 'M') {
// GET MONTH NAME AND EXPENSE TYPE
StringTokenizer stk1 = new StringTokenizer (line, ":");
stk1.nextToken();
month = stk1.nextToken();
type = BillsType.valueOf(stk1.nextToken());
oai++;
}
else {
StringTokenizer stk2 = new StringTokenizer (line, ":");
days = stk2.countTokens();
expenseAmount = new double[days];
index = 0;
while (stk2.hasMoreTokens()) {
expenseAmount[index] = Double.parseDouble(stk2.nextToken());
index++;
}
MyBills a = new MyBills (month, type, expenseAmount, days);
bills[oai] = a;
} // END OF WHILE LOOP
}
} // END OF TRY
/* DISPLAY THE OBJECT */
catch (IOException ioe) {
System.out.println ("The file can not be read.");
System.out.println ("The number of strings tokens read is: " + count);
}
System.out.println ("________Output # 1________");
for (int g = 0; g <= bills.length-1; g++) {
System.out.println(bills[g]);
}
System.out.println ("________Output # 2________");
MyBillsClient client = new MyBillsClient();
String []output = client.totalExpensesPerMonth(bills);
for (int j = 0; j <= output.length-1; ++j) {
System.out.println (output[j]);
}
}
}
MONTH: JANUARY: ExpenseType: School 45 . 34, 56. 76, 23. 67, 89·00, 67·00, 46 . 34, 100 . 50, 12. 23, 12. 4, 56. 78, 23. 45, 78·00 MONTH: JANUARY: ExpenseType: Restaurant 34.23,12.56,2.57,45.00, 67.00,1.34, 34.89,56.00, 65.00,27.46,3.23,6.78,7.80 MONTH: JANUARY: ExpenseType:Clothing 45·00, 25·00, 34. 67, 14. 23, 34. 56, 36·00, 56. 85, 16·00, 15·00, 30. 23, 4 , 34, 123. 78 MONTH: JANUARY: ExpenseType:0ther 34·00, 78·00, 100 . 30, 120. 23, 167, 56, 5 . 96, 1·23, 23 . 45, 69 . 78, 100·00, 90. 23, 105·00, 200 . 0,126.68 MONTH: FEBRUARY:ExpenseType: School 55. 34, 26. 76, 53. 97, 59. 80, 67·00, 46 . 34, 140 . 45, 18 . 23, 2·4, 56. 78, 53. 45, 98. 24 MONTH: FEBRUARY: ExpenseType Restaurant 14.23,19.50,22.50,45.89, 67.20,1.54,39.89,56.38,45.00,37.46,13.23,8.78,9.82 MONTH: FEBRUARY: ExpenseType: Clothing 55·00, 25·39, 34. 67, 14 . 23, 34 . 56, 86·00, 26 , 85, 16·50, 15. 33, 38. 29 MONTH: FEBRUARY : ExpenseType:0ther 4·00, 28. 30, 120. 36, 160·00, 107 . 56, 28·98, 11. 23, 24 . 45, 89 . 78, 50. 00, 9 . 33, 12510, 100·00 ,128.68, 50.45 MONTH: MARCH: ExpenseTYPE: School 15.24,6.16, 23.81,89.00,67.50, 26.34,10.50,12.25, 18.45, 6.28, 29.00, 28.00 MONTH:MARCH: ExpenseType Restaurant 34.23,12.06,6.10,23.00,7.20,1.44, 24.00,16.87,95.00, 29.46,18.23,10.78,10.80,2.47, 12.45 MONTH: MARCH: ExpenseType:Clothing 13·00, 15·00, 24. 87, 14. 23, 34·50, 16 . 80, 16. 95, 39·00, 15. 83, 38 . 23, 92 . 34 MONTH: APRIL: ExpenseType: School 19.24,6.16, 23.81,89.00,67.50, 26.34,10.50, 12.25,18.45, 6.28,29.00,28.00,45.67,2.54 MONTH:APRIL:ExpenseType:Other 9·00, 70. 80, 70. 36, 30. 13, 107 . 56, 125. 95, 10. 43, 8 . 45, 59. 78, 40. 50, 10. 23, 18500, 120·00, 296.68,3.45Explanation / Answer
Correction is made in MyBillsClient.java in main method stk1.nextToken(); is added before type is assigned to nextToken as next token contains ExpenseType string.
in else condition StringTokenizer stk2 = new StringTokenizer(line, ","); "," is used instead of ":" as amounts are seperated by ",".
MyBillsClient.java
package Client;
import Client.Services.BillsType;
import Client.Services.Classes.MyBills;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.StringTokenizer;
class MyBillsClient {
public String[] totalExpensesPerMonth(MyBills[] bills) {
String[] totalperMonth = null;
MyBills[] newbills = new MyBills[bills.length];
NumberFormat n = NumberFormat.getCurrencyInstance();
double sum = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0, sum7 = 0, sum8 = 0, sum9 = 0,
sum1a = 0, sum1b = 0, sum1c = 0;
int cnt = 0;
int x = 0;
for (int m = 0; m < bills.length; ++m) {
newbills[m] = bills[m];
}
for (int i = 0; i < newbills.length - 1; i++) {
String month = newbills[i].getMonthExpenses();
/* EQUAL METHODS */
if (month.equals("JANUARY")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum1 = sum1 + sum;
sum = 0;
if (cnt == 0) {
cnt++;
}
}
else if (month.equals("FEBRUARY")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum2 = sum2 + sum;
sum = 0;
if (cnt == 1) {
cnt++;
}
}
else if (month.equals("MARCH")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum3 = sum3 + sum;
sum = 0;
if (cnt == 2) {
cnt++;
}
}
else if (month.equals("APRIL")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum4 = sum4 + sum;
sum = 0;
if (cnt == 3) {
cnt++;
}
}
else if (month.equals("MAY")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum5 = sum5 + sum;
sum = 0;
if (cnt == 4) {
cnt++;
}
}
else if (month.equals("JUNE")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum6 = sum6 + sum;
sum = 0;
if (cnt == 5) {
cnt++;
}
}
else if (month.equals("JULY")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum7 = sum7 + sum;
sum = 0;
if (cnt == 6) {
cnt++;
}
}
else if (month.equals("AUGUST")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum8 = sum8 + sum;
sum = 0;
if (cnt == 7) {
cnt++;
}
}
else if (month.equals("SEPTEMBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum9 = sum9 + sum;
sum = 0;
if (cnt == 8) {
cnt++;
}
}
else if (month.equals("OCTOBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum1a = sum1a + sum;
sum = 0;
if (cnt == 9) {
cnt++;
}
}
else if (month.equals("NOVEMBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum1b = sum1b + sum;
sum = 0;
if (cnt == 10) {
cnt++;
}
}
else if (month.equals("DECEMBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum1c = sum1c + sum;
sum = 0;
if (cnt == 11) {
cnt++;
}
}
else if (month.equals("SEPTEMBER")) {
double[] amount = bills[i].getExpenseAmount();
for (x = 0; x <= amount.length - 1; x++) {
sum = sum + amount[x];
}
sum9 = sum9 + sum;
sum = 0;
if (cnt == 8) {
cnt++;
}
}
} // END OF WHILE LOOP
totalperMonth = new String[cnt];
for (int y = 0; y < totalperMonth.length; y++) {
if (y == 0) {
String av1 = n.format(sum1);
String str1 = "The total of all the expenses for the month of January is: " + av1;
totalperMonth[0] = str1;
}
else if (y == 1) {
String av2 = n.format(sum2);
String str2 = "The total of all the expenses for the month of February is: " + av2;
totalperMonth[1] = str2;
}
else if (y == 2) {
String av3 = n.format(sum3);
String str3 = "The total of all the expenses for the month of March is: " + av3;
totalperMonth[2] = str3;
}
else if (y == 3) {
String av4 = n.format(sum4);
String str4 = "The total of all the expenses for the month of April is: " + av4;
totalperMonth[3] = str4;
}
else if (y == 4) {
String av5 = n.format(sum5);
String str4 = "The total of all the expenses for the month of May is: " + av5;
totalperMonth[4] = str4;
}
else if (y == 5) {
String av6 = n.format(sum6);
String str4 = "The total of all the expenses for the month of June is: " + av6;
totalperMonth[5] = str4;
}
else if (y == 6) {
String av7 = n.format(sum7);
String str4 = "The total of all the expenses for the month of July is: " + av7;
totalperMonth[6] = str4;
}
else if (y == 7) {
String av8 = n.format(sum8);
String str4 = "The total of all the expenses for the month of August is: " + av8;
totalperMonth[7] = str4;
}
else if (y == 8) {
String av9 = n.format(sum9);
String str4 = "The total of all the expenses for the month of September is: " + av9;
totalperMonth[8] = str4;
}
else if (y == 9) {
String av10 = n.format(sum1a);
String str4 = "The total of all the expenses for the month of October is: " + av10;
totalperMonth[9] = str4;
}
else if (y == 10) {
String av11 = n.format(sum1b);
String str4 = "The total of all the expenses for the month of November is: " + av11;
totalperMonth[10] = str4;
}
else if (y == 11) {
String av12 = n.format(sum1c);
String str4 = "The total of all the expenses for the month of December is: " + av12;
totalperMonth[11] = str4;
}
}
return totalperMonth;
}
public static void main(String[] args) {
/* FIND THE NUMBER OF LINE IN THE .TXT FILE */
/* SCOPE OF VARIABLES */
MyBills[] bills = null;
String l;
String month = " ";
String numline = " ";
String[] tokens;
BillsType type = null;
double[] expenseAmount = null;
int count = 0;
int days = 0;
int index = 0;
int oai = -1;
/* READ DATA FROM A FILE */
try {
File myFile = new File("D:/workspace/Test/src/Client/Services/myexpenses.txt");
Scanner sc = new Scanner(myFile);
while (sc.hasNextLine()) {
l = sc.nextLine();
StringTokenizer stk = new StringTokenizer(l, ":");
if (stk.nextToken().equals("MONTH")) {
count++;
}
}
bills = new MyBills[count];
Scanner scan = new Scanner(myFile);
while (scan.hasNextLine()) {
String line = scan.nextLine();
if (line.charAt(0) == 'M') {
// GET MONTH NAME AND EXPENSE TYPE
StringTokenizer stk1 = new StringTokenizer(line, ":");
stk1.nextToken();
month = stk1.nextToken();
stk1.nextToken();
type = BillsType.valueOf(stk1.nextToken());
oai++;
}
else {
StringTokenizer stk2 = new StringTokenizer(line, ",");
days = stk2.countTokens();
expenseAmount = new double[days];
index = 0;
while (stk2.hasMoreTokens()) {
expenseAmount[index] = Double.parseDouble(stk2.nextToken());
index++;
}
MyBills a = new MyBills(month, type, expenseAmount, days);
bills[oai] = a;
} // END OF WHILE LOOP
}
} // END OF TRY
/* DISPLAY THE OBJECT */
catch (IOException ioe) {
System.out.println("The file can not be read.");
System.out.println("The number of strings tokens read is: " + count);
}
System.out.println("________Output # 1________");
for (int g = 0; g <= bills.length - 1; g++) {
System.out.println(bills[g]);
}
System.out.println("________Output # 2________");
MyBillsClient client = new MyBillsClient();
String[] output = client.totalExpensesPerMonth(bills);
for (int j = 0; j <= output.length - 1; ++j) {
System.out.println(output[j]);
}
}
}
BillsType.java
package Client.Services;
public enum BillsType {
School, Restaurant, Clothing, Other
};
MyBills.java
package Client.Services.Classes;
import Client.Services.BillsType;
public class MyBills {
private String monthExpenses;
private BillsType expenseType;
private double[] expenseAmount;
private int numberDays;
private static int idCounter = 0;
private int id;
public MyBills() {
this.setMonthExpenses("any month");
this.setExpenseType(null);
this.setExpenseAmount(null);
this.setNumberofDays(0);
this.setID();
}
public MyBills(String monthExpenses, BillsType expenseType, double[] expenseAmount, int numberDays) {
this.setMonthExpenses(monthExpenses);
this.setExpenseType(expenseType);
this.setExpenseAmount(expenseAmount);
this.setNumberofDays(numberDays);
this.setID();
}
public String getMonthExpenses() {
return this.monthExpenses;
}
public BillsType getExpenseType() {
return this.expenseType;
}
public double[] getExpenseAmount() {
return this.expenseAmount;
}
public int getNumberofDays() {
return this.numberDays;
}
public int getID() {
return this.id;
}
public void setMonthExpenses(String monthExpenses) {
this.monthExpenses = monthExpenses;
}
public void setExpenseType(BillsType expenseType) {
this.expenseType = expenseType;
}
public void setExpenseAmount(double[] expenseAmount) {
this.expenseAmount = expenseAmount;
}
public void setNumberofDays(int numberDays) {
this.numberDays = numberDays;
}
public void setID() {
this.id = ++idCounter;
}
public String toString() {
String expenses = "";
int i = 0;
while (i < this.getExpenseAmount().length) {
expenses = expenses + " " + this.getExpenseAmount()[i];
++i;
}
String str = " The month is: " + this.getMonthExpenses() + " The type of expenses is: "
+ this.getExpenseType() + " The amounts are: " + expenses + " The number of days is: "
+ this.getNumberofDays() + " The expense object ID is: " + this.id
+ " And the static ID value is: " + this.idCounter;
return str;
}
public boolean equals(MyBills bills) {
if ((bills.getExpenseType() == this.getExpenseType())
&& (bills.getNumberofDays() == this.getNumberofDays()))
return true;
else
return false;
}
}
myexpenses.txt
MONTH:JANUARY: ExpenseType:School
45.34,56.76,23.67,89.00,67.00,46.34,100.50,12.23,12.4,56.78,23.45,78.00
MONTH:JANUARY:ExpenseType:Restaurant
34.23,12.56,2.57,45.00,67.00,1.34,34.89,56.00,65.00,27.46,3.23,6.78,7.80
MONTH:JANUARY:ExpenseType:Clothing
45.00,25.00,34.67,14.23,34.56,36.00,56.85,16.00,15.00,30.23,4.34,123.78
MONTH:JANUARY:ExpenseType:Other
34.00,78.00,100.30,120.23,167.56,5.90,1.23,23.45,69.78,100.00,90.23,105.00,200.00,126.68
MONTH:FEBRUARY:ExpenseType:School
55.34,26.76,53.97,59.80,67.00,46.34,140.45,18.23,2.4,56.78,53.45,98.24
MONTH:FEBRUARY:ExpenseType:Restaurant
14.23,19.50,22.50,45.89,67.20,1.54,39.89,56.38,45.00,37.46,13.23,8.78,9.82
MONTH:FEBRUARY:ExpenseType:Clothing
55.00,25.30,34.67,14.23,34.56,86.00,26.85,16.50,15.33,38.29
MONTH:FEBRUARY:ExpenseType:Other
4.00,28.30,120.30,160.00,107.56,28.90,11.23,24.45,89.78,50.00,9.33,125.10,100.00,128.68,50.45
sample output:
________Output # 1________
The month is: JANUARY The type of expenses is: School The amounts are: 45.34 56.76 23.67 89.0 67.0 46.34 100.5 12.23 12.4 56.78 23.45 78.0 The number of days is: 12 The expense object ID is: 1 And the static ID value is: 8
The month is: JANUARY The type of expenses is: Restaurant The amounts are: 34.23 12.56 2.57 45.0 67.0 1.34 34.89 56.0 65.0 27.46 3.23 6.78 7.8 The number of days is: 13 The expense object ID is: 2 And the static ID value is: 8
The month is: JANUARY The type of expenses is: Clothing The amounts are: 45.0 25.0 34.67 14.23 34.56 36.0 56.85 16.0 15.0 30.23 4.34 123.78 The number of days is: 12 The expense object ID is: 3 And the static ID value is: 8
The month is: JANUARY The type of expenses is: Other The amounts are: 34.0 78.0 100.3 120.23 167.56 5.9 1.23 23.45 69.78 100.0 90.23 105.0 200.0 126.68 The number of days is: 14 The expense object ID is: 4 And the static ID value is: 8
The month is: FEBRUARY The type of expenses is: School The amounts are: 55.34 26.76 53.97 59.8 67.0 46.34 140.45 18.23 2.4 56.78 53.45 98.24 The number of days is: 12 The expense object ID is: 5 And the static ID value is: 8
The month is: FEBRUARY The type of expenses is: Restaurant The amounts are: 14.23 19.5 22.5 45.89 67.2 1.54 39.89 56.38 45.0 37.46 13.23 8.78 9.82 The number of days is: 13 The expense object ID is: 6 And the static ID value is: 8
The month is: FEBRUARY The type of expenses is: Clothing The amounts are: 55.0 25.3 34.67 14.23 34.56 86.0 26.85 16.5 15.33 38.29 The number of days is: 10 The expense object ID is: 7 And the static ID value is: 8
The month is: FEBRUARY The type of expenses is: Other The amounts are: 4.0 28.3 120.3 160.0 107.56 28.9 11.23 24.45 89.78 50.0 9.33 125.1 100.0 128.68 50.45 The number of days is: 15 The expense object ID is: 8 And the static ID value is: 8
________Output # 2________
The total of all the expenses for the month of January is: $2,633.35
The total of all the expenses for the month of February is: $1,406.91
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.