CS 1713 Introduction to Programming II Spring 2012 Daily Answers


Class 11:

  1. The class has a compareTo method that take a single object parameter and returns an int.
  2. "cdefg"
  3. "cde"
  4.     public static String firstToken(String s) {
           while (s.indexOf(' ') == 0)
              s = s.substring(1);
           int ind = s.indexOf(' ');
           if (ind == -1)
              return "";
           return s.substring(0,ind);
        }
    

  5.    public int compareTo(Object other) {
          StudentInfo otherStudent = (StudentInfo)other;
          double gpa1 = computeGPA();
          double gpa2 = otherStudent.computeGPA();
          if (gpa1 > gp12)
             return 1;
          if (gpa1 < gpa2)
             return -1;
          return myName.compareTo(otherStudent.myName);
       }
    
  6.    public void printLargestRadius(Circle[] circles) {
          if (circles.length == 0)
             return;
          double largestRadius = circles[i].getRadius();
          for (int i=1; i<circles.length;i++)
             if (largestRadius < cirlces[i].getRadius();
                largestRadius = circles[i].getRadius();
          System.out.println(largestRadius);
       }