0

I am trying to run this program but I cannot, the compiler is sending me a ".class" error. Can somebody help me with my problem and if it is possible a general tip about ".class" error? Here is the program:

    import java.io.*;
    class Bus
    {
        private int kostos;
        private int plithos;
        private int typepiv;
        Bus(int x,int y,int z)
        {
            kostos=x;
            plithos=y;
            typepiv=z;

        }
        public void KB(int[] x)
        {
        try{
           for(int i=1;i<5;i++)
             {

                 if(typepiv==2)
                 {
                     plithos=plithos+plithos/2;
                     kostos=kostos-kostos/2;
                 }
                 if(typepiv==3)
                 {
                     plithos=plithos-plithos/5;
                     kostos=kostos-kostos*25/100;
                 }
                 if(typepiv==1)
                 {
                     plithos=plithos;
                     kostos=kostos;
                 }
                     x[i]=plithos*kostos; 
             } 
         } catch(Exception ex){
              ex.printStackTrace();
         }
      }
   }

  class testBus
  {
     public static void main(String args[])
     {
          String leof[]=new String[4];
          int leof1[][]=new int[4][3];
          for(int i=1;i<5;i++)
             {
                 System.out.println("dwste onoma leoforiou");
                 leof[i]=UserInput.getString();
                 System.out.println("dwste kostos thesis enilika");
                 leof1[i][1]=UserInput.getInteger();
                 System.out.println("dwste plithos thesewn");
                 leof1[i][2]=UserInput.getInteger();
                 System.out.println("dwste tupos epibath gia enilikes=1,gia
                 paidia=2,gia    suntaksiouxous=3");
                 leof1[i][3]=UserInput.getInteger();
                 Bus leof2=new Bus(leof1[i][1],leof1[i][2],leof1[i][3]);
              }
           int KostEnoik[]=new int[4];
     ----->leof2.KB(KostEnoik);
           System.out.print("onoleo");
           System.out.print("  ");
           System.out.print("plithos");
           System.out.print("  ");
           System.out.print("kost(EURO)");
           System.out.print("typepiv");
           System.out.print("  ");
           System.out.print("apotelesma kostEnoik");
           for(int g=1;g<5;g++)
              {
                  System.out.print(leof[g]);
                  System.out.print(leof1[g][2]);
                  System.out.print(leof1[g][1]);
                  System.out.print(leof1[g][3]);
                  System.out.print(KostEnoik[g]);
              }
          }
      }

the compiler message says : testBus.java:56:error:cannot find symbol leof2.KB(KostEnoik); symbol:bariable leof2 location:class testBus 1 error

2
  • 3
    Even if the compiler error doesn't mean anything to you, it probably means something to other people here. Can you copy the exact text of the compiler error? Commented Jan 14, 2014 at 17:08
  • i put leof2.KB(KostEnoik); inside the loop and now the compiler complile the file thnxs very much everyone Commented Jan 14, 2014 at 17:44

5 Answers 5

1

Remove the array brackets [] when invoking KB

leof2.KB(KostEnoik); 

and remove the preceding enclosing brace }.

Aside: Java naming conventions indicate that variables start with a lowercase letter e.g. kostEnoik. Also consider giving the method KB a meaningful name, e.g. calculateCost

Read Java naming conventions

Sign up to request clarification or add additional context in comments.

2 Comments

i tried like this too but not it says that it cannot find symbol
Did you import UserInput?
1

concern is with your access

leof2.KB(KostEnoik[]);

You are trying to access the "leof2" variable outside of the scope in which it is defined i.e. outside for loop and scope is upto for loop and that's why the compiler will not be able to find that varialble .

1 Comment

@user3194888 have u get my friend
0
    leof1[i][3]=UserInput.getInteger();
    Bus leof2=new Bus(leof1[i][1],leof1[i][2],leof1[i][3]);
}
int KostEnoik[]=new int[4];
leof2.KB(KostEnoik[]);
  1. You are trying to access the "leof2" variable outside of the scope in which it's defined (in this particular case, the for loop) and that's not allowed.
  2. method KB takes an int array as argument, but you don't have to add the [] when passing the argument. The correct line is

    leof2.KB(KostEnoik);

However, there's something pretty odd with you logic: you're repeatedly (for loop) setting leof2, but only the last iteration of the loop will have any effect. I'm almost certain that that's not what you actually want, but the correct answer to where Bus leof2 should actually be defined depends on the correction of that issue.

2 Comments

hwat i want is that the array leof[1][1] and leof1[2][1] to go to the method i really dont know how to do this keep in mind that i am first year student so i dont know very much
ok I see. I think you're better off starting over, because the logic of your program is quite twisted due to all the different arrays you're using, and once you solve the issues mentioned in this question you'll be facing a number of array index of of bounds conditions (hint: the last element of int a[4] is a[3]). Ideally try to group all data that describe 1 line in a separate class and move the KB method to that class. That will be a lot clearer, and a lot more object oriented.
0

leof2.KB(KostEnoik); this is the main culprit. whether you have imported UserInput. Also try to go through the Java Basics

any method can be invoked using object when it is non static or class name when it is static. Please consider this link

Comments

0
  1. Get leof2 object out side the For Loop.
  2. Don't type [] when you pass the array as argument "leof2.KB(KostEnoik[]);".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.