1
e02
CS56 m18
DO NOT WRITE IN THIS AREA! Name: Seat:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu

EXAM: e02: Final Exam

ready? date points
true Wed 09/12 09:30AM

You may not collaborate on this exam with anyone. If you need to use the restroom, you must leave your cell phone with the exam proctor before leaving the room.

  • Write your name at the top of this page AND EVERY ODD NUMBERED PAGE.
  • Double check that you turned in ALL pages; look for "End of Exam" on the last page.
  • This exam is closed book, closed notes, closed mouth, cell phone off.
  • You are permitted one sheet of paper (max size 8.5x11") on which to write notes.
  • This sheet will be collected with the exam, and might not be returned.
  • Please write your name on your notes sheet.

  1. For this question, you need page 1 of handout A with code for these files: Beverage.java, Edible.java, Food.java, FreeCandy.java and Product.java. These are classes used by a grocery store known as “Trader Bobs”.

    Some of these methods will compile and run, while others will not.

    Indicate, for each method, whether it compiles or not, and if it does compile, the output when invoked. in context of the classes on handout A and assuming the methods appear inside this class:

    public class TraderBobs {
     // methods appear here
    }
    
    Will it compile?Output when called (only if it compiles)
    Yes
    No
    1. (2 pts)

          public static void TB11 () {
              Product p11 = new Product(199,"Bandaids");
              System.out.println("p11: " + p11.getPrice());
          }
      
    2. (2 pts)

          public static void TB12 () {
      	Product p12 = new Beverage(399,"Root Beer",200,12.0);
              System.out.println("p12: " + p12.getCalories());
          }
      
  2. Continued from previous problem…

    Some of these methods will compile and run, while others will not.

    Indicate, for each method, whether it compiles or not, and if it does compile, the output when invoked. in context of the classes on handout A and assuming the methods appear inside this class:

    public class TraderBobs {
     // methods appear here
    }
    
    1. (2 pts)

          public static void TB13 () {
              Edible e13 = new FreeCandy(15);
              System.out.println("e13: " + e13.getCalories());
          }
      
    2. (2 pts)

          public static void TB14 () {
              Edible e14 = new Food(249,"Cottage Cheese",240,8.0);
              System.out.println("e14: " + e14.getWeight());
          }
      
    3. (2 pts)

          public static void TB15 () {
              Edible e15 = new Food(249,"Cottage Cheese",240,8.0);
              System.out.println("e15: " + e15.getWeight());
          }
      
    4. (2 pts)

          public static void TB16 () {
      	Edible e16 = new Food(349,"Dill Pickles",100,16.0);
              System.out.println("e16: " + e16.getCalories());
          }
      
  3. Continued from previous problem…

    Some of these methods will compile and run, while others will not.

    Indicate, for each method, whether it compiles or not, and if it does compile, the output when invoked. in context of the classes on handout A and assuming the methods appear inside this class:

    public class TraderBobs {
     // methods appear here
    }
    
    1. (2 pts)

          public static void TB17 () {
      	Edible e17 = new Edible() {
      		public int getCalories() { return 10;}
      	    };      
              System.out.println("e17: " + e17.getCalories());
          }
      
    2. (2 pts)

          public static void TB18 () {
              Food f18 = new Food(249,"Cottage Cheese",240,8.0);
              System.out.println("f18: " + f18.getName());
          }
      
    3. (2 pts)

          public static void TB19 () {
              Edible e19 = () -> 25;
              System.out.println("e19: " + e19.getCalories());
          }
      
  4. Answer each of the following questions as if you were in a job interview. Your interviewer has a short attention span, and if you don’t get to the point quickly and clearly, you’ll lose the chance for the job. So make the answers short, but not too short.

    The space shown gives you an idea of the maximum length answer I’m looking for. Your answer should easily fit into the space given.

    1. (6 pts) It is said that design patterns are “discovered, not invented”. What does this mean?

    2. (10 pts) Choose one of the following design patterns, and explain where it is useful, but with an application DIFFERENT from one the one in the Head First Design Patterns textbook.

      That is, choose ONE (and only one of these), and answer it:

      • Explain Strategy without talking about Ducks (or flying or quacking)
      • Explain Observer without taking about a Weather Station
      • Explain Decorator without talking about Coffee (or any Beverages, Condiments or food products).
  5. All classes in Java inherit certain methods from java.lang.Object. There are at least three such methods that are standard “good practice” to override.

    Write a short but complete Java class definition for a class Vehicle that has private attribute licensePlate of type String and capacity of type int (i.e. capacity is the number of passengers that can ride in the vehicle.

    For full credit, include:

    1. (6 pts) Correct syntax for a class that implements java.lang.Comparable<Vehicle> (see bottom of p.2 of Handout A). The comparison should be based on comparing the values of licensePlate. You can assume there are no ties, since license plate values should be unique.
    2. (4 pts) A constructor that takes licensePlate and capacity as parameters
    3. (6 pts) Getters for the two attributes (setters are not needed)
    4. (15 pts) Definitions of three methods that, according to common good Java practice, should be overridden, instead of relying on the default implementation inherited from java.lang.Object: toString,equals and hashCode. (For full credit, include the Java annotation that should be used when overriding a method.)
  6. Using the Vehicle class from the previous example, write a class called Fleet. In this context, the english word “fleet” means “a collection of Vehicles”. The class should have these specifications:

    1. (4 pts) Correct syntax for a class that inherits from java.util.ArrayList<Vehicle>.
    2. (4 pts) A private data member name of type String
    3. (4 pts) Constructor that takes name and sets its value (getters and setters are not needed)
    4. (4 pts) A method with the signature public int totalCapacity() that returns the sum of all of the vehicles in the fleet.
    5. (4 pts) An overloaded toString that returns a string of the form “(Vans 5/40)” where Vans is the value of name, 5 is the number of Vehicle objects in the Fleet (i.e. in the ArrayList), and 40 is the capacity.
  7. In this question, please focus on your web application project.

    Please write clearly; your answer will be graded on clarity as well as content. Minor grammar/spelling errors will not cause deductions, as long as the meaning is clear—errors that make the meaning difficult to understand will result in deductions.

    1. (5 pts) Every application should meet some need that the user has, or help them acheive some goal. What is the name of your app, and what is the goal, or need that a user of your app can get met by using your app?

    2. (5 pts) How did you, personally, make a technical contribution to your team’s success?

      Be specific about your technical contributions. Describe a technical challenge that your team faced in enough detail that it is clear you understood the challenge. Mention enough specifics of either Java code, Maven, Git/Github, HTML, CSS, JavaScript, database technology, Mustache or something else, so that the grader can know that you understand the issues involved. Then describe how you helped to contribute to solving the problem. Be brief, but include “just enough detail” to make it clear that you know what you are talking about.

  8. (5 pts) As in the previous question, please focus on your web application project, and write clearly.

    There are also many non-technical challenges that can arise when trying to work with a team of 4-6 people to build a project. Describe a specfic non-technical challenge (communication, scheduling, coordination, etc.) that arose during your project, and how you overcame it.

    (You do not need to use the entire page; a half-page answer is sufficient. The extra space is there in case you need it for any part of this question, or the preceeding one.)

End of Exam