Mr. Meinzen - Advanced Placement Computer Science - A

"Success is the ability to go from one failure to another with no loss of enthusiasm." Winston Churchill

Lab Assignment : Program 1 : Preparing for AP CSA with Eclipse


Student Name_____________________ Grade ____ / 20 pts

Teacher Name: Mr. John Meinzen,

Optional Summer Assignment. The following will be due on the FIRST WEEK of class:

  1. Review Mr. Meinzen's website for resources and discuss with Mr. Meinzen if you have any questions.
      1. internet access to the course website at:
      2. a flash drive (1GB or larger) with copy of:
        • exemplar labs (code & student guides) retrieved from either
        • official College Board website for AP Computer Science is "" OR
        • G://EHS Courses/AP Computer Science/0-SummerAssignment/1-installAtHome
      3. use of home computer (or laptop) running Microsoft Windows 64 bit. Please see Mr. Meinzen if any of the following exists:
        • access to a computer or laptop at home or
        • access to high speed internet at home or
        • student computer is running a different operating system (Linux, Macintosh, or ?)
    2. ____ [2 pts] EVIDENCE:
      1. Printout of this assignment/grading sheet.
      2. Printout or a screen shot of Mr. Meinzen's APCS webpage [1 page only]
  2. Install Eclipse IDE for Java Developers (Luna or newer) on home computer or laptop
      • using Version: Oxygen.3a Release (4.7.3a) from2018 OR
      • G://EHS Courses/AP Computer Science/0-SummerAssignment/1-installAtHome
    2. ____ [5 pts] EVIDENCE: printout of a screen shot of Eclipse running.
  3. Copy & Install the Exemplar Lab Materials
      1. Copy the folder containing the 3 Exemplar Labs from the student drive:
        • "G:\EHS Courses\AP Computer Science\0-SummerAssignment\LabMaterials"
      2. The LabMaterials folder has 3 separate projects/folders (i.e. 3 labs) along with 3 Student Guide files in .pdf format.
        1. "Magpie Lab" which uses Strings to do Natural Language Processing (NLP) .
        2. "Elevens Lab" which is a card game to help understand Object-Oriented-Program design.
        3. "Picture Lab" which is a Image Processing program to help understand 2-dimensional array/matrix manipulation.
    2. Get each of these lab projects running from within Eclipse:
      1. For Magpie Lab, complete Activity 2. Be ready to answer the question in the Student Guide for Activity 2.
      2. For Elevens Lab, complete Activity 6 which demonstrates playing the game of Elevens. Also, be familiar with the,, and classes as shown in Activity 4 Starter Code. You do NOT have to complete Activity 1-5 before completing Activity 6. If you have completed Poker from Programming in Java or Honors Programming in Java, you do NOT have to do Elevens Lab assignment.
      3. For Picture Lab, read and complete the Student Guide for Activity 1,2 and 3 (A1, A2, and A3). Note that the "pixLab" folder described in the Student Guide is the same as Mr. M's "PictureLab" folder.
    3. ____ [14 pts] EVIDENCE: Screenshot of each lab program running [2 or 3 images on 1 page]

