Advertisement
incomplete

ObjectList

Apr 15th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class ObjectList {
  4.  
  5.     private int numFractions = 0;
  6.     private String[] listOfFractions = new String[100];
  7.     Fraction[] fractionList = new Fraction[255];
  8.  
  9.     /****************************************************/
  10.     /* Add the line from the file to the next index of  */
  11.     /* the array. */
  12.     /****************************************************/
  13.     public void add(String f) {
  14.         listOfFractions[numFractions++] = f;
  15.     }
  16.    
  17.     /****************************************************/
  18.     /* This method creates a string array that will     */
  19.     /* contain two elements - the left and right side of*/
  20.     /* the fraction. The numerator and denominator are  */
  21.     /* sent to the ctor of Fraction. */
  22.     /****************************************************/
  23.     public Fraction[] repopulateArray(){
  24.         String[] splitFractions = new String[2];
  25.         for(int i=0;i<numFractions;i++){
  26.             splitFractions = listOfFractions[i].split("/");
  27.             Fraction theFraction = new Fraction (Integer.parseInt(splitFractions[0]), Integer.parseInt(splitFractions[1]));
  28.             fractionList[i] = theFraction;
  29.         }
  30.         return fractionList;
  31.     }
  32.    
  33.     public String toString(){
  34.         return Arrays.toString(fractionList);
  35.     }
  36.    
  37.     public void expand() {
  38.         Fraction[] newFractionList = new Fraction[fractionList.length + 1];
  39.         System.arraycopy(fractionList, 0, newFractionList, 0, fractionList.length);
  40.         fractionList = newFractionList;
  41.     }
  42.    
  43.     public Fraction[] getFractionList(){
  44.         return fractionList;
  45.     }
  46.    
  47.     public void setFractionList(Fraction[] fractionList){
  48.         this.fractionList = fractionList;
  49.     }
  50.    
  51.     public int getNumFractions(){
  52.         return numFractions;
  53.     }
  54.    
  55.     public void setNumFractions(int numFractions){
  56.         this.numFractions = numFractions;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement