A Design-First Java Curriculum

Total Page:16

File Type:pdf, Size:1020Kb

A Design-First Java Curriculum

Design-First with Java Curriculum

Unit One

Lesson 1a: Introduction to Software Engineering

Analogies:

1. Building a house (What planning/design is done before building begins? What pieces are put together? How many people are involved and what parts does each work on? 2. Building a car (What pre-made "off the shelf" parts are put into it? How many people are involved in the process? What planning/design is done up front?)

Discuss how these processes are similar to building a software system. The developer must understand the requirements (exactly what the program is to do), then must design the program (decide how it will be structured), and last, translate the design into code.

Talk about the different types of software development jobs: systems analysts, who gather and document user requirements, and design how a system should be built, and programmers who write code. Talk about different levels of programming: application programming, writing the code for high level uses like businesses (much of which is being outsourced, or even automated); systems programming, writing lower-level code for operating systems, controlling hardware of all types (less likely to be outsourced)

Instructor Notes: Lesson2.doc Handout: Lesson2Handout.doc

Lesson 1b: Object Orientation

Everything in the real world is an object (a house, a car, a person)

How are individual objects identified?

 Objects may have different characteristics (a car and a house have different components, and "do" different things)  Objects that share the same characteristics have different values for those characteristics (everyone in this class is a person, but each person has a different name)  Objects that share the same characteristics belong to the same category, or class. Individual objects (each person in the room, for example) are also called instances of the class.

Use the Person class as an example, and have the students identify the information about a person (attributes) and the behaviors of a person (methods).

Another example would also be helpful here: perhaps a Car class, where attributes include the Parts of a car (engine, body, wheels, tires), which are also objects. Lesson 1c: Looking at an example in Java

What is a compiler?

Introduce the IDE (Eclipse/DrJava/UML)

Student Exploration #1: Students follow handout to open the Shapes project, then write and execute statements to create shapes and manipulate them using the classes provided (through the Interactions Pane).

Handout: ObjectsEclipse-1.doc

Student Exploration #2: Following handout, students learn to create objects and call methods within a method inside a Java class. Students modify an existing method that uses the shapes classes to draw a picture.

Handout: ObjectsEclipse-2.doc

Student Exploration #3: An extra, advanced activity for students who finish the first two exercises early.

Handout: ObjectsEclipse-3.doc

Unit Two – From Problem Description to UML Class Diagram

Lesson 2: Analyzing a problem description

Learn how to identify classes starting with nouns that have internal properties and behavior. Then identify their attributes and behaviors (methods). Then model a problem domain analysis as a UML diagram. Go through an example, such as an ATM machine, as a class.

Then students begin working on their own solution in pairs, analyzing the problem description for the ATM machine on paper.

Lesson 2b: Designing the TicketMachine Class

Introduce simple UML class diagrams and how to create them in Eclipse plug-in. Explain how to create a project, open a class diagram in the plug-in, create classes, attributes and methods, and the importance of using comments to document each class and each method. Multimedia is also available to introduce this material.

Discuss the problem description for the Movie Ticket Machine problem example (adapted from the Ticket Machine example in Objects First with Java: A Practical Introductions using BlueJ by David Barnes and Michael Kolling) Students develop their own solution for the Movie Ticket Machine, creating a class diagram for the TicketMachine class (Use the Eclipse UML plug-in. It automatically generates the code stubs, which students can modify later.)

Create a list of tests for the TicketMachine class.

Handouts: ClassDesignLesson.doc and CreateProject.doc

Unit Three - The Development Process: Gathering requirements, designing a class, implementing it and testing

Lesson 3a: Gathering requirements

As a class, come up with the requirements of an ATM or a Movie Ticket Machine (What does it do? Think about other types of vending machines and how they work. What are the components of this Ticket Machine, and what does each do?

Introduce Actors and Use Cases: Identify and list all actors. Write use cases for the Ticket Machine (together).

Instructor Notes: UseCaseInstructorNotes.doc Handout: UseCasesHandout.doc Ticket Machine Project: TicketMachineDescription.doc

Lesson 3b: Creating the TicketMachine Class

Generate the code shell in Eclipse.

These concepts are needed to write the inputMoney, returnChange and constructor methods:

 int and double primitive datatypes  basic arithmetic  variables and assignment  constants  comments (Use Javadoc format. When the TicketMachine code is complete, generate the Javadoc for the TicketMachine.)

Handouts: VariablesAndAssignment.doc, VariablesExercise.doc and AssignmentExercise.doc

Lesson 3c: Writing the inputMoney, returnChange, and constructor methods. Testing the TicketMachine class so far.

Step through the logic for the three methods. Emphasize when tests are developed! (They can be written before creating the code for the class!) Write a test plan for the TicketMachine class. Execute the test code in the Interactions Pane in Eclipse.

Handouts: methodImplementation.doc and TMconstructor.doc

Unit Four

Lesson 3a: Character-based Printing and if statements

 System.out.print, println  if-else statements  {} blocks  Relational operators < > <= >= == !=  Nested if statements

Handouts: Printing.doc, PrintExercises.doc, IfStatements.doc, IfStatementExercises.doc

Lesson 3b: Review printTickets use case

Write printTickets code, including all alternatives (not enough money for tickets requested, not enough seats left in theater).

Handouts: printTicketsUseCase.doc, printTicketsPseudocode.doc

Lesson 3c: Completing and testing methods for customer

Review all methods for customer (including get/set methods generated by Eclipse). Students write and execute final test plan, using Interactions Pane.

Lesson 3d: Creating a Character-based User Interface

A simple class for input: EasyReader Creating a TicketMachineInterface class and main to read in initial values for the TicketMachine. Coding and testing the main method

Handout: AddingUI.doc

Lesson 3e: Converting character data to integer and double

Integer.parseInt and Double.parseDouble methods

Handout: DataConversion.doc

Creating a simple menu for the customer

Handout: CustInterface.doc Unit Five

Lesson 5a: Loops do-while loop while loop

Handouts: loops.doc, loops2.doc

Students write the code to keep displaying the customer menu until an ending condition is met.

Lesson 5b: Scope of variables

Use example from TicketMachineInterface. Students had been declaring variables where they are used. Discuss pros and cons of declaring variables at the top of a method, outside a block, etc.

Handouts: scope.doc, scopeExercises.doc

Lesson 5c: String as a class

String methods. Comparing Strings. Removing one char at a time from a String.

Handout: StringMethods.doc

THIS MARKS THE END OF THE TICKET MACHINE PROJECT. STUDENTS NOW COMPLETE ALL CODING AND TESTING OF THE FINAL VERSION BEFORE MOVING ON TO THE GROUP PROJECT.

Group project: Creating a calculator. At this point, students follow the same design and development process as for the Ticket Machine. Students should not base the functionality on what they already know how to code, but should think solely about what the calculator should do. (These operations should include addition, subtraction, multiplication, and division with two or more operands. The instructor may limit the scope, although a few more advanced operations like square root are not unreasonable.)

Handout: CalculatorProject.doc

Deliverable #1: Use cases.

Handout: CalculatorWorksheet1.doc

Deliverable #2: Class diagram (including attributes and method definitions) in Eclipse.

Deliverable #3: All Calculator methods coded and unit tested (testing demonstrated to instructor). Deliverable #4: Character-based Interface.

Handout: CalculatorInterface.doc

Unit Six Graphical User Interface

Lesson 6a: Simple Dialog Boxes using JoptionPane

Convert input of TicketMachine's initial values to Dialog Boxes using JOptionPane.showInputDialog().

Handout: GUI1.doc

Lesson 6b: Creating a frame with text objects

JFrame and Container classes JTextField and commonly used methods JLabel JButton

Activity: Students redesign the Calculator interface to use text fields and buttons. Students create new CalculatorInterface class to display it.

Handout: GUI2.doc

Lesson 6c: Tying action to text fields and buttons

ActionListener interface, building your own Listener class actionPerformed method Connecting Listener class to a field Exercise: Implement a listener for a simple program that adds two numbers.

Handouts: GUI3.doc,GuiSum.java

Tying a listener to a button. Exercise: Expand previous example program to add and subtract.

Handout: GUI4.doc

Group Project: Students complete their new graphical Calculator interface. Deliverable #5: Calculator application with a graphical interface.

Lesson 6d: The Sun Java documentation Package and class lists How to read the documentation for a class Finding what you need

Handout: sunJavaDoc.doc

Deliverable #5a: Graphical calculator with a "square root" button added.

Lesson 6e: Converting an application to an applet

Differences between applets and applications. The Applet class. Invoking an applet from HTML.

Handouts: applet1.doc, applet2.doc

Deliverable #6: Calculator run as an applet.

Author: Sally Moritz with input from Glenn Blank and Chad Neff, last modified June 16, 2005 Modified by Glenn Blank, June 6, 2006.

Recommended publications