?
Solved

test programme not working - compilation error?

Posted on 2004-10-08
8
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 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