What's wrong with this code?
import java.util.*;
public class Exercise14
{
static Scanner console = new Scanner(System.in);
public static void main(String [] args)
{
int first, third;
IntClass second, fourth;
first = 3;
second = new IntClass(4);
third = 6;
fourth = new IntClass(7);
System.out.println(first + " " + second.getNum()
+ " " + third + " "
+ fourth.getNum());
getData(first, second, third, fourth);
System.out.println(first + " " + second.getNum()
+ " " + third + " "
+ fourth.getNum());
fourth.setNum(first * second.getNum() + third +
fourth.getNum());
getData(third, fourth, first, second);
System.out.println(first + " " + second.getNum()
+ " " + third + " "
+ fourth.getNum());
}
public static void getData(int a, IntClass b, int c, IntClass d)
{
a = console.nextInt();
b.setNum(console.nextInt());
c = console.nextInt();
d.setNum(console.nextInt());
b.setNum(a * b.getNum() - c);
d.setNum(b.getNum() + d.getNum());
}
}
I'm getting this when I compile:
Exercise14.java:32: cannot find symbol
symbol : class IntClass
location: class Exercise14
public static void getData(int a, IntClass b, int c, IntClass d)
^
Exercise14.java:32: cannot find symbol
symbol : class IntClass
location: class Exercise14
public static void getData(int a, IntClass b, int c, IntClass d)
^
Exercise14.java:10: cannot find symbol
symbol : class IntClass
location: class Exercise14
IntClass second, fourth;
^
Exercise14.java:13: cannot find symbol
symbol : class IntClass
location: class Exercise14
second = new IntClass(4);
^
Exercise14.java:15: cannot find symbol
symbol : class IntClass
location: class Exercise14
fourth = new IntClass(7);
^
Exercise14.java:24: operator + cannot be applied to int,IntClass.getNum
fourth.setNum(first * second.getNum() + third +
^
6 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
First, have you created the IntClass? and is it in the same package as Exercise14?
Your compiler is not able to find IntClass. So, if you've already created it, then make sure you compile everything all together, like javac *
If you haven't created IntClass yet, here's what it should look like:
public class IntClass
{
private int num;
public IntClass( int num )
{
this.num = num;
}
public int getNum()
{
return num;
}
public void setNum( int num )
{
this.num = num;
}
}
I'm further humbled. Thanks. Big help.