[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

test programme not working - compilation error?

Posted on 2004-10-08
8
Medium Priority
?
225 Views
Last Modified: 2010-03-31
Cannot understanding why my test file does not compile?

/*This programme tests the DataLog class*/

public class DataLogTestProg
{
      public static void main(String [] args)
      {
            DataLog d1, d2;//declare two DataLog objects
            d1 = new DataLog();//create the first DataLog instance
            d2 = new DataLog();//create the second DataLog instance

            System.out.println("d1:" + d1.toString());
            System.out.println("d2:" + d2.toString());

            d1.setData(4);//send value 4 to ojbect 1
            d2.setData(6);//send value 6 to ojbect 2
      }
}

public class DataLog
{
      private int x;//the current data value
      private int lastx;//the previous data value

      //Constructors

      /*Default constructor, sets data to zero*/

      public DataLog()
      {
            x = 0;
            lastx = 0;
      }

      /*Sets data to initialValue.  This is also the previous value*/

      public DataLog(int initialValue)
      {
            x = initialValue;
            lastx = initialValue;
      }

      //Methods

      /*Sets data to dataValue*/

      public void setData(int dataValue)
      {
            lastx = x;
            x = dataValue;
      }

      /*Returns the current data value*/

      public int getData()
      {
            return x;
      }

      /*Restores the previous value of the data value*/

      public void undo()
      {
            x = lastx;
      }

      /*Returns a text representation of the current and last value of the data value*/

      public String toString()
      {
            return "new value" + x + "last value" + lastx;
      }
}
0
Comment
Question by:buglouie
  • 5
  • 2
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12264024
Nothing wrong with code posted - what problem are you getting?
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 12264028
What error message are you getting?

P.S. I assume those two classes are in separate files with the correct names?
0
 

Author Comment

by:buglouie
ID: 12264053
Error message reads:-

DataLogTestProg.java:8:cannot resolve symbol
symbol:class DataLog
location:class DataLogTestProg

DataLog d1, d2;//
             ^

etc
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12264067
Make sure DataLog class is in the other's classpath
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12264075
If they're in one file, remove second 'public' and compile the one with main method. The file should be DataLogTestProg.java
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 12264086
Or, simply put the two files in the same directory (if possible). It should run fine then. You may also have to compile DataLog first as some compilers will not look for and compile necessary class files for you.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 12264088
So,

1. Remove second 'public' from 'public class ...'
2. Save as DataLogTestProg.java
3. Compile:

javac DataLogTestProg.java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12264107
8-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month17 days, 14 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question