lundi 27 juin 2016

Java Complex Class

public class Test {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the first complex number: ");
        double c1Real = input.nextDouble();
        double c1Imag = input.nextDouble();
        Complex c1 = new Complex(c1Real, c1Imag);

        System.out.print("Enter the second complex number: ");
        double c2Real = input.nextDouble();
        double c2Imag = input.nextDouble();
        Complex c2 = new Complex(c2Real, c2Imag);

        System.out.println("(" + c1 + ")" + " + " + "(" + c2 + ")" + " = " + c1.add(c2));
        System.out.println("(" + c1 + ")" + " - " + "(" + c2 + ")" + " = " + c1.subtract(c2));
        System.out.println("(" + c1 + ")" + " * " + "(" + c2 + ")" + " = " + c1.multiply(c2));
    }

    public Complex add(Complex c2) {
        double totalRealPart = this.real + c2.getReal();
        double totalImagPart = this.imag + c2.getImag();
        return new Complex(totalRealPart, totalImagPart);
    }

    public Complex subtract(Complex c2){
        double totalRealPart = this.real - c2.getReal();
        double totalImagPart = this.imag - c2.getImag();
        return new Complex(totalRealPart, totalImagPart);
    }

    public Complex multiply (Complex c2){
        double totalRealPart = this.real * c2.getReal();
        double totalImagPart = this.imag * c2.getImag();
        return new Complex(totalRealPart, totalImagPart);

}

I seem to keep having the same repeated issue for the most part, but I'm unable to figure out what. Suggestions?

Description Resource Path Location Type

//not sure what this is// Build path specifies execution environment CDC-1.1/Foundation-1.1. There are no JREs installed in the workspace that are strictly compatible with this environment. JUnit Build path JRE System Library Problem Build path specifies execution environment J2SE-1.4. There are no JREs installed in the workspace that are strictly compatible with this environment. try Build path JRE System Library Problem

//my errors// Scanner cannot be resolved to a type Test.java /_pasted_code_/sources line 4 Java Problem

line 8 Java Problem Scanner cannot be resolved to a type Test.java /_pasted_code_/sources

line 4 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 13 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 8 Java Problem Syntax error on token "/", delete this token TestAssignment7.java /_pasted_code_/sources line 1 Java Problem Build path specifies execution environment CDC-1.1/Foundation-1.1. There are no JREs installed in the workspace that are strictly compatible with this environment. Product Build path JRE System Library Problem Syntax error on token(s), misplaced construct(s) TestAssignment7.java /_pasted_code_/sources line 1 Java Problem Syntax error, insert "}" to complete ClassBody Test.java /_pasted_code_/sources line 37 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 20 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 13 Java Problem real cannot be resolved or is not a field Test.java /_pasted_code_/sources line 21 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 20 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 23 Java Problem imag cannot be resolved or is not a field Test.java /_pasted_code_/sources line 22 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 26 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 26 Java Problem imag cannot be resolved or is not a field Test.java /_pasted_code_/sources line 28 Java Problem real cannot be resolved or is not a field Test.java /_pasted_code_/sources line 27 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources line 32 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 29 Java Problem real cannot be resolved or is not a field Test.java /_pasted_code_/sources line 33 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 32 Java Problem Complex cannot be resolved to a type Test.java /_pasted_code_/sources

line 35 Java Problem imag cannot be resolved or is not a field Test.java /_pasted_code_/sources line 34 Java Problem

Aucun commentaire:

Enregistrer un commentaire