Solved

test programme not working - compilation error?

Posted on 2004-10-08
8
217 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12264067
Make sure DataLog class is in the other's classpath
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 86
network + 7 73
Python Assistance 7 36
micro services vs rest web services 16 50
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now