• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

This is bugging me, and i lost sleep from it.

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, i am meant to create a class called Line with the Line Main client to print out two points through a string. However, we are only needing 4 things.

public Line // a constructor

// two return's for the accessors
public Point getP1()
public Point getP2()

// and the string which will return this "[(3,5),(2,7)]"
public String toString()

Here is my code from Line:


And here is the client LineMain



I do not know how the client's program should be designed, and when i'm checking the solutions, it would let a import java.awt.*;

which will do this, java.awt.Point[x = 3, y =8] which is not what i'm looking for.

Can you assist me please?
 
Saloon Keeper
Posts: 9562
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not entirely sure I understand your question, but let me make an observation.
Nowhere in your LineMain are you constructing a line, you are constructing two points instead.
Seems like you'd want something like:
 
Kyle Grady
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Not entirely sure I understand your question, but let me make an observation.
Nowhere in your LineMain are you constructing a line, you are constructing two points instead.
Seems like you'd want something like:



Sorry if i'm difficult when it comes to explanation, yea it would seem like that but i still get the print out.

[java.awt.Point[x=22,y=3], java.awt.Point[x=4,y=7]]

what i am wanting is them to be without the java.awt.Point, and when i do take the import out it would still give me the error which would still put me back into the same situation.

 
Kyle Grady
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do have my other class methods such as Point and PointMain that are used used with Line.

After taking off the import java which worked, i do get a [(null),(null)]

How do i fix this?
 
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you wrote your own Point class? In that case you don't want to import java.awt.Point, so you're going in the right direction.

Now you want your Point class to help out in producing the right output from your Line class's toString() method. That means that Point needs a toString() method which returns whatever you need to be plugged into Line's toString() method.
 
Kyle Grady
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:So you wrote your own Point class? In that case you don't want to import java.awt.Point, so you're going in the right direction.

Now you want your Point class to help out in producing the right output from your Line class's toString() method. That means that Point needs a toString() method which returns whatever you need to be plugged into Line's toString() method.



Can you explain further, here i'll post what i have. Here's the Point and PointMain with Line and LineMain









 
Marshal
Posts: 8412
606
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kyle,

Fix typo mistakes in method name:
"Point" class: line 58
"PointMain" class: line 63
 
Paul Clapham
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see your Point class already has a toString() method. And it looks to me like it's exactly what you need. So can you refresh us with what the problem is, now that we've seen that code?
 
Kyle Grady
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Hi Kyle,

Fix typo mistakes in method name:
"Point" class: line 58
"PointMain" class: line 63



Can you tell me how is it suppose to look? : )

Like, help write it down if it's too much trouble? ^ ^

I would appreciate it.
 
Paul Clapham
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


One of these two is not like the other...
 
Kyle Grady
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I see your Point class already has a toString() method. And it looks to me like it's exactly what you need. So can you refresh us with what the problem is, now that we've seen that code?



OK ^^


Here's what's to happen, the code i written down serves to get the Quardinate points based on where the x's and y's are. Like Quadrant I (+ , +), Quadrant II ( -, + ), Quadrant III ( - , - ), and Quadrant IV ( +, - ).

Along with texting the vertical x's if they are aline. See this code:



The next part (which is the nightmare of lost sleep lol), is to create a line class that has 4 behaviors which are the public Line, get P1, get P2, and toString()



Now as you can see i created the mainLine, after your good help but it only returned null values.

If you run this, with the line main in front of you, the return for the two points will be [(null),(null)]

when it should be [(22, 3),(4,7)] that should show on the console yet id does not, and i want to know how to fix this so that it can print ints upon return.

Can you help with some code text? : )
 
Liutauras Vilda
Marshal
Posts: 8412
606
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, it seems other case here.
You have two methods which looks pretty the same:

Lines 32 - 34Line 58
Not sure what happened, but likely you don't want one of those.
 
Kyle Grady
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

One of these two is not like the other...



Oh, no need to worry i took care of that. It still works normally since it's locating the objects but with different mutations already pre-set in the parameters as you can see. it's just taking theses x and y's and adding them to p1 for p1.translation and p2 for p2.translation. It's totally fine, thanks though. ^^
 
Kyle Grady
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Ok, it seems other case here.
You have two methods which looks pretty the same:

Lines 32 - 34Line 58
Not sure what happened, but likely you don't want one of those.




OHHHHHHH!!!

Thanks, i got rid of it. Ok now onto the main problem which is my Line behavior in quotes - thank you very much.


OK ^^


Here's what's to happen, the code i written down serves to get the Quardinate points based on where the x's and y's are. Like Quadrant I (+ , +), Quadrant II ( -, + ), Quadrant III ( - , - ), and Quadrant IV ( +, - ).

Along with texting the vertical x's if they are aline. See this code:



The next part (which is the nightmare of lost sleep lol), is to create a line class that has 4 behaviors which are the public Line, get P1, get P2, and toString()



Now as you can see i created the mainLine, after your good help but it only returned null values.

If you run this, with the line main in front of you, the return for the two points will be [(null),(null)]

when it should be [(22, 3),(4,7)] that should show on the console yet id does not, and i want to know how to fix this so that it can print ints upon return.

Can you help with some code text? : )

 
Carey Brown
Saloon Keeper
Posts: 9562
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kyle Grady wrote:


Is this what your Line class still looks like? Here you aren't setting p1 and p2 in the constructor.
 
Kyle Grady
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Kyle Grady wrote:


Is this what your Line class still looks like? Here you aren't setting p1 and p2 in the constructor.




Oh my god, i got it. thanks for pointing that out for the constructor.

Seriously here is the final form.




It just needs the string to be cleaned up and that's it.

Thank you very much . ^^
 
I like tacos! And this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic