Results 1 to 5 of 5
Thread: NEED HELP Please!!!
- 05-02-2010, 10:41 PM #1
Member
- Join Date
- May 2010
- Posts
- 6
- Rep Power
- 0
NEED HELP Please!!!
Hey guys, i have been working on this code for 2 days. I was wondering if someone can help me out, ITS DUE TOMORROW!!
This is the question/prompt:
Build the class LINE of equation y=ax+b.
Their attributes a and b are integers.
Two contructors are created: one with both a and b are provided,and the other only a is provided (in the second case, set b=0)
One method is built: printLINE: if (b==0) print equation of form y=ax else print equation of form y=ax+b.
In the test section, build 2 objects: abc=new LINE(2,3) and xyz=new LINE(5). Then print oth both of them. You expect the first object will be y=2x+3 and the second y=5x
This is what i have so far and it outputs y=0x (2 times):
//Monish Mehta
//04-30-2010
//Build a line y=ax+b
class LINE {
//attribute
int a;
int b;
//constructor
LINE (int a, int b){
}
LINE (int a){
b= 0;
}
//method
public void printLine (){
if (b==0)
System.out.println ("y="+a+"x");
else
System.out.println ("y="+a+"x"+"+"+b);
}
//Test
public static void main(String[] args){
LINE abc= new LINE (2,3);
LINE xyz= new LINE (5);
abc.printLine ();
xyz.printLine ();
}
}
PLEASE HELP! :confused:
THANKS IN ADVANCE
- 05-02-2010, 10:50 PM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
This is not our problem, and though it may be surprising to you, it makes us less likely to want to help you. Also, use CODE tags and format your code properly if you want people to try to read it.
The problem is in your first constructor. It doesn't do anything, and it needs to.
-Gary-
-
- 05-02-2010, 10:59 PM #4
Member
- Join Date
- May 2010
- Posts
- 6
- Rep Power
- 0
Hey guys i am really sorry. That was not my intention. It's just that i am a first time forum user. I have never used it before.
Sorry Once again. What do you suggest i should do?
-
As Gary stated, your constructors take parameters but don't do anything with them. You should use the constructor parameters to set class fields (you have two of them, ints a and b).
If you make the changes but it still doesn't work out, (as Gary stated), please post well-formatted code using code tags (see my signature below for more on how to use code tags).
Much luck.


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks