This discussion is archived
1 Reply Latest reply: Sep 15, 2012 2:20 PM by rp0428 RSS

Help me to troubleshoot the errors

962352 Newbie
Currently Being Moderated
import java.io.DataInputStream;
class Items
{
     int itemcode[]=new int[10];
     int itemcoast[]=new int[10];
     int rem;
     int i,coast,counter;
     try
     {
          //Input Items
          void getitem()
          {
               
               System.out.println("Enter the item code");
               itemcode[counter]=Integer.parseInt(d.readLine());
               System.out.println("Enter the item cost");
               itemcost[counter]=Integer.parseInt(d.readLine());
               counter++;
          }
          //Total price
          void sumitemcoast()
          {
               for(i=0;i<counter;i++)
               {
                    coast=coast+itemcoast;
               }
          }
          //to display current items and its coast
          void display()
          {
               System.out.println("Item code And Item Coast");
               for(i=0;i<counter;i++)
               {
                    System.out.println(itemcode[i]+" "+itemcoast[i]);
               }
          }
          //remove item
          void remove()
          {
               System.out.println("Enter the item code you want to remove");
               rem=Integer.parseInt(d.readLine());
               for(i=0;i<counter;i++)
               {
                    if(itemcode[i]==rem)
                    {
                         itemcoast[i]=0;
                         break;
                    }
               }
          }
     }
     catch (Exception e)     {     }
}

//main
class Allitem
{
     public static void main(String args[])
     {
          DataInputStream d=new DataInputStream(System.in);
          Items I=new Items();
          try
          {
               System.out.println("Press 1 to Enter Data \n Press 2 to display Item and Coast \n Press 3 to get total item coast \n Press 4 to remove item");
               x=Integer.parseInt(d.readLine());
               do
               {
                    switch(x)
                    {
                         case 1:I.getitem();
                                   break;
                         case 2:I.display();
                                   break;
                         case 3:I.sumitemcoast();
                                   break;
                         case 4:I.remove();
                                   break;
                    }
                    System.out.println("Enter 1 to stop or 0 to continue");
                    int w=Integer.parseInt(d.readLine());
               }
               while(w!=0);
          }
          catch (Exception e){}
     }
}
  • 1. Re: Help me to troubleshoot the errors
    rp0428 Guru
    Currently Being Moderated
    Welcome to the forum!

    Please read the FAQ for how to post questions on the forum.

    The most important guideline is that you actually need to ask a question. All you did was post a bunch of code. When you do post code put \
     tags on the line before and the line after the code to  preserve formatting as discussed in the FAQ.
    
    Edit your post to add the \
    tags and to ask a question. Provide all information needed for someone to help you.

    If you have errors you need to provide the full error and stacktrace.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points