Advanced Programming - CS239

Similar documents
Chapter 6 Lab Classes and Objects

Chapter 9 Lab Text Processing and Wrapper Classes

CS 101 Fall 2005 Midterm 2 Name: ID:

Chapter 6 Lab Classes and Objects

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 101 Fall 2006 Midterm 3 Name: ID:

Software and Programming 1

Chapter 4 Defining Classes I

Simple Component Writer's Guide

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS 101 Fall 2006 Midterm 1 Name: ID:

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Guessing Game with Objects

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS 101 Spring 2006 Final Exam Name: ID:

CS 251 Intermediate Programming Methods and Classes

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

CS 251 Intermediate Programming Methods and More

CS313D: ADVANCED PROGRAMMING LANGUAGE

Handout 7. Defining Classes part 1. Instance variables and instance methods.

Introduction to Computer Science I

CS 139 Practice Midterm Questions #2

TaxiBot New attributes Variables Math! TaxiBot

Lab 4. Since this lab has several components in it, I'm providing some guidance to keep everyone

public static boolean isoutside(int min, int max, int value)

3.1 Class Declaration

CS 302 Week 9. Jim Williams

Programming overview

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE


Computer Programming, I. Laboratory Manual. Final Exam Solution

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

CS111: PROGRAMMING LANGUAGE II

CSE 11 Midterm Fall 2008

H212 Introduction to Software Systems Honors

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Lec 3. Compilers, Debugging, Hello World, and Variables

CS 159 Midterm #1 Review Questions

CS 61B, Spring 1999 MT3 Professor M. Clancy

EECS168 Exam 3 Review

Object Oriented Programming

CPS109 Lab 7. Source: Big Java, Chapter 7 Preparation: read Chapter 7 and the lecture notes for this week.

Practice Questions for Chapter 9

Class, Variable, Constructor, Object, Method Questions

Homework Set 2- Class Design

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

COE318 Lecture Notes Week 10 (Nov 7, 2011)

(a) in assignment statements. (b) when invoking methods (with objects as parameters) (d) equality of references versus equality of objects

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

CS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015. Name: Umail umail.ucsb.edu. Circle one: 4pm 5pm 6pm

Use the Scantron sheets to write your answer. Make sure to write your Purdue ID (NOT Purdue Login ID) and your name on the Scantron answer sheet.

CS 455 Midterm Exam 1 Fall 2017 [Bono] Thursday, Sep. 28, 2017

Computer Science II (20082) Week 1: Review and Inheritance

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

Exam 1 - (20 points)

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Assertions, pre/postconditions

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Defining Your Own Classes

Programming - 2. Common Errors

COMP Assignment #4 (Due: Mon. Mar 12 noon)

Key Java Simple Data Types

Tutorial 2 Today we will have a quick introduction to ArgoUML and how to use it, as well as look at some examples of class diagrams.

CSE 113 A. Announcements - Lab

An introduction to Java II

Media Computation. Lecture 16.1, December 8, 2008 Steve Harrison

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this.

CS : Data Structures

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

APCS Semester #1 Final Exam Practice Problems

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

1/27/2014. OO design approach with examples. UML and project clarifications (2) Project clarifications 1. UML

Electronically Filed - City of St. Louis - May 27, :02 PM

CS 101 Exam 2 Spring Id Name

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

VARIABLES AND TYPES CITS1001

CSE 11 Midterm Fall 2012

University of Palestine. Mid Exam Total Grade: 100

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

CS 617 Object Oriented Systems Lecture 5 Classes, Classless World:Prototypes, Instance Variables, Class Variables, This/Self 3:30-5:00 pm Thu, Jan 17

Computer Programming: C++

Binghamton University. CS-140 Fall Unit Testing

CS260 Intro to Java & Android 03.Java Language Basics

I. True/False: (2 points each)

CS 170 Java Programming 1. Week 12: Creating Your Own Types

PROGRAMMING FUNDAMENTALS

This exam is open book. Each question is worth 3 points.

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

CS 302: Introduction to Programming in Java. Lecture 15

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean

Public-Service Announcements

Transcription:

