Solved

test programme not working - compilation error?

Posted on 2004-10-08
8
220 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 250 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

740 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