Solved

Compilation errors, help with using constructors

Posted on 2004-03-22
6
203 Views
Last Modified: 2010-03-31
I made a class called Complex which holds 3 methods. Then i created another file called complextest
I'm trying to invoke the methods in complex through complextest but getting errors in the complextest

I'm not sure what I'm doing wrong or what I need to do to resolve this problem.

here is the code for complex

public class Complex
{
   
    public Complex()
    {
       

       

    }
   
    public void add(float w, float x, float y, float z)
    {
       float a = w + y;
       float b = x + z;
       System.out.println(a + " + " + b + "i");
    }
   
    public void subtract(float w, float x, float y, float z)
    {
        float a = w - y;
        float b = x - z;
        System.out.println(a + " + " + b + "i");
    }
   
    public void printComplex(float w, float x, float y, float z)
    {
        System.out.print( "(" + w + "," + x + ")");
        System.out.println(" (" + y + "," + z + ")");
    }
   
}

here is the code for complextest

import javax.swing.JOptionPane;
import java.lang.String;

public class Complextest {
           
    public static void main(String args[])
        {
            String I, I2; //user input for the imagionary parts
            String R, R2; //user input for the real parts
            float real, real2; //to be used for calculations
            float imag, imag2; //to be used for calculations
           
                    //recieve input from user
            R = JOptionPane.showInputDialog("Enter the real part of the first complex num.");
            I = JOptionPane.showInputDialog("Enter the imagionary part of the first complex num.");
            R2 = JOptionPane.showInputDialog("Enter the real part of the second complex num.");
            I2 = JOptionPane.showInputDialog("Enter the imagionary part of the second complex num.");
       
            //convert string input into float to be used for calculations
            real = Float.parseFloat(R);
            real2 = Float.parseFloat(R2);
            imag = Float.parseFloat(I);
            imag2 = Float.parseFloat(I2);
           
            Complex complex = new Complex(R, I, R2, I2);
            Complex.add(real, imag, real2, imag2);
            Complex.subtract(real, imag, real2, imag2);
            Complex.printComplex(real, imag, real2, imag2);

            /*method calls
            add(real, imag, real2, imag2);
            subtract(real, imag, real2, imag2);
            printComplex(real, imag, real2, imag2);*/
        }
       
    }

and here is the errors that I'm receiving:

Complextest.java [33:1] cannot resolve symbol
symbol  : class Complex
location: class Complextest
            Complex complex = new Complex(R, I, R2, I2);
            ^
Complextest.java [33:1] cannot resolve symbol
symbol  : class Complex
location: class Complextest
            Complex complex = new Complex(R, I, R2, I2);
                                  ^
Complextest.java [34:1] cannot resolve symbol
symbol  : variable Complex
location: class Complextest
            Complex.add(real, imag, real2, imag2);
            ^
Complextest.java [35:1] cannot resolve symbol
symbol  : variable Complex
location: class Complextest
            Complex.subtract(real, imag, real2, imag2);
            ^
Complextest.java [36:1] cannot resolve symbol
symbol  : variable Complex
location: class Complextest
            Complex.printComplex(real, imag, real2, imag2);
            ^
5 errors
Errors compiling Complextest.

Thanks for the help.
0
Comment
Question by:Orlando15767
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:Moroni24
ID: 10651911
I don't see a constructor for complex that takes 4 strings as parameters... do you need to crate one or is it just not listed?
0
 
LVL 1

Author Comment

by:Orlando15767
ID: 10651922
are you saying that I need to change the parameters from the strings to the floats?
0
 
LVL 2

Expert Comment

by:Moroni24
ID: 10651975
You don't have a constructor that takes 4 strings as params. Your constructor takes nothing. So you need to do something like

public class Complex
{

  String I, I2; //user input for the imagionary parts
  String R, R2; //user input for the real parts

   
    public Complex(String I, String I2, String R, String R2)
    {
        this.I = I;
        this.I2 = I2;
        this.R = R;
        tis.R2 = R2;
    }
     
....
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 1

Author Comment

by:Orlando15767
ID: 10652034
I put that in Complex, but I'm still getting the same errors in Complextest
0
 
LVL 2

Accepted Solution

by:
Moroni24 earned 90 total points
ID: 10652041
are they in the same package?
0
 
LVL 1

Author Comment

by:Orlando15767
ID: 10652129
that was the problem.....

thanks for all the help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Should localization be done inside spring controller 5 32
tomcat startup error 5 102
Java string replace 11 54
servlet and mdb, jms error 1 33
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

856 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