Test. A software house decides to develop a DVD renting program. The product manager identifies the following requirements: Every DVD will have a title,

Slides:



Advertisements
Similar presentations
13 X 11 Java Lecture 3 CS 1311 Structure 13 X 11.
Advertisements

Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
19-Jun-15 Access to Names Namespaces, Scopes, Access privileges.
IEG 3080 Tutorial 1 Wilson Ip. Outline Lecture reviews: Some basics of Software Engineering principle Some basics of OOP How to use Visual Studio.NET.
Abstract Classes and Interfaces
Chapter 9 Domain Models 1CS6359 Fall 2012 John Cole.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
1 Exercise /* A lockbox can be open or closed. If closed, only a valid password will open the box. Once the box is open, the contents can be retrieved.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Consolidation. Code making (i.e. making ciphers) is undertaken by a cryptographer whereas cryptanalysts try to break ciphers in order to gain intelligence.
F27SB2 Software Development 2 Lecture 4: Java GUIs 3.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
CMSC 202 Generics. Nov Generalized Code One goal of OOP is to provide the ability to write reusable, generalized code. Polymorphic code using.
Chapter 1 - Getting to know Greenfoot
Inheritance (Part 4) Abstract Classes 1.  sometimes you will find that you want the API for a base class to have a method that the base class cannot.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
Programming in Java CSCI-2220 Object Oriented Programming.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
CS2110: SW Development Methods Inheritance in OO and in Java Part 2: Topics: Forms of inheritance Interfaces in Java.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
Refactoring II Dealing with Polymorphism. Switch in Rental Switches on Movie! class Rental … public double getCharge() { double result = 0; switch (getMovie().getPriceCode()){
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© 2006 Pearson EducationDesign Patterns1 of 20 A Final Example: A Traffic Light Let’s model a traffic light! – here’s the spec: Have a column of two circles.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
 Columns  Rows  Cells  Ranges  Cell addresses  Column headers  Row headers  Formulas  Spreadsheet.
Creating a GUI Class An example of class design using inheritance and interfaces.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Lecture Model View Controller s/w architecture AND general tips on structuring classes.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
CS/ENGRD 2110 SPRING 2016 Lecture 2: Objects and classes in Java 1.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 3 – Extending classes.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
OOP Basics Classes & Methods (c) IDMS/SQL News
Unified Modeling Language (UML)
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
A High Flying Overview CS139 – Fall 2010 How far we have come.
Refactoring (1). Software Evolution Cope with change Feature bloat Design decay Code duplications “Pattern time is refactoring time” Make future changes.
A (Very) Simple Example Consolidate duplicate conditional fragments if (isSpecialDeal()) { total = price * 0.95; send (); } else { total = price * 0.98;
CSC 205 Programming II Lecture 5 AWT - I.
CompSci 230 S Programming Techniques
Module Road Map Refactoring Why Refactoring? Examples
CompSci 230 Software Construction
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Object Oriented Programming
CS139 – Fall 2010 How far we have come
Overview of Eclipse Lectures
lecture 08, OO Design Principle
Week 6 Object-Oriented Programming (2): Polymorphism
Introduction to TouchDevelop
This is a setup file for a Jeopardy game.
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
This is a setup file for a Jeopardy game.
Constructors, GUI’s(Using Swing) and ActionListner
This is a setup file for a Jeopardy game.
This is a setup file for a Jeopardy game.
CMPE212 – Reminders Assignment 2 due next Friday.
Plug-In Architecture Pattern
Presentation transcript:

Test

A software house decides to develop a DVD renting program. The product manager identifies the following requirements: Every DVD will have a title, one or more actors, a production studio, a SIN (Standard Identification Number), and a rental charge (see below). Initially, the system will deal with three categories of DVD: Children, New Release and Regular. The rental charge for each is different: Children: These DVDs cost £1.50 for the first three days of renting and then £1.50 for each further day. New Release: These DVDs cost £3 for every rental day. Regular: These DVDs cost £2 for the first two days of renting and then £1.50 for each further day. The program must handle new categories of DVD in the future with minimal change to existing code. The chief designer of the DVD renting program asks you to design the classes that will represent the DVDs based on the above requirements. Finally, the chief designer indicates that it will be necessary to serialize the objects in the system so that they can be sent across the network or stored in a file. The chief designer has also provided you with two interfaces HAS-A IS-A NO NEED FOR AN APPLICATION – BUT NOT WRONG YOU HAVE TO USE THESE

public interface Price extends Serializable{ public double getCharge(int daysRented); } public interface Dvd extends Price{ public String getTitle(); public void setTitle(String title); public String getSin(); public void setSin(String sin); public Actor[] getActors(); public void setActors(Actor[] actors); public String getStudio(); public void setStudio(String studio); }

Remember! Interfaces cannot HAVE data Minimise duplication – the kinds of Dvd must inherit from something You may override methods at a lower level

Some attempts might include Having all three types of Dvd implement the interface – but then duplication

DON’T FORGET THE ACTORS! getCharge() is different for the 3 kinds of Movies – rest of methods and all attributes are same

Dvd and Price interfaces were included since they were specified. By making Price extend Serializable, we know that most of our classes will implement the interface. Actor is also made to implement Serializable. The Movie class has been made abstract and implements the Dvd interface. It is abstract so that common attributes and code can be defined in one place. All the setter methods are common to all movies. A Movie has many Actors. It is only the getCharge method that changes, and indeed could itself be defined as abstract in the Movie class. The three concrete subclasses override getCharge() and the right one will be called at runtime, depending on the kind of Movie. It will be very easy to plug in further kinds of movie in the future by simply extending Movie. Note that getCharge method should really return a BigDecimal rather than than a double. It is more precise since double arithmetic will result in loss of precision, which is critical in this application.

Test some things – USE methods public class DvdTester { public static void main(String [] args){ Dvd nr1 = new NewRelease("No Place For Old Men"); Dvd r1 = new Regular ("Men In Black"); Dvd c1 = new Childrens ("Shrek"); System.out.println(nr1.getTitle() + ‘ ‘ + nr1.getCharge(2)); System.out.println(r1.getTitle() + ‘ ‘ + r1.getCharge(3)); System.out.println(c1.getTitle() + ‘ ‘ + c1.getCharge(4)); }

Code that IMPLEMENTS the getCharge method or methods public abstract Class Movie implements Dvd {... public abstract double getCharge(int days);... } public class NewRelease extends Dvd public double getCharge(int days) { return days * 3; }... } public class Childrens extends Movie public double getCharge(int days) { if (days > 3){ return (days - 3) * ; } else { return 1.5; } public class Regular extends Dvd public double getCharge(int days) { if (daysRented > 2){ return (days - 2) * ; }else{ return 2; }

An object representing a particular category of DVD can have its category changed at run time, without the need to create a new object, for example, a New Release DVD becomes a Children’s DVD after so many days Note that now the Movie has an attribute of Price – which can be any of the particular implementing prices

What next Tomorrow – I will talk about assignment for people who are really stuck We may have no 124 lectures on Friday?? There will be an exam review lecture in May We plan to issue the problem for PART OF the exam towards the end of this month so you will have a little while to think about it

Assignment

Have you started the assignment? 2 Views of the same Model class

How to start Implement the interface (add a few more methods – like how are you getting the thing to guess into the Model?) Write a driver and an application with a simple menu to run its methods – this is essentially the text based game Also write JUnit tests Then look at GUI – Life and Bank in Topic00 examples are a good place to start Run system tests

So, you need to write a Model class that allows you to put in a String – that will be the hidden thing, e.g. “hello” maybe done with constructor? Also probably stores: the visible thing - to start with that would be “*****” And the number of guesses left – 10 to start And (probably as a String?) the letters they have guessed so far – to start with that might be “”

Text based Application – must have a link to the Model and the Model must have a word in it runMenu() is something like while (model.guessLeft()>0) { S.o.p(“guess word or letter”); read answer if answer is letter read letter if (model.tryThis(letter)) break; // you have a winner else S.o.p(“no sorry – try again”) else if answer is word read word if (model.tryWord(word)) break; // you have a winner else S.o.p(“no sorry – try again”) } if (model.guessLeft()==0) //say something nasty else //say something nice

Something that extends JFrame PicturePanel a JPanel with a picture in it TopPanel - another JPanel with Buttons and Labels and TextFields in it In background a Listener has to listen to the button presses and then in an actionPerformed() method modify the Model and the PicturePanel (the JFrame or the TopPanel could be own Listeners – or have separate one) the Model

Keep it simple and build a bit at a time Use ‘stubs’ methods that just print ‘now trying letter X’ for instance I’d probably first always use a Model with the same word in it – when all methods work add reading from a file and picking a random one Same with GUI you can print ‘now clicked letter button’ or pop up a MessageDialog like in the Bank Leave enough time to make a jar file & document