CS230 Data Structures, Wellesley College

Assignment 2

Due: Thursday, February 28, soft copy in class

[CS230 Home Page] [Syllabus] [Assignments] [Documentation] [CS Dept.]

Choosing the Right Computer Science Graduate School

There are many online resources that provide valuable information about graduate programs in Computer Science, and how to choose programs that best fit an individual student's interests and needs. One particularly interesting website allows you to customize the ranking of graduate programs based on your own weighting of various criteria used to judge the quality of these programs and was created by Geoff Davis while he was on the faculty at Dartmouth College.

In this problem, you will implement a small version of a program that produces a customized ranking of Computer Science graduate programs.

Task 1: Sorting an Array of integers

Consider the code in the file Sort.java, in particular the sortArray() method, and its auxiliary swap() method. Study the code carefully. Hand-run the code in a couple of sample inputs. Once you are sure you have understood the overall algorithm, add a short paragraph -as comments- to the file summarizing the strategy in abstract terms. Please do not re-state every code statement in words! In task 3, you will modify these two methods to fit your specific needs there.

Task 2: School.java

In this file define a class, School, to store information about a single graduate school program. A School instance has the following properties:

In the definition of the School class, each of the above properties should be represented as a private instance variable. You can assume that the value of each of the ratings above is an integer in the range [1 .. 10]. Add two more instance variables to your School class:

Your task: (Please add the code in the following order!)

  1. Set up the instance variables, according to the discussion above.
  2. Provide a constructor to create instances of School objects, given values for the four properties.
  3. Provide means for printing an instance of type School.
  4. Provide getters (accessors) for all the private instance variables in the School class.
  5. Provide a method, computeRating(), that computes the overall rating of a School instance and sets the appropriate instance variable (overall rating). Different users may value each of the ranking factors (academic programs, research and publications) differently. The method definition should reflect that. In particular, the method should take three weights, with values in the integer range [1 .. 5], to be associated with each of the three evaluation factors. Then, it should compute the overal rating as the weighted sum, Σ(weight * factor), of the three evaluation factors, and set the overall rating accordingly.
  6. As always, add a main() method to test your work.

Task 3: GradSchools.java

In this file define a new class, GradSchools, that stores information about a collection of School objects. Use an array as the container for the School objects. Once the user enters her weights for Academics, Research and Publications, the program computes the overall rating for all schools in the collection, as the weighted sum of the three rating factors. Then, it sorts the schools according to each one of the ranking factors, and prints the results. (See the Sample run provided at the end of this document.)

Your task: (Please add the code in the following order!)

  1. Set up the appropriate instance variables in the GradSchools class.
  2. Provide a constructor for the GradSchools class.
  3. Provide means for printing an instance of type GradSchools. (Hint: This method should implicitely use the printing method in the School class!)
  4. Define a method, addSchool(), that adds a School instance to the collection.
  5. Define a method, computeRatings() that computes the overall rating for all schools in the collection, based on the three weights that are passed as parameters to it.
  6. Provide a method rankSchools() to rank-order all the schools in the collection, based on its input factor. The input to the method should be a String, specifing one of the three ranking factors (academics, research, publications), or the overall rating, to be used as the criterion for ranking. For example, suppose that a GradSchools object has been created named myGradSchools. The method call
    > myGradSchools.rankSchools("Academics")
    might result in a printout like the following:

    Ranking of schools from highest to lowest using "Academics" as the factor:
    MIT
    CMU
    Stanford
    Univ. of Illinois
    UC Berkeley
    Univ. of Washington
    Cornell
    Princeton

    The method call
    > myGradSchools.rankSchools("Overall")
    might result in a printout like the following:

    Ranking of schools from highest to lowest using "Overall" as the factor:
    Stanford
    CMU
    MIT
    Univ. of Illinois
    UC Berkeley
    Cornell
    Princeton
    Univ. of Washington

    Notice that the names of the schools are printed in order from highest to lowest rank.

    The rankSchools() method stores each school's rating value for the desired factor into the school's rank value instance variable. Then, the sorting process uses the rank value to sort the School objects in the array. At the end, the method prints the names of the ranked schools. It is advisable that rankSchools() method calls a sorting helper method to sort the array of schools based on their rank value. Use the sorting method you worked with in Task 1 as your starting point in writing the method that sorts the array of School objects. You only need to make few modifications to the method that sorts an array of integers, in order to make it sort an array of School objects! (Feel free to make changes to the arguments of the method, or make it an instance method, as opposed to a class one, as it fits your needs.)

  7. Finally, add a main() method with code to test the methods defined in the GradSchools class. Add test cases to thoroughly test your code, including calls to the method rankSchools().

What to turn in

On the day the assignment is due, bring to class a hardcopy of your final .java code files. Also, drop off an electronic copy of your code files by connecting to your personal account (cd to your drop dir) and executing the following command:

submit cs230 GradSchools *.*

Note: Be sure to include top-of-the-file comments in each of your code files.

But I do not care about Grad School Ratings!

No problem; you can rank movies. But you need to understand the problem first and keep the overall idea and complexity above. For example, replace School with Movie and GradSchools with Classics. You should also replace the rating categories accordingly (e.g., you can use plot quality, cinematography and societal impact.). Ask us if you want to do that and it is not clear.

Samle run

Assign2 tm$ java GradSchools
Please provide 3 weights (1..5) for Academics, Research and Publications

Assign2 tm$ java GradSchools 3 5 4
There are 4 schools in the database:

 Name: MIT
 Rating of Academics: 10
 Rating of Research: 10
 Rating of Publications: 7
 Overall rating: 108
 Current rank value: 0

 Name: Stanford
 Rating of Academics: 8
 Rating of Research: 10
 Rating of Publications: 9
 Overall rating: 110
 Current rank value: 0

 Name: CMU
 Rating of Academics: 7
 Rating of Research: 8
 Rating of Publications: 6
 Overall rating: 85
 Current rank value: 0

 Name: UC Berkeley
 Rating of Academics: 9
 Rating of Research: 9
 Rating of Publications: 9
 Overall rating: 108
 Current rank value: 0

Ranking of schools from highest to lowest using Acedemics
MIT
UC Berkeley
Stanford
CMU

Ranking of schools from highest to lowest using Effectiveness of Research
Stanford
MIT
UC Berkeley
CMU

Ranking of schools from highest to lowest using Pubs
UC Berkeley
Stanford
MIT
CMU

Ranking of schools from highest to lowest using Overall
Stanford
MIT
UC Berkeley
CMU