Sharpen Solutions. 1 Part One. Sometimes there s more than one right answer. And sometimes the



Similar documents
The 5 P s in Problem Solving *prob lem: a source of perplexity, distress, or vexation. *solve: to find a solution, explanation, or answer for

Club Accounts Question 6.

Game or bike? Movie or shoes? Chocolate sundae with extra rainbow sprinkles on top?

Top 5 Mistakes Made with Inventory Management for Online Stores

Welcome! You ve made a wise choice opening a savings account. There s a lot to learn, so let s get going!

Seven Things You Must Know Before Hiring a Real Estate Agent

Cornell Critical Thinking Test Series THE CORNELL CLASS-REASONING TEST, FORM X

The High Value Advertising Formula

DEFINITELY. GAME CHANGER? EVOLUTION? Big Data

GAcollege411 Site Overview Transcript

Hypercosm. Studio.

SALE TODAY All toys half price

10 tips for running successful competitions on facebook

Copyright Brad Kendall

Sample CSE8A midterm Multiple Choice (circle one)


I use several different introductions when it comes to calling purchased leads or leads that I have generated on my own through different ads.

Grades 5 & 6 (B1): choosing a Topic

Chronoforums. Written by ClubAero.nl, 8 th December 2013

So you want to create an a Friend action

CollegeInColorado Set Goals, Create a Plan, Achieve Your Dreams Transcript

Seven Things You Must Know Before Hiring a Real Estate Agent

Your Health Insurance: Questions and Answers

[Ask Candidate A and Candidate B in turn questions about name and nationality (see below).]

CLAIM, QUOTE, COMMENT! (CQC)

TRANSCRIPT An Interview with Jeanette C. Rudy. Video clip: I Collect Duck Stamps!

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Goal: Practice writing pseudocode and understand how pseudocode translates to real code.

You are going to listen to Jay talking about a special sign language for babies that her son Benen used when he was little.

Debugging Strategies

YouTube Channel Authority - The Definitive Guide

STEPS TO COLLECTING AMAZING CUSTOMER FEEDBACK. a publication of

The Marketer s Guide To Building Multi-Channel Campaigns

Can you briefly describe, for those listening to the podcast, your role and your responsibilities at Facebook?

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

STUDENT LEARNING OUTCOME (SLO): Paragraphs should be logically organized and focused.

Salary Review Spreadsheets

Would You Like To Earn $1000 s With The Click Of A Button?

Tech savvy? Lesson A Tech support. I have no idea why... UNIT. A Unscramble the questions. B Unscramble the statements.

PEER PRESSURE TEACHER S GUIDE:

Multiplying Integers. Lesson Plan

National Cybersecurity Awareness Campaign. Kids Presentation

Program 123: Income and Expenses

HOW TO GET THE MOST OUT OF YOUR ACCOUNTANT

The first program: Little Crab

Making the Case for Service Recovery - Customer Retention

Module 6: How to Write the Book

A: We really embarrassed ourselves last night at that business function.

4 Ways. To Strengthen Your Brand. Dental Marketing Experts

Reducing Customer Churn

MITI Coding: Transcript 5

1 Hour, Closed Notes, Browser open to Java API docs is OK

2 The first program: Little Crab

The Children s Advertising Review Unit Presents: A Parent s Guide to Advertising and Your Child

How To Use Bridallive

Premium Tax Credits and Tax Reconciliation

Income For Life Introduction

Everything You Need To Know About Middle School. This planning guide belongs to:

ETHICAL VALUES AND OTHER K INDS OF VALUES

Getting Started with WebSite Tonight

KEY ENGLISH TEST for Schools

Dimes to Riches Money Management for Teens in Grades 7-12

16.1 DataFlavor DataFlavor Methods. Variables

Too Good for Drugs Grade 5

Industries. Industry Standards

Reputation Marketing

CROSS EXAMINATION OF AN EXPERT WITNESS IN A CHILD SEXUAL ABUSE CASE. Mark Montgomery

Understanding class definitions

How to Make Money with Google Adwords. For Cleaning Companies. H i tm a n. Advertising

Beginning to Program Python

How to Start Your Own Hosting Company for Free!

ONLINE SAFETY TEACHER S GUIDE:

Introduction Purpose...vii Rationale...xiii How to Use this Book...x Process Essentials...xi

How to Get of Debt in 24 Months

