Results 1 to 4 of 4
  1. #1
    ModestMariner is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Comparing multiple string values

    So I had an idea to write a program that will take a string variable and compare it to other string variables and give a list of what is better or what is worse than the input variable... I'm not entirely certain where to begin with this program, but I have a feeling I may have to create some kind of data array or matrix or something of that sort. Am I on the right track? What all will I need to do?

    Lets say I have a list of eight cars. car_A, car_B, car_C, etc..., car_H

    Here's an example input/output:
    Enter a vehicle name: car_A.

    The car_A is faster than: car_B, car_C, car_E
    The car_A is as fast as: car_A, car_D
    The car_A is slower than: car_F, car_G, car_H

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,600
    Rep Power
    5

    Default Re: Comparing multiple string values

    Clearly you need to associate a value with the car name that gives it a speed rating. You want to compare speed ratings, not car names. So I would suggest creating a Car class and put those in an array (or preferably a List).

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    WSUVanc is offline Member
    Join Date
    Mar 2013
    Posts
    14
    Rep Power
    0

    Default Re: Comparing multiple string values

    If you want to compare string variable, compareTo(String anotherString) , is will pretty much accomplish that. But as Jim said this may not be what you want to do. If you wanted to assign int values to your cars, such as speeds, <,>,==, and some type of loop or if statement, depending on what you want to do is a pretty simple way to go about that.

    As for starting the program, pretty much what jim said, use a Scanner to bring in your strings and build a list.
    Last edited by WSUVanc; 03-15-2013 at 02:19 AM.

  4. #4
    ModestMariner is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: Comparing multiple string values

    Alrighty, this is a step in the right direction. I still have a lot to learn before I'm actually able to work on this, but thanks for your help!

Similar Threads

  1. Comparing array values with int's
    By kcon90 in forum New To Java
    Replies: 11
    Last Post: 10-29-2012, 01:45 AM
  2. Comparing 4 values
    By faust83 in forum New To Java
    Replies: 11
    Last Post: 05-04-2012, 02:23 PM
  3. Help with comparing values
    By sabarooni in forum New To Java
    Replies: 1
    Last Post: 12-06-2011, 03:41 PM
  4. Comparing values within an Object
    By Bake1tEazy in forum New To Java
    Replies: 10
    Last Post: 02-09-2011, 02:05 PM
  5. Comparing values problems
    By mari.beka in forum New To Java
    Replies: 12
    Last Post: 11-16-2010, 09:15 PM

Tags for this Thread

Posting Permissions

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