Homework Set 2- Class Design

Similar documents
AP Computer Science Homework Set 2 Class Design

AP Computer Science Homework Set 2 Class Design

AP Computer Science Homework Set 3 Class Methods

AP Computer Science Homework Set 5 2D Arrays

AP Computer Science Homework Set 5 2D Arrays

AP Computer Science Homework Set 1 Fundamentals

Homework Set 1- Fundamentals

AP Computer Science Homework Set 3 Class Methods

Object Oriented Design: Identifying Objects

Activity 11: Designing Classes

Guessing Game with Objects

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

CS 61B, Spring 1999 MT3 Professor M. Clancy

Exam Duration: 2hrs and 30min Software Design

More about inheritance

DATA STRUCTURES CHAPTER 1

CS211 Prelim Oct 2001 NAME NETID

CO Java SE 8: Fundamentals

CLASS DESIGN. Objectives MODULE 4

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology

Programming Assignment Unit 7

Programming Problems 22nd Annual Computer Science Programming Contest

AP Computer Science Homework Set 1 Fundamentals

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

CSC Java Programming, Fall Java Data Types and Control Constructs

Polymorphism. return a.doublevalue() + b.doublevalue();

JOptionPane Dialogs. javax.swing.joptionpane is a class for creating dialog boxes. Has both static methods and instance methods for dialogs.

Distributed Systems Recitation 1. Tamim Jabban

Chapter 4 Defining Classes I

Chapter 4: Control structures. Repetition

2. [20] Suppose we start declaring a Rectangle class as follows:

Guessing Game with Objects

Classes. Classes (continued) Syntax The general syntax for defining a class:

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

Project #2: Linear Feedback Shift Register

Chapter 4: Control structures

CMSC 132: Object-Oriented Programming II. Interface

Advanced Programming - CS239

University of Palestine. Mid Exam Total Grade: 100

COS 126 General Computer Science Spring Written Exam 1

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Orifice Flow Meter

Subclassing for ADTs Implementation

Distributed Systems Recitation 1. Tamim Jabban

Java Fundamentals (II)

Lesson 5 Cloud Upload

In this lecture Simple List Algorithms

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Creating Java Programs with Greenfoot

Introduction to Programming Using Java (98-388)

JAVA WRAPPER CLASSES

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

CS162: Introduction to Computer Science II. Primitive Types. Primitive types. Operations on primitive types. Limitations

Back public class HelloWorld { public static void main ( String arg[] ) { Front Basic Setup. Java Quick Sheet. ~ 35 Flashcards. 1 AP CS - Rodriguez

Defining Your Own Classes

CMSC131. Library Classes

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

Full file at

Lesson 2.4 Arraylist

Classes. Brahm Capoor

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1

EXAM Computer Science 1 Part 1

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 4

SYSC Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

BEFORE WE GET STARTED. BASIC TERMS TO KNOW JavaScript Python Basic Syntax Object String Functions Arguments Property While- Loops Varibles

CS162 Computer Science I Fall 2018 Practice Exam 1 DRAFT (9 Oct.)

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

C12a: The Object Superclass and Selected Methods

Find the flaw. Also show a timing diagram that indicates the sequence of actions for several interleavings.

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

CS 302: Introduction to Programming in Java. Lecture 15

ITI 1120 Lab #9. Slides by: Diana Inkpen, Alan Williams, Daniel Amyot Some original material by Romelia Plesa

Software Systems Development Unit AS1: Introduction to Object Oriented Development

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

JAVA Programming Language Homework II Student ID: Name:

CS 200 More Classes Jim Williams, PhD

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

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

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

Java Identifiers, Data Types & Variables

C a; C b; C e; int c;

Computer Sciences 302 Exam 2 Information & Sample Exam

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

Exam 1 - (20 points)

CS111: PROGRAMMING LANGUAGE II

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

Objectives for this class meeting. 1. Conduct review of core concepts concerning contracts and pre/post conditions

Final Exam CS 251, Intermediate Programming December 13, 2017

CS61B Lecture #2. Public Service Announcements:

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

Activity 3: Data Types

CMP-326 Exam 2 Spring 2018 Total 120 Points Version 1

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Object Oriented Programming. Java-Lecture 6 - Arrays

CS 1331 Exam 1 ANSWER KEY

Transcription:

1 Homework Set 2- Class Design By the end of the lesson students should be able to: a. Write the Java code define a class, its data members, and its constructors. b. Write a tostring() method for a class. c. Write the Java code that uses the new operator to instantiate an object. d. Write the Java code for a driver class that creates instance of an object and initializes the class instance variables and calls the class tostring() method.

P2A P2A. Write a class Song that stores information about a song. Class Song should include at least three instance variables that represent characteristics of the song. Include a zero-argument and three-argument constructor to initialize all instance variables. It should also have a tostring() method to display the object s instance variables in a user-friendly format. Write a separate SongDriver class to: a) create an instance of a Song called song1 using its zero-argument b) display the instance variables of the song1 using the object s tostring() method, c) create an instance of a Song called a song2 and initialize its instance variables using the object s multi-argument and d) display the instance variables of the song2 using the object s tostring() method. 2

3 P2B P2B. Write a class Alarm that stores information about a clock alarm. It should have integer instance variables for the Alarms s hours, minutes, seconds. Include a zero-argument and three-argument constructor to initialize all instance variables (hour, min, sec). It should also have a tostring() method to display the time in the format shown below: Wake up time is 3:45:16 Write a separate AlarmDriver class to: a) create an instance of a Alarm clock called phonealarm using its zeroargument b) display the time of the phonealarm using its tostring() method, c) create an instance of a Alarm called a bedroomalarm and set the hours, minutes, and seconds using the Alarm s three-arguments constructor using a JOptionPane, and d) display the time of the bedroomalarm using its tostring() method. NOTE: zero-argument constructors should initialize instance variables to known values, most commonly zero for integers, for Strings, or false for boolean values. See the example below: String brand = new String( );

P2C P2C. Let s write another class and test it with a driver. This time let s create a Student class that models a SFHS student. The Student class should have instance variables for the student s first and last name, and at least TWO other instance variables chosen by you. Include a zero-argument and multi-argument constructor to initialize all instance variables. Choose the most appropriate variable types (i.e. int, double, String, boolean) for each instance variable. It should also have a tostring() method to display the object s instance variables in a user-friendly format. Write a separate StudentDriver class to: a) create an instance of a Student called senior001 using its zeroargument b) display the instance variables of the senior001 using the object s tostring() method, c) create an instance of a Student called a frosh001 and initialize its instance variables using the object s multi-argument and d) display the instance variables of the frosh001 using the object s tostring() method. Print out the results of the program using JOptionPane.showMessageDialog(). 4

P2D P2D. Design a class that models an object of your choice (e.g. type of car, sports team, musical instrument, etc.) Include at least two different instance variables of two different types (e.g. String and an int, int and a double, boolean and a String, etc.) for your class. It should also have a tostring() method to display the object instance variables in a user-friendly format. Write a separate YourObjectDriver class to: a) create an instance of a your object called obj1 (or a name more appropriate for your object) using its zero-argument b) display the instance variables of the obj1 using the object s tostring() method, c) create an instance of a your object called a obj2 and initialize its instance variables using the object s multi-argument and d) display the instance variables of the obj2 using the object s tostring() method. 5