Rocco s Proven Phone Script. Hello. Hi. This is representing. I m assigned to the area and my company asked kdme to give you a call.

RESOURCES.RESULTS.RELIEF.

DIDAKIS- ENGLISH ASSESSMENT TEST

Getting ahead online. your guide to. GOL412_GBBO brochure_aw5.indd 1 10/2/10 10:10:01

Algebra: Real World Applications and Problems

Nine Things You Must Know Before Buying Custom Fit Clubs

EKOLA Junior High School Bilingual Programme Entrance Test (1h15) Sample Paper. Result:

YouTube In-Stream Ads 101

LESSON 7. Managing the Trump Suit. General Concepts. General Introduction. Group Activities. Sample Deals

UNDERSTANDING YOUR ONLINE FOOTPRINTS: HOW TO PROTECT YOUR PERSONAL INFORMATION ON THE INTERNET

5IMPROVE OUTBOUND WAYS TO SALES PERFORMANCE: Best practices to increase your pipeline

Test Driven Development

Fruit Machine. Level. Activity Checklist Follow these INSTRUCTIONS one by one. Test Your Project Click on the green flag to TEST your code

and Maths in School. Addition in School. by Kate Robinson

STRING TELEPHONES. Education Development Center, Inc. DESIGN IT! ENGINEERING IN AFTER SCHOOL PROGRAMS. KELVIN Stock #651817

Business Introduction Script Introduction

I QUIT! What To Do When You re Sick Of Smoking, Chewing Or Dipping

HOW TO RUN A GALA. One Year in Advance:

THINGS TO KNOW ABOUT VOLLEYBALL RECRUITING. Don Perkins Head Coach, Men s and Women s Volleyball, Kean University

Transcription:

1 Part One g h Sharpen Solutions g You didn t think we d just leave you hanging, did you? No, we thought we d be all nice and helpful with this first book, to get you hooked, and then slam you in the next one... Sometimes there s more than one right answer. And sometimes the answer is whatever you want it to be. If you don t like our answers, argue with us. If we re just plain wrong, we ll change it and give you credit on the web site. If you re wrong, we ll publicly humiliate you, using a very large font. Just kidding. Please share your ideas and solutions with us, and we ll add them with your name (unless you want to be anonymous, and who could blame you.) this is a new chapter 1

chapter one Page 4 int size = 27; String name = Fido ; Dog mydog = new Dog(name, size); x = size - 5; if (x < 15) mydog.bark(8); while (x > 3) { mydog.play(); declare an integer variable named size and give it the value 27 declare a String variable named name and give it the String value Fido declare a Dog variable named mydog and give it a new Dog (that has a name and a size) subtract 5 from the current value of the variable size, assign the result to the variable x if the value of x is less than 15, then tell mydog to bark 8 times as long as the value of x is greater than 3, tell mydog to play Page 11 Given the output: % java Test DooBeeDooBeeDo Fill in the missing code: public class DooBee { public static void main (String[] args) { int x = 1; while (x < ) { System.out. ( Doo ); System.out. ( Bee ); x = x + 1; 3 3 print print if (x == ) { System.out.print( Do ); 2 Sharpen Your Pencil - Part One

chapter two Head First Java Sharpen Solutions Page 32 Television int channel int volume boolean power setchannel() setvolume() setpower() skipcommercials() searchforsimpsons() Page 35 MOVIE title genre rating playit() object 1 title genre rating Gone with the Stock Tragic -2 title Lost in Cubicle Space object 2 genre Comedy rating 5 title Byte Club object 3 genre Tragic but ultimately uplifting rating 127 you are here 4 3

chapter three Page 50 Circle the legal statements from the following list: 1. int x = 34.5; 2. boolean boo = x; 3. int g = 17; 4. int y = g; Page 50 What is the current value of pets[2]? null What code would make pets[3] refer to one of the two existing Dog objects? pets[3] = pets[0] 5. y = y + 10; 6. short s; 7. s = y; 8. byte b = 3; 9. byte v = b; 10. short n = 12; 11. v = n; 12. byte k = 128; 13. int p = 3 * g + y; 4 Sharpen Your Pencil - Part One

chapter four Head First Java Sharpen Solutions Page 85 What s legal? Given the method below, which of the method calls listed on the right are legal? Put a checkmark next to the ones that are legal. (Some statements are there to assign values used in the method calls). int calcarea(int height, int width) { return height * width; int a = calcarea(7, 12); short c = 7; calcarea(c,15); int d = calcarea(57); calcarea(2,3); long t = 42; int f = calcarea(t,17); int g = calcarea(); calcarea(); byte h = calcarea(4,20); int j = calcarea(2,3,5); need two args t is a long (too big for the int parameter height ) need two args need two args calcarea returns an int, not a byte need two args you are here 4 5

chapter five Page 101 In the next couple of pages we implement the SimpleDotCom class, and then later we return to the test class. Looking at our test code above, what else should be added? What are we not testing in this code, that we should be testing for? Write your ideas (or lines of code) below: Make a fake user guess that is a MISS instead of a hit Try all three hits Try out a range of guesses Try duplicate guesses (these are just a few...) Page 105 Turn the to the next page in your book (106) for the answer. But then, you obviously know that already. We just put this in for completeness. Didn t want you thinking we just skipped it. Although we actually are skipping it. Here in the solutions document, anyway, not in the real book. You know what we mean. Page 111 It s a cliff-hanger! Will we find the bug? Will we fix the bug? Will Ben marry J-Lo? Stay tuned for the next chapter, where we answer these questions and more... And in the meantime, see if you can come up with ideas for what went wrong and how to fix it. The current version of the game cares only about the NUMBER of hits, not what the actual hits really are. So entering the same number (as long as it s a hit) three times is the same as entering the three correct, but different, numbers corresponding to the three hit locations. So, we need to somehow keep track of each hit, and maybe cross it off the list to show that it s been hit and is no longer a valid entry. 6 Sharpen Your Pencil - Part One

chapter six Head First Java Sharpen Solutions Page 130 Turn to page 132 in your book for the answer. Page 141 We didn t do an answer for this one, but nobody around here can remember why. Must have been some excuse about how that makes it more of a learning opportunity for you. If you ve got an answer you want to share with others (for that warm fuzzy feeling and good karma points), let us know and we ll include it (with your name). [ Kathy, this looks pretty weak here for chapter six. Doesn t look like we re giving them ANYTHING! Don t you feel guilty about that? Bert ] [ No. Kathy ] you are here 4 7

chapter seven Page 165 How many instance variables does Surgeon have? How many instance variables does FamilyDoctor have? How many methods does Doctor have? How many methods does Surgeon have? How many methods does FamilyDoctor have? 2 1 Can a FamilyDoctor do treatpatient()? Can a FamilyDoctor do makeincision()? 2 1 2 Yes No Page 172 Page 175 Fan Musician Put a check next to the relationships that make sense. Oven extends Kitchen Guitar extends Instrument Rock Star concert Pianist I think I see a problem here... what if you have a bass player who IS a rock star? A rock star who IS a bass player? Not all bass players are rock stars, and not all rock stars are bass players, so what do you do? [answer: you ll have to wait for chapter 8 where we talk about interfaces...] Bass Player Person extends Employee Ferrari extends Engine FriedEgg extends Food Beagle extends Pet Container extends Jar Metal extends Titanium GratefulDead extends Band Blonde extends Smart Beverage extends Martini What if I want Beagle to extend Dog, but not all dogs are pets? (chapter 8) Hint: apply the IS-A test 8 Sharpen Your Pencil - Part One

chapter eight Head First Java Sharpen Solutions Page 201 Concrete Sample class Abstract golf course simulation Tree tree nursery application monopoly game House architect application satellite photo application Town video game Atlas/map application Football Player coaching application banquet seating app home floorplan design app Chair business modeling app technical support app Customer employee training app Store inventory system Sales Order home inventory program online book store Book Mall store directory kiosk Warehouse distribution system Store Simple business accounting Just-in-time inventory system Supplier simple golf game Pro shop POS system Golf Club Parts Inventory app Carburetor Home / architectural design Engine design software Gourmet restaurant app Oven Note: this is a little confusing and a little subjective, but here s a tip for this exercise -- the abstract category is for applications where the class in the center column would need to be SUBCLASSED. The concrete category is for applications where the class in the center can be concrete, and the only thing differentiating one instance from another is instance variable values. For example, in a home inventory system, you probably don t need to distinguish between different classes of books, you simply need an instance variable with the title, so that each instance of Book represents a book in your house. But a bookstore might *care* about different TYPES of books like FictionBook, TradePaperback, Children, etc. since each type might have different policies for stocking, discounts, and advertising. you are here 4 9