Results 1 to 4 of 4

Thread: ComPareTo Usage

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    3

    ComPareTo Usage

    1. Write a class Compare3 that provides a static method largest. Method largest should take three Comparable parameters and return the largest of the three (so its return type will also be Comparable). Recall that method compareTo is part of the Comparable interface, so largest can use the compareTo method of its parameters to compare them.
    2. Write a class Comparisons whose main method tests your largest method above.
    • First prompt the user for and read in three strings, use your largest method to find the largest of the three strings, and print it out. (It's easiest to put the call to largest directly in the call to println.) Note that since largest is a static method, you will call it through its class name, e.g., Compare3.largest(val1, val2, val3).
    • Add code to also prompt the user for three integers and try to use your largest method to find the largest of the three integers. Does this work? If it does, it’s thanks to autoboxing, which is Java 1.5’s automatic conversion of ints to Integers. You may have to use the –source 1.5 compiler option for this to work.

    This is my assignment.
    I'm kind of a newbie to java programing, any hints on where to begin

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: ComPareTo Usage

    Well, What have you done so far?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    3

    Re: ComPareTo Usage

    Thanks
    Last edited by MugenNeuspeed; Nov 6th, 2007 at 01:31 PM.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: ComPareTo Usage

    It looks like you've gotten all of it right.

    congratulations
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width