0
import java.text.DecimalFormat;
import java.util.Scanner;
public class Expenditure2
{
    static Scanner input = new Scanner(System.in).useDelimiter("\r\n"); 
    static DecimalFormat fmt= new DecimalFormat("0.00");
public static void main(String[]args) throws Exception
  {
     String[] item= new String[10];
     double[] amount= new double[10]; 
     String[] month = {"null", "Jan", "Feb","March", "April",  "May" ,"June" ,"July" ,"Aug" ,"Sept" ,"Oct" ,"Nov","Dec"  } ; 
        System.out.println("1) Enter expenses ");
System.out.println("2) Display expenses by month ");
System.out.println("3) Quick glance at monthly expenses");
System.out.println("4) Exit ");
System.out.print("Please select your choice <1-3>:  ");
choice = input.nextInt();
    double total;
     int choice,x,y,loop;
    case 1:   
             System.out.print("Enter month <1-12> : ");
         y = input.nextInt(); 
         //end of month 
                     for ( x=1; x<=item.length;x++)
                     {
                    System.out.print("Enter item "+x+" <Press ENTER to exit>: ");
                    item[x] = input.next();          
                    if (item[x].equals(""))
                    {
                        System.out.print("\n\n");
                        break;
                    }
                    System.out.print("Enter amount: $");
                    amount[x] = input.nextDouble();
                    System.out.print("\n");
                     }
                   break;
    case 2    : 
        //month
        System.out.print(" Enter month <1 for Jan - 12 for Dec> :");
        y= input.nextInt();
        System.out.println(""+month[y]+" expenditures <max 10 items> :");
       //end of month 
   System.out.println(item[1]+"\t\t"+amount[1]);
   System.out.println(item[2]+"\t\t"+amount[2]);
   System.out.println(item[3]+"\t\t"+amount[3]);
   System.out.println(item[4]+"\t\t"+amount[4]);
   System.out.println(item[5]+"\t\t"+amount[5]);
   System.out.println(item[6]+"\t\t"+amount[6]);
   System.out.println(item[7]+"\t\t"+amount[7]);
   System.out.println(item[8]+"\t\t"+amount[8]);
   System.out.println(item[9]+"\t\t"+amount[9]);
             //total amount
       total= amount[1]+amount[2]+amount[3]+amount[4]+amount[5]+amount[6]+amount[7]+amount[8]+amount[9]+amount[10];
       System.out.println("Total spendings for "+month[m]+"is\t\t"+total);
  break;

Hi, I'm a beginner at Java programming.
My problems are:
- how to store my inputs(item & amount) into the month[m]
- for case2, what should i do so that it will display the items , amounts & total the user keyed in based on the month?

2
Contributors
1
Reply
15
Views
3 Years
Discussion Span
Last Post by JamesCherrill
0

You didn't post the requirements definition, so we have to guess exactly what you were asked to do, but ... at a guess ...
Either:
Your expenses need to have a month number associated with them ( a third array?
or:
Each month should have its own arrays of items and amounts... eg

String[][] item ... // first index is month number, second is item number
int monthNum = ... // whatever month you are interested in
for (int i = 0; i < item{monthNumm}.length; i++) {
   System.out.println(item[month][i] ...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.