Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Thecount2

By: ace on May 5th, 2010  |  syntax: None  |  size: 2.09 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.ArrayList;
  2.  
  3. /**
  4.  * The train class contains the basic information about a train,
  5.  * but right now it's rather useless as it has no public
  6.  * methods. Do not change the private methods to public.  Do create
  7.  * your own public methods so that TrainTest will pass.
  8.  *
  9.  * @author (your name)
  10.  * @version (a version number or a date)
  11.  */
  12. public class Train
  13. {
  14.     private String name;
  15.     private int length;
  16.     private final ArrayList<String> maxSpeed = fillMaxSpeed();
  17.  
  18.     /**
  19.      * Constructor for objects of class Train
  20.      */
  21.     public Train(){
  22.         name = "";
  23.         length = 0;
  24.     }
  25.    
  26.    
  27.     private ArrayList<String> fillMaxSpeed(){
  28.         ArrayList<String> al = new ArrayList<String>();
  29.         al.add(0, "350.0");//minimum train length is 0: engine only
  30.         al.add(1, "344.7");
  31.         al.add(2, "340.2");
  32.         al.add(3, "332.8");
  33.         al.add(4, "321.2");
  34.         al.add(5, "315.9");
  35.         al.add(6, "311.0");
  36.         al.trimToSize();//trims the capacity of the ArrayList to its current size.
  37.         return al;
  38.     }
  39.    
  40.     public void setName(String name)
  41.         {
  42.             this.name = name;
  43.              }
  44.  
  45.      public String getName()
  46.         {
  47.             return name;
  48.         }
  49.        
  50.         public void setLength(int length)
  51.             {
  52.                 this.length = length;
  53.             }
  54.            
  55.             public int getLength()
  56.             {
  57.                 return length;
  58.             }
  59.            
  60.             public void getMaxSpeed(String speed)
  61.                 {
  62.                     while (index < maxSpeed.size)
  63.                         {
  64.                             if (maxSpeed.get(index) == speed))
  65.                                 {
  66.                                     return speed;
  67.                                 }
  68.                                 else
  69.                                     {
  70.                                         return 0;
  71.                                     }
  72.                                 index++
  73.                             }
  74.                         }
  75. }