Skip to content
Advertisement

Online Compiler won’t run more than one class

I am using the online compiler “onlinegdp” to run java and I am unable to use multiple files in my programming. The exact same code works on eclipse so I am unsure where the problem is.

I don’t know enough about java to try anything other that Object myObject = newObject(); . So anything would be helpful.

This is what is in my worker class

public class Worker
{
  private int hours;
  private double rate;
public Worker ()
{
  hours = 999;
  rate = 999;
}
public Worker (int nHours, double nRate)
{
  hours = nHours;
  rate = nRate;
}
public int getHours ()
{
  return hours;
}
public void setHours (int nHours)
{
  hours = nHours;
}
public double getRate ()
{
  return rate;
}
public void setRate (double nRate)
{
  rate = nRate;
}
public double paycheck ()
{
  return rate * hours;
}
public void raiseRate (double raiseRate)
{
  rate = raiseRate + rate;
}

}

This is the main class

public class Main
{

public static void main (String[]args)
{
  Worker bob = new Worker ();
  System.out.println (bob.getHours ());
  System.out.println (bob.getRate ());
  bob.setHours (9);
  bob.setRate (7.9);
  System.out.println (bob.getHours ());
  System.out.println (bob.getRate ());
  System.out.println (bob.payCheck ());
  System.out.println (bob.raiseRate ());
}
}

I got this error
Main.java:14: error: cannot find symbol
Worker bob = new Worker ();
^
symbol: class Worker
location: class Main

Advertisement

Answer

I don’t know how onlinegdp – online compiler will save another class file & reference it. If they have functionality then you can try to add them in package & import that file using package.

It’s pain to see the folder/project structure on most of the online compiler. They are meant to run small snippet & not to run the whole project.

Below is the snippet you can run on onlinegdp without creating the different file.

public class Main
{
  public static void main (String[]args)
  {
    Worker bob = new Worker ();
      System.out.println (bob.getHours ());
  }

  static public class Worker
  {
    private int hours;
    private double rate;
    public Worker ()
    {
      hours = 999;
      rate = 999;
    }
    public Worker (int nHours, double nRate)
    {
      hours = nHours;
      rate = nRate;
    }
    public int getHours ()
    {
      return hours;
    }
    public void setHours (int nHours)
    {
      hours = nHours;
    }
    public double getRate ()
    {
      return rate;
    }
    public void setRate (double nRate)
    {
      rate = nRate;
    }
    public double paycheck ()
    {
      return rate * hours;
    }
    public void raise (double raise)
    {
      rate = raise + rate;
    }

  }

}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement