AP Computer Science Homework Set 2 Class Design

Similar documents
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 1 Fundamentals

AP Computer Science Homework Set 3 Class Methods

AP Computer Science Homework Set 5 2D Arrays

AP Computer Science Homework Set 5 2D Arrays

Homework Set 1- Fundamentals

AP Computer Science Homework Set 1 Fundamentals

Programming Assignment Unit 7

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

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

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

CS201 - Assignment 1, Part 2 Due: Wednesday February 19, at the beginning of class

TeenCoder : Java Programming (ISBN )

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

Exam 1 - (20 points)

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

Lesson 39: Conditionals #3 (W11D4)

CO Java SE 8: Fundamentals

CompuScholar, Inc. 9th - 12th grades

AP Computer Science in Java Course Syllabus

Draft. Students Table. FName LName StudentID College Year. Justin Ennen Science Senior. Dan Bass Management Junior

Interfaces: JAVA CONTRACTS

THE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING

CS 61B, Spring 1999 MT3 Professor M. Clancy

Advanced Java Concepts Unit 2: Linked Lists.

CIS 110: Introduction to Computer Programming

DATA STRUCTURES CHAPTER 1

CS211 Prelim Oct 2001 NAME NETID

CLASS DESIGN. Objectives MODULE 4

APCS Semester #1 Final Exam Practice Problems

Lesson 36: for() Loops (W11D1)

Advanced Java Concepts Unit 9: Graph Exercises

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

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

Computer Sciences 302 Exam 2 Information & Sample Exam

CSIS 10B Lab 2 Bags and Stacks

Excel Functions & Tables

STUDENT LESSON A15 ArrayList

Object Oriented Design: Identifying Objects

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

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

Chapter 4: Control structures. Repetition

Topic 7: Algebraic Data Types

CS 106 Introduction to Computer Science I

Introduction to Computer Science II (CSI 1101)

CS61B Lecture #2. Public Service Announcements:

Object-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007

Java Fundamentals (II)

Object-Oriented Programming in Java

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Introduction to Programming Using Java (98-388)

Chapter 4: Control structures

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

Classes Classes 2 / 35

Prelim 1. CS 2110, March 15, 2016, 5:30 PM Total Question Name True False. Short Answer

Loops. In Example 1, we have a Person class, that counts the number of Person objects constructed.

Rules and syntax for inheritance. The boring stuff

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

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

CS1004: Intro to CS in Java, Spring 2005

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

CMP 326 Midterm Fall 2015

Student Performance Q&A:

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

Excel Functions & Tables

CS2141 Software Development using C/C++ C++ Basics

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Java Arrays (review) Linked Lists (preview)

Bellwork Strings 11/25/13

University of Palestine. Mid Exam Total Grade: 100

Introduction to Computer Science II (CSI 1101) Midterm Examination

CSC Java Programming, Fall Java Data Types and Control Constructs

Creating an Immutable Class. Based on slides by Prof. Burton Ma

Arrays & Classes. Problem Statement and Specifications

Creating an object Instance variables

Lesson 10: Quiz #1 and Getting User Input (W03D2)

Unit Testing. SWEN-610 Foundations of Software Engineering. Department of Software Engineering Rochester Institute of Technology

(4-3) Selection Structures II in C H&K Chapter 4. Instructor - Andrew S. O Fallon CptS 121 (February 2, 2018) Washington State University

Binghamton University. CS-140 Fall Data Types in Java

C12a: The Object Superclass and Selected Methods

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

Intro. Scheme Basics. scm> 5 5. scm>

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

COMP 105 Homework: Type Systems

CSC-140 Assignment 6

CSE 143: Computer Programming II Autumn Sample Solutions

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

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

Comp Intermediate Programming EXAM #1 February 16, 2004 Rice University - Instructors: Cox & Nguyen

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Fundamentals of Programming Data Types & Methods

More about inheritance

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

IMACS: AP Computer Science A

