CS 222 Spring 2016

MVC Pattern Challenge

Due: April 13, Wednesday, 10:30 am.

Language: Java

Submission:

  • Check your file encoding. It should be UTF-8
  • Checkout the project inClass_refactoring from SVN to get started
  • Commit your code to SVN at the end of the class

Assignment Explanation

Consider this scenario: There is a school festival. In this school festival there are many schools. And each school has many stands. Students sell small items in these stands. The code that will be provided to you simulates a very small portion of this scenario: It displays stands of a school along with information about the stands.

Task

  • Apply MVC principle to the code given to you.
  • The code works but it does not display anything. Hence, you’re also expected to write code to display stands and information about stands. However, stands along with their information are already provided in the code, thus, your task is just to display them decently.
  • Refactor your code. In addition to appropriate naming, clean and short and well-defined functions, apply what you have learnt from formatting lecture. Make sure that you don’t have any code smells in your code.
public class Stand {
  private String standName;
  private String itemSold;
  private double itemPrice;

  public Stand(String standName, String itemSold, double itemPrice) {
    this.standName = standName;
    this.itemSold = itemSold;
    this.itemPrice = itemPrice;
  }

  public String getStandName() {
    return standName;
  }

  @Override
  public String toString() {
    return "Sells " + itemSold + " with price " + itemPrice;
  }
}

public class School {
  private String name;
  private ArrayList<Stand> stands;

  public School(String name) {
    this.name = name;
    this.stands = new ArrayList<Stand>();
  }

  public void addStand(Stand stand) {
    stands.add(stand);
  }

  public String getName() {
    return name;
  }
}

Here is how the code provided to you will look like:

Without MVC & Code to display stand info

This is how it should look like when you’re finished with it: School Festival 2

School Festival

Grading

  • MVC and displaying required information decently (26)
  • Writing clean code (9)

Penalties:

  • Submitting code that is not compiling: -15 points
  • Submitting code that is not runnning correctly: -10 points