Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 21st, 2005, 1:42 PM   #1
Esroh
Newbie
 
Join Date: May 2005
Posts: 8
Rep Power: 0 Esroh is on a distinguished road
Coding problem. Help!!!

Hi
I've written some lines of codes but can't make it work. Can anyone help me and tell me what's the problem.

 
public class Point
{
  public static void main(String args[])
  {
	Pointing point1= new Pointing(2,3);
	Pointing point2= new Pointing(4,5);

	point1.displayDetails();
	point2.displayDetails();

  }


 class Pointing
 {
  Pointing(int XCoord, int YCoord)
  {
	  this.XCoord=XCoord;
	  this.YCoord=YCoord;

	  displayDetails()
	  {
		  System.out.println("(" + XCoord + "," + YCoord + ")");
	  }
  }
 }
}
Esroh is offline   Reply With Quote
Old May 21st, 2005, 2:41 PM   #2
kirkl_uk
Programmer
 
kirkl_uk's Avatar
 
Join Date: Apr 2005
Location: England
Posts: 86
Rep Power: 4 kirkl_uk is on a distinguished road
Send a message via MSN to kirkl_uk
Two problems that I can see:
  1. You need to declare member variables for the Pointing class to hold the coordinates.
  2. Your displayDetails function needs a return type.

public class Point
{
  public static void main(String args[])
  {
	Pointing point1= new Pointing(2,3);
	Pointing point2= new Pointing(4,5);

	point1.displayDetails();
	point2.displayDetails();

  }


 class Pointing
 {
  private int XCoord = 0; 
  private int YCoord = 0;

  Pointing(int XCoord, int YCoord)
  {
	  this.XCoord=XCoord;
	  this.YCoord=YCoord;

	  void displayDetails()
	  {
		  System.out.println("(" + XCoord + "," + YCoord + ")");
	  }
  }
 }
}

Last edited by kirkl_uk; May 21st, 2005 at 2:45 PM.
kirkl_uk is offline   Reply With Quote
Old May 21st, 2005, 2:52 PM   #3
Esroh
Newbie
 
Join Date: May 2005
Posts: 8
Rep Power: 0 Esroh is on a distinguished road
Thanks a lot kirkl_uk!!!
Esroh is offline   Reply With Quote
Old May 21st, 2005, 3:06 PM   #4
Esroh
Newbie
 
Join Date: May 2005
Posts: 8
Rep Power: 0 Esroh is on a distinguished road
I've tried it but it still doesn't work. It's about a ; about line 25 but i can't see where there is a ; missing.
Esroh is offline   Reply With Quote
Old May 21st, 2005, 4:12 PM   #5
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
displayDetails() cant be inside of the constructor Pointing...

public class Point
{
  public static void main(String args[])
  {
	Pointing point1= new Pointing(2,3);
	Pointing point2= new Pointing(4,5);

	point1.displayDetails();
	point2.displayDetails();

  }
}

class Pointing
 {
  private int XCoord = 0; 
  private int YCoord = 0;

  Pointing(int XCoord, int YCoord)
  {
	  this.XCoord=XCoord;
	  this.YCoord=YCoord;
  }
  public void displayDetails()
  {
	  System.out.println("(" + XCoord + "," + YCoord + ")");
  }

 }

JD
JDStud6 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:07 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC