Reputation: 3
class Maths{
// Attributes of maths
private int num1;
private int num2;
//Constructor
public Maths ***- This is where the error is***
{
add = a;
subtract = s;
multiply = m;
divide = d;
}
//Get me some Accessors
public String getAdd()
{
return add;
}
public string getSubtract()
{
return subtract;
}
public String getMultiply()
{
return multiply;
}
public String getDivide()
{
return divide;
}
}
}
Alright so I'm new to programming, Absolutely newborn. I'm really not sure what to do for this. I need to "Write a class called Maths. It has 2 attributes called num1 and num2. It has a constructor. It will have methods called Add(), subtract(), multiply() and divide().(Hint: integer division use modulus operator). Most of these methods return the result. Write all the getters and setters and a toString() method."
Upvotes: 0
Views: 57
Reputation: 509
constructor has the same name as class and parenthesis. this is what you need to put there.
public Maths()
{
add = a;
subtract = s;
multiply = m;
divide = d;
}
Upvotes: 0
Reputation: 13854
In Maths constructor you have forgotten parenthesis ()
Do like this
public Maths()
{
add = a;
subtract = s;
multiply = m;
divide = d;
}
Upvotes: 1