1 (5pts) 2 (20 pts) 3 (20 pts) 4 (10 pts) 5 (15 pts) 6 (30 pts) Total NAME: CU ID: Recitation instructor/time

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 2

Computer Science 210: Data Structures

Transcription:

AP Computer Science Homework Set 2 Class Design P2A. Write a class Song that stores information about a song. Class Song should include: a) At least three instance variables that represent characteristics of a song. b) A zero-argument and three-argument constructor to initialize all instance variables c) A tostring() method to display the object s instance variables in a userfriendly format. Write a separate SongDriver class to: a) create an instance of a Song called song1 using its zero-argument constructor, 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 constructor, and d) display the instance variables of the song2 using the object s tostring() method. Page 1

P2B. Write a class Clock that stores information about a clock. It should have integer instance variables for the Clock s hours, minutes, seconds. Include a zeroargument and three-argument constructor to initialize all instance variables. It should also have a tostring() method to display the time in the format shown below: The time is 3:45:16 Note that 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: public Clock() { int hour = 0; double cost = 0.0; String brand = new String( ); boolean ison = false; } // end constructor Clock Write a separate ClockDriver class to: a) create an instance of a Clock called kitchenclock using its zeroargument constructor, b) display the time of the kitchenclock using its tostring() method, c) create an instance of a Clock called a bedroomclock and set the hours, minutes, and seconds using the Clock s three-arguments constructor d) display the time of the bedroomclock using its tostring() method. Page 2

P2C. Let s write another class and test it with a driver. This time let s create a Student class that models a Fairfax 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 constructor, 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 constructor, and d) display the instance variables of the frosh001 using the object s tostring() method. If you are looking for an extra challenge, try to printout the results of the program using JOptionPane.showMessageDialog(). See the LewTube video for this HW Set on the details of how to use this very cool tool. 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 s 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 constructor, 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 constructor, and d) display the instance variables of the obj2 using the object s tostring() method. Page 3

P2E. Blackjack! Design a class called Card that models a playing card. Decide what instance variables you will need for your class in order to play Blackjack (or any other card game.) Include a zero-argument constructor and the appropriate multiargument constructor for your class. It should also have a tostring() method to display ALL of the object s instance variables in a user-friendly format this can be a bit tricky Write a CardDriver that will perform the following tasks: a) Create three Card objects: a blank card (i.e. a Card created using its zeroargument constructor), a number card, and a face card you pick the cards. b) Create an array called myhand that can hold 3 Card objects. Below are the lines of code that demonstrate how to create an array of Card objects and how to place a Card object into an array called myhand. Card[] myhand = new Card[10]; Card card1 = new Card( 10, Jack, Hearts ); myhand[0] = card1; c) Use a for loop to traverse the array of your Cards and print each Card using System.out.println(). The following programs DO NOT need a separate class and driver files. They are stand-alone programs that are meant to review previous topics (and introduce a couple new concepts) P2F. Write a program that creates an array that can hold 9 double values that represent baseball batting averages for a starting baseball lineup. Use a for loop to populate array with double values in the range of 0.00 to 0.500. Recall that double values are what Java calls real numbers. Use a second for loop to print the values in the array with one number per line. Finally, use a third for loop to traverse the array and find and print the maximum batting average in the array. See the LewTube for this HW assignment to see how to control the precision of a double number when you print it. Page 4

P2G. College application time! Write a program that creates an array of Strings. Fill the array with the name of the universities that you will be applying to. Then perform the following tasks: a. traverse the array using a for loop and printout the length of each university s name. You can find the length of a String as shown below: String name = new String( UCLA ); System.out.println( name.length() ); // prints 4 b. print the name of the university that has the shortest length. c. You ve decided not to apply to one of the schools on your list. Remove that school from the list by setting that element in the array to null. This can be done as shown below: school[3] = new String( NYU ); school[3] = null; // null removes NYU from array d. print your list of schools again using a second for loop. Page 5

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. Page 6