Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Need help on java

Thread view: 
paul.paik@gmail.com - 09 Apr 2007 07:28 GMT
Other parts of the project, I've already done; however, I'm stuck on 2
parts (Making the interface and creating a Location

Picture of the structure
http://img47.imageshack.us/img47/946/untitledgi7.jpg

   quote:

   Instructions:
   Locatable Objects

   Create a class that represents a Locatable object. Use your
imagination - it can be anything that is Locatable, which is to say it
must implement the Locatable interface. As an added requirement, your
class must also implement Comparable and provide a toString method.

   Your compareTo method should order instances of your class
according to their location.

   Show me your Locatable and Comparable class before proceeding.

   quote:

   The Locatable Interface

   Any object that "Has-A" Location should be able to report its
Location on demand, and all objects that have a Location should report
their location in the same way. We enforce this rule by introducing an
interface that specifies how an object should report its location, and
by insisting that all objects that have a Location implement this
interface. We call objects with a Location "Locatable".

   The Locatable interface specifies only one method: location. The
method returns a Location object which encapsulates the Locatable
object's current location. The interface looks like this:

   Public interface Locatable
   {
   Location location();
   }

   Code the Locatable interface and add it to your project.

PROGRAM

   quote:

   Main:

   /**
   * Write a description of class Main here.
   *
   * @author (your name)
   * @version (a version number or a date)
   */
   public class Main
   { public static void main ()
   {
   Location testing = new Location (3,6);
   Location atesting = new Location (4,7);
   System.out.println ("Rows: " + testing.row());
   System.out.println ("Columns: " + testing.col());
   System.out.println ("Index of Compare to A" +
testing.compareTo("a"));
   if (testing.equals(atesting)==true)
   {
   System.out.println ("They are equal");
   }
   else
   {
   System.out.println ("They are not equal");
   }
   System.out.println (testing.toString());
   }
   }

   quote:

   public class Location implements Comparable
   {
   private int qrow;
   private int qcol;
   // constructors
   public Location(int row, int col)
   {
   qrow=row;
   qcol=col;
   }
   // accessors
   public int row()
   {
   return qrow;
   // return the row value for this Location
   }
   public int col()
   {
   return qcol;
   // return the col value for this Location
   }

   // compareTo and equals
   public int compareTo(Object other)
   {
   if (((Location)other).row()==qrow &&
((Location)other).col()==qcol)
   {
   return 0;
   }
   else
   {
   int difference;

   if (((Location)other).row()==qrow)
   {
   int diff=qcol-(((Location)other).col());
   return diff;
   }
   else
   {
   difference=qrow-(((Location)other).row());
   return difference;
   }
   }
   }
   public boolean equals(Object other)
   {
   if (qrow==((Location)other).row() &&
qcol==((Location)other).col())
   {
   return true;
   }
   else
   {
   return false;
   }
   }
   // toString method returns a String representation
   // of this Location
   public String toString()
   {
   String x = qrow + "this is the row";
   String y = qcol + "this is the col";
   return x + y;
   // String remember=qrow + " ," + qcol;
   // return remember;
   }
   }

   quote:

   /**
   * Write a description of interface Locatable here.
   *
   * @author (your name)
   * @version (a version number or a date)
   */

   public interface Locatable
   {
   Location location();
   }

   quote:

   /**
   * Write a description of class School here.
   *
   * @author (your name)
   * @version (a version number or a date)
   */
   public class School extends Location
   {
   private int qasdf;
   private int qfdsa;
   public School(int asdf, int fdsa)
   {
   qasdf=asdf;
   qfdsa=fdsa;
   }
   }

The School class has an error of a wrong constructor for location
What's the issue?

Thanks for any help
Andrew Thompson - 09 Apr 2007 07:56 GMT
>Other parts of the project, I've already done; however, I'm stuck on 2
>parts (Making the interface and creating a Location
...
>    Public interface Locatable

D:\projects\junk\numbered\237Main\Main.java:1: class, interface, or enum
expected
Public interface Locatable
^

You should be getting the above qoted compilation
error on the very first line of code posted.

(big snip)
>The School class has an error of a wrong constructor for location

Huhh?  I have never seen the error 'wrong constructor
for location' which makes me suspect that you are
paraphrasing the error the compiler reports.

Please don't do that.  Instead, it is always best to
copy/paste compilation and runtime errors, as I did
above.
<http://www.physci.org/codes/javafaq.html#exact>

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.