Solved

test programme not working - compilation error?

Posted on 2004-10-08
8
219 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
nextBoolean(double p) for Random class 3 41
Way to decrease size of apk file 9 86
JAVA API design with micro service cloud in mind 1 46
Running JavaFX on the Raspberry Pi 27 40
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

860 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