I'm new here and pretty new to java. I've been reading some text books on the subject and am excited to be learning this language! So far I've been keeping it pretty simple just using the System.out.println() method for output and so forth. I read one of the project idea posts for something to challenge me and what I've learned so far. I decided to start a Budget program. I've tried implementing an array for the expenses and tested making my own custom method. I would appreciate if any one will take a look at the start of my code and offer any suggestions, things you would do differently. Particularly the getExspenses method, am I getting the values I need correctly? Do I actually have to make it return a value since I am getting values for variables? It's not much so far but its a start! Any and all help is greatly appreciated!
Reppard
import javax.swing.*;
public class Budget {
static double income = 0;
static double billsTotal = 0;
static double bills[];
public static void main(String args[]){
bills = new double [6];
bills[0] = 0;//rent
bills[1] = 0;//electric
bills[2] = 0;//water
bills[3] = 0;//food
bills[4] = 0;//gas
bills[5] = 0;//baby
getExpenses(bills[0], bills[1], bills[2]);
JOptionPane.showMessageDialog(null, "*****Expenses and Budget*****\n\n" +
"Rent: " + bills[0] + "\n" +
"Electric: " + bills[1] + "\n" +
"Water: " + bills[2] + "\n\n" +
"Total Exspenses: " + billsTotal);
}//end of main method
public static double getExpenses(double rent, double elec, double water){
bills[0] = rent = Integer.parseInt(JOptionPane.showInputDialog("Enter rent ammount"));
bills[1] = elec = Integer.parseInt(JOptionPane.showInputDialog("Enter electric ammount"));
bills[2] = water = Integer.parseInt(JOptionPane.showInputDialog("Enter water ammount"));
billsTotal = bills[0]+bills[1]+bills[2];
return elec;
}
}//end of budget class

New Topic/Question
Reply



MultiQuote





|