Lab Assignment : Program 1 : Preparing for AP CSA with Eclipse

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/* 0. TRY to use a UserInterface Manager
 * 1. DECLARE a frame, then a panel, then components
 *       a. components are buttons, textfield, labels, menus, etc.
 * 2. CONSTRUCT a frame, then a panel, then components
 *       a. create the components by adding pictures (Icons) if desired
 *       b. have buttons and textfields "listen" for actions
 * 3. CONSTRUCT a layout then ADD to panel
 * 4. ADD components to panel
 * 5. ADD panel to frame
 * 6. Set the Frame to be visible

public class SwingTemplate extends JFrame implements ActionListener
	// frame which is the window with borders, title bar, min/max/exit buttons
	private static JFrame f;

	// panel that will huld the contents (i.e. all the components)
	private JPanel p;

	/*****************************  These are all components */
	// buttons
	private JButton fancyButton;

	// text field
	private JTextField text1;

	// labels
	private JLabel  fancyLabel;
	/*****************************  Ending the components */

	/** this is where we all start
	public static void main(String arg[])
		catch (Exception e)
			// do nothing if a problem...just quit

		// this will really do all the work!
		// it declares and creates a new application
		SwingTemplate app = new SwingTemplate();

		// needed at bottom to of main() to be able to close the application

		// automatically resize window (use instead of setSize)
	} // main()

	/** constructor that creates or instatiates the frame, panel, layout, etc.
	public SwingTemplate()
		// Create the overall window for the application
		f = new JFrame("Swing Template");

		// create the content panel to be put in the frame
		p = new JPanel();

		// set the layout which will be in a grid measuring 3 rows x 2 culumns
		GridLayout layout = new GridLayout(3,2);
		// set whichever layout is chosen above
		p.setLayout( layout);

		// call the following methods so that they will
		// create & add each of the labels, buttons, & textfields
		// to the content panel

		// finally add the content to the window

	/** create and add for the labels to the content panel
	public void addLabelsToContentPanel()
		Icon myPicture = new ImageIcon("butterfly.gif");
		fancyLabel = new JLabel("Fancy Label", myPicture, SwingConstants.LEFT);
		fancyLabel.setToolTipText("toultip for fancy label");

	/** create,add, and attach events for the text fields to the content panel
	public void addFieldToContentPanel()
		text1 = new JTextField(10);     // create the textfield & set size to 10
		text1.setEditable(true);        // the user can change it
		p.add(text1);                   // add it to the content
		text1.addActionListener(this);  // listen for an mouse click

	/** create, add, and attach events for the buttons
	*  to the content panel
	public void addButtonsToContentPanel()

		// create a fancy button with pictures and a rullover
		Icon frog    = new ImageIcon("frog.gif");
		Icon buffalo = new ImageIcon("buffalo.gif");
		fancyButton  = new JButton("Fancy Button", frog);

		// add the button to the content pane then listen for clicks

	/** handle the actions were taken in the application window
	public void actionPerformed(ActionEvent e)
		// if button was pressed change the text field
		if (e.getSource() == fancyButton)
			// swap the text from fancy to plain and back again
			if (text1.getText().equals("fancy"))

		// if the textfield was typed in then change the label
		if (e.getSource() == text1)


} // SwingTemplate

Lab Assignment : Program 2 : Phase 1: Supply and Demand Curves in Economics



  • Start writing an application that simulates the interaction between a consumer and a producer using the Supply and Demand curves from an Economics perspective.
  • From a top-down perspective (i.e. a client/teacher), the programmer (i.e. student) should write the necessary and relevant classes to:
  • "Create a simulation that will demonstrate the negotiations and interaction between a consumer and producer in a market environment. "


Each student will complete each of the following 4 classes:

  • A Point class that describes a"Quantity-Price" ordered pair as discussed in class.
  • A ProducerCurve class that "has a" array of Point's.
  • A ConsumerCurve class that "has a" ArrayList of Point's.
  • an appropriate Test class/application (ideally a JUnit test) that verifies the proper object-oriented properties of the above three classes.


Key features scored include (NOTE: these are "necessary but not sufficient" for a high-score):

  • creation and comparison of Point:
    • override Object's equals(Object) method
    • overload Object's equals(Object) method by defining an equals(Point) method
    • override the toString() method
  • creation of linear curves (increasing for Producer, decreasing for Consumer)
    • addition of a Point to a curve
    • determining if a given Point is on a curve
    • deletion of a Point from a curve
    • override the toString() method


Classes (4 total) will be printed out and turned in. These will be scored according to:

  • style - - choice of identifier names - commenting (javaDoc, multi-line, and single line) - indenting
  • verification of key features: - test each class for key features by using either BlueJ or by writing "TestDriver" program(s).
  • demonstration to your teacher - submit either hardcopy (paper) or softcopy for JUnit testing (requires consistent interface for all APCS to your teacher as he will determine how you will demonstrate your programs correct execution.)


NOTE: The following are clarifications of the assignment based on discussions in class.


Students must be aware that there will be additional clarifications that are based on personal discussions generated from questions asked by individual students. These personal clarifications will NOT be posted as part of this website but can be scored for every student. For example, if one student asks if they should check for out-of-bounds conditions (OOB) , the answer will be "yes" as OOB checks are necessary part of every AP CSA course and will be scored as such.


2018-19 Clarifications of assignment based on discussions in the classroom :

  • // additional constructor for each curve
    public ProducerCurve(int m, int startQuantity, double startPrice, int n)

  • public boolean add(Point p)

  • public boolean remove(Point p)

  • public boolean isOnCurve(Point p)


Lab Assignment : Program 3 : Phase 2 : Abstract Classes and Methods


Based upon your ConsumerCurve and ProducerCurve classes from Programming Assignment 2, complete the following:


Hand Draw a single UML class diagram that combines the two stated classes into a single abstract class called AbstractCurve. The diagram should specify the appropriate common fields and methods as well as specify which method(s) are abstract. This diagram must be approved by your teacher.



  • the curve field "has a" ArrayList of Points
  • sort() method must be abstract
  • a constructor must accept as parameters:
    • int n -- the number of points on the curve
    • double m -- the slope of the curve
    • double b -- the y-intercept of the curve
    • int dx -- the increment along the x-axis (i.e. difference in quantity from one point to the next point]

After approval of the diagram, the AbstractCurve class is to be programmed based upon the diagram and commented appropriately. A program listing is to be printed and turned in.

  • ProducerCurve and ConsumerCurve classes must be re-written (keep old copies!) so that they extend AbstractCurve class. These two curves classes must have all the features of the original classes before the AbstractCurve was written. A program listing is to be printed and turned in
    • ProducerCurve "is a" AbstractCurve
    • the following methods are to be defined: add(Point), toString(), remove(Point), contains(Point)
    • the following method is to be implemented: sort() (and appropriate constructor(s)).
  • A Test class/application must then be generated to test your abstract/concrete classes. This must demonstrate to your teacher that your simulation works to these specifications. A simple application or use of BlueJ is acceptable. However, JUnit test may be given bonus points.
  • A program listing of your Test class is to be printed and turned in .

NOTE: The following are clarifications of the assignment based on discussions in class.

  • Students must be aware that there will be additional clarifications that are based on personal discussions generated from questions asked by individual students. These personal clarifications will NOT be posted as part of this website but can be scored for every student. For example, if one student asks if they should check for out-of-bounds conditions (OOB) , the answer will be "yes" as OOB checks are necessary part of every AP CSA course and will be scored as such.


    2018-19 Clarifications of assignment based on discussions in the classroom :

    • package name: org.ecusd7.ehs.apcsa


      Point class :

      • public static double PRICE_TOLERANCE = 0.01
      • public Point()
      • public Point(int q, double q)
      • public boolean equals(Point p)
      • public boolean equals(Object o)
      • public int getQuantity()
      • public double getPrice()
      • public String toString()


      • private ArrayList<Point> myCurve; // standardized field variable name...accessible only to Curves
      • ?? should ConsumerCurve have a default constructor to create points (1,1), (2,2,)...(10,10) and similar for ProducerCurve??
      • // for all curves need a constructor
        public ...Curve(int n,double m, double b, int dx)
      • public boolean add(Point p)
      • public boolean remove(Point p)
      • public boolean isOnCurve(Point p)
      • public String toString()
      • public void sort()

Lab Assignment : Program 4 : Phase 3: Producer & Consumer Classes

  • Students will write the Producer & Consumer classes with the following specifications:
    • Each will have their own respective Curve. (i.e. Producer "has a" ProducerCurve).
    • Each will have the following method signature as discussed in class:
    • public Point respondToBid(Point)
    • Students will have to add any needed/relevant methods to previous classes to support the above two objectives.
    • Note: unless approved by your teacher, A consumer should NOT have direct access to any ArrayList.
  • Students will start writing a Market class that tests the Consumer and Producer classes:
    • Instantiate a single object each of a Consumer and a Producer (i.e. 2 objects)
    • Create points that test the following 3 scenarios that the consumer (& producer) will respond to:
      • a Point below the curve,
      • above the curve, and
      • on the curve
  • Students will hand in the program listings (3 total) along with any APPROVED changes (i.e. turn in a signed written approval from Mr. M) to prior classes and demonstrate the working classes (i.e. screenshot).

Lab Assignment : Program 5 : Phase 4: Market class


Using the correct Consumer & Producer classes from the previous assignment, students will complete the Market class applications with the following specifications:

  1. instantiate a Consumer (i.e. BestBuyer) and a Producer (i.e. Sonyer)
  2. Instantiate a starting Point as the initial bid to be passed to the Consumer
  3. use the Point respondToBid(Point method in the Consumer to return a response Point that moves towards an equilibrium with the Producer.
  4. pass the response Point in step 3 to the Producer's respondToBid(Point) method and receive a response point from the Producer that moves toward an equilibrium.
  5. Repeat steps 3 & 4 until either the Market detects and prints out an equilibrium point, detects and prints an "out of bounds" condition, or detects an oscillation condition (print out one of the oscillation points).

Students will turn in the listings and demonstrate the working classes at each of the above steps.

  • Output should look like the following:
    • For Producer (10, -1.0,10,1) and Consumer (10,1.0,0,1) the equilibrium point is (5.0,5)
    • For Producer (10, -1.0,100,10) and Consumer (10,1.0,0,2) the equilibrium point could not be reached
Four Simulations are to be tested. [TESTING SCENARIOS TO BE GIVEN ON DUE DATE]

Lab Assignment : Program 6 : Phase 5: The View of Consumer and Producer Curves.


Based upon Program Assignment #3, you will create a new application class that will generate a graphical view of your ConsumerCurve and ProducerCurve (that are extensions of the AbstractCurve class).


The following details will be required and you must turn in to your teacher to be scored:

  • A hand-drawing of a your View. The drawing must be similar to a "screenshot" of your completed application demonstrating where various components (buttons, textboxes, labels, etc.) will be placed. Get approval from your teacher.
    • The center of the screenshot should be a 2-dimensional coordinate system where the x-axis is the quantity and the y-axis is the price.
    • A layout manager is required (see
    • You will need to learn how to draw points, lines and "symbols" from the Java Swing API.
    • The final result should include two linear curves (one with positive slope and another with negative slope) that represents a ConsumerCurve and ProducerCurve .
    • Read Appendix B in textbook or visit the Resource page for more info on doing graphics.

Printout a listing of this application and demonstrate to your teacher.


Lab Assignment : Program 5 : String manipulation with arrays

On the lecture notes based on 1st Qtr-Syntax:Java Overview at about Pages 26-31, there is an Example of String and Array Minipulations. Along with the lecture notes, there is a Scenario and assignment with steps 1-7. Steps 1-3 are already solved and provided in the Starter Code. Your assignment is to copy the Starter Code into Eclipse, understand the Starter Code, and then complete Steps 4-6 and at least one of the Parts from Step 7.