Advanced Programming - CS239 Department of Computer Science LAB: EXPERIMENTING WITH SPECIALIZATION Getting Ready: Before going any further you should: 1. Make a directory on your N: drive for this lab. 2. Setup your development environment. 3. Download Clock.class and icon.gif, and put them in your working directory. The documentation for the Clock class is available at javadocs/clock.html. Part I: In this part of the lab you will use an existing class. 1. Write a driver that constructs two clocks, one for Harrisonburg and one for Paris. 2. Compile and execute your driver. Part II: In this part of the lab you will specialize an existing class. 1. Create a file named AlarmClock.java that contains the following: A GUI window that contains an alarm clock with a digital display @author @version 1.0 public class AlarmClock extends Clock private boolean on; private int hour, minute, second; private String ampm; Default Constructor public AlarmClock() Explicit Value Constructor Constructs a clock for a particular city, setting the time zone appropriately

@param city The city public AlarmClock(String city) 2. Modify the two constructors in the AlarmClock class so that they call the appropriate constructors in the Clock class. 3. Modify your driver so that the clock for Harrisonburg is actually an AlarmClock object. 4. Compile and execute your driver. 5. Add the following to your AlarmClock.java class: Set the alarm @param hour The hour of the alarm @param minute The minute of the alarm @param second The second of the alarm @param ampm "AM" for before noon, "PM" for noon and after public void setalarm(int hour, int minute, int second, String ampm) Turn the alarm off public void turnalarmoff() on = false; Turn the alarm on public void turnalarmon() on = true; and complete the setalarm() method (i.e., set the attributes appropriately). 6. Add the following to your AlarmClock.java class: Update the time displayed on the clock

public void updatetime() int hournow, minutenow, secondnow; String ampmnow; // Call the parent's version of updatetime() // If the alarm is on, get the current hour, minute // second, and ampm and check to see if the alarm // should sound now and complete the udpatetime() method. 7. Modify your driver so that it sets the alarm (for a time about a minute in the future) and turns the alarm on. 8. Compile and execute your driver. 9. What happens (or doesn't happen) if you comment out the call to the parent's updatetime() method? Part III: In this part of the lab you will think about specialization in Java, and what kinds of errors you might encounter when you compile classes that you develop. 1. Create a file named Tester1.java that contains the following: A Driver for testing the Clock and AlarmClock classes public class Tester1 The enty point of the application @param args The command line arguments AlarmClock home; Clock paris; home = new AlarmClock(); paris = new Clock("Paris"); setup(home); setup(paris); Setup a Clock @param clock The clock to setup private static void setup(clock clock) clock.reversecolors();

2. The setup() method has a Clock as a formal parameter but is actually passed an AlarmClock. Will this class compile? If so, why? If not, why not? 3. Create a file named Tester2.java that contains the following: A Driver for testing the Clock and AlarmClock classes public class Tester2 The enty point of the application @param args The command line arguments AlarmClock home; Clock paris; home = new AlarmClock(); paris = new Clock("Paris"); setup(home); setup(paris); Setup a clock @param clock The clock to setup private static void setup(clock clock) clock.reversecolors(); clock.turnalarmon(); 4. Will this class compile? If so, why? If not, why not? 5. Create a file named Tester3.java that contains the following: A Driver for testing the Clock and AlarmClock classes public class Tester3 The enty point of the application @param args The command line arguments AlarmClock home;

Clock paris; home = new AlarmClock(); paris = new Clock("Paris"); setup(home); setup(paris); Setup a clock @param clock The clock to setup private static void setup(alarmclock clock) clock.reversecolors(); clock.turnalarmon(); 6. Will this class compile? If so, why? If not, why not? 7. Create a file named Tester4.java that contains the following: A Driver for testing the Clock and AlarmClock classes public class Tester4 The enty point of the application @param args The command line arguments Clock home, paris; home = createclock("harrisonburg"); paris = createclock("paris"); Create and setup a Clock @param clock The clock to setup private static AlarmClock createclock(string city) AlarmClock temp; temp = new AlarmClock(city); temp.reversecolors(); return temp;

8. The createclock() method creates and returns AlarmClock objects that main assigns to Clock objects. Will this class compile? If so, why? If not, why not? 9. Create a file named Tester5.java that contains the following: A Driver for testing the Clock and AlarmClock classes public class Tester5 The enty point of the application @param args The command line arguments Clock home, paris; home = createclock("harrisonburg"); paris = createclock("paris"); home.setalarm(1, 39, 45, "PM"); home.turnalarmon(); Create and setup a Clock @param clock The clock to setup private static AlarmClock createclock(string city) AlarmClock temp; temp = new AlarmClock(city); temp.reversecolors(); return temp; 10. Will this class compile? If so, why? If not, why not? Copyright 2004