Homework Assignment 2: Java Console and Graphics

Similar documents
Assignment #2: Intro to Java Due: 11AM PST on Wednesday, July 12

Assignment 2: Welcome to Java!

Assignment #2: Simple Java Programs Due: 1:15pm on Friday, April 19th

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

Assignment #2: Simple Java Programs Due: 11AM PST on Monday, Jan 29 th

CS 106B, Lecture 1 Introduction to C++

CS 245 Midterm Exam Winter 2014

CS 245 Final Exam Winter 2016

Assignment #2: Simple Java Programs Due: 11AM PST on Monday, April 23 rd

CS-245 Database System Principles

CS 155 Final Exam. CS 155: Spring 2005 June 2005

CS 245 Midterm Exam Solution Winter 2015

CS 155 Final Exam. CS 155: Spring 2004 June 2004

CS 155 Final Exam. CS 155: Spring 2009 June 2009

CS 106A, Lecture 27 Final Exam Review 1

Practice Midterm Examination

CS 106A, Lecture 27 Final Exam Review 1

Using Eclipse and Karel

YEAH 2: Simple Java! Avery Wang Jared Bitz 7/6/2018

SSEA Computer Science: Track A. Dr. Cynthia Lee Lecturer in Computer Science Stanford

CS 155 Final Exam. CS 155: Spring 2006 June 2006

COSC 115: Introduction to Web Authoring Fall 2013

CS 106A, Lecture 5 Booleans and Control Flow

CS 155 Final Exam. CS 155: Spring 2011 June 3, 2011

Practice Midterm Examination #1

CS 245 Final Exam Winter 2017

Assignment #1: /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th

Updated: 2/14/2017 Page 1 of 6

CS 106A, Lecture 3 Problem-solving with Karel

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

COSC 115A: Introduction to Web Authoring Fall 2014

Practice Midterm Examination

CS 106A, Lecture 7 Parameters and Return

Mehran Sahami Handout #7 CS 106A September 24, 2014

CS 106X, Lecture 16 More Linked Lists

CS 155 Final Exam. CS 155: Spring 2012 June 11, 2012

You must pass the final exam to pass the course.

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

Internet Web Technologies ITP 104 (2 Units)

CS 3030 Scripting Languages Syllabus

CS 106X, Lecture 10 Recursive Backtracking

Practice Midterm Examination

Assignment #1: and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th due: 11:59pm on Sunday, October 6th

IML 300: Reading and Writing the Web

CS 106A, Lecture 16 Arrays

CSE 131 Introduction to Computer Science Fall Exam II

Due: Wednesday, August 31 st at 11:59pm. Pair programming is permitted on this assignment. See course information sheet and honor code.

CS 106A, Lecture 25 Life After CS 106A, Part 1

THE UNIVERSITY OF TEXAS AT AUSTIN MIS373 e-discovery and Digital Forensics SPRING 2015 Unique#: (03665) VERSION: 2_011718

Pick any positive integer. If the integer is even, divide it by 2. If it is odd,

CMSC 132: Object-Oriented Programming II. Administrivia

ITP489 In-Memory DBMS for Real Time Analytics

CIT110 A+ Hardware Spring 2015

CS 106A, Lecture 3 Problem-solving with Karel

CS 200, Section 1, Programming I, Fall 2017 College of Arts & Sciences Syllabus

Lecture 1 Course Overview Introduction to OOP/Java. Manu Kumar

CS 106A, Lecture 14 Events and Instance Variables

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Syllabus for HPE 099 Aerobic Proficiency 1 Credit Hour Spring 2015

Practice Midterm #2. Midterm Time: Monday, July 18 th, 7pm 9pm Midterm Location: Hewlett 200

CS 106A, Lecture 9 Problem-Solving with Strings

Assignment: 2. CS 135 Winter 2018 Graham, Nijjar

Syllabus for HPE 120 Dance Aerobic Proficiency 0.0 Credit Hour Spring 2012

CMSC 201 Fall 2016 Homework 6 Functions

IS 331-Fall 2017 Database Design, Management and Applications

CSE 142. Lecture 1 Course Introduction; Basic Java. Portions Copyright 2008 by Pearson Education

VIS II: Design Communication Graphic Design Basics, Photoshop and InDesign Spring 2018

Repetition Through Recursion

CS 106A, Lecture 9 Problem-Solving with Strings

CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points

Syllabus for HPE 099 Aerobic Proficiency 1 Credit Hour Fall 2012

CS 241 Data Organization using C

Oklahoma State University Institute of Technology Online Common Syllabus Spring 2019

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Computer Science Department

Lecture 1: CSE 373. Data Structures and Algorithms

THE UNIVERSITY OF TEXAS AT AUSTIN MIS373 e-discovery and Digital Forensics SPRING 2015 Unique#: (03883) VERSION: 1/23/2015

Introduction to Computer Systems

CS 106A, Lecture 20 ArrayLists and HashMaps

Practice Midterm Exam #2

During the first 2 weeks of class, all students in the course will take an in-lab programming exam. This is the Exam in Programming Proficiency.

YEAH Hours. January , 7-8 PM Jared Wolens

CSCI 528: OBJECT ORIENTED PROGRAMMING, Fall 2015

Welcome to CS 135 (Winter 2018)

CS 106A, Lecture 23 Interactors and GCanvas

Solution READ THIS NOW! CS 3114 Data Structures and Algorithms

Ascii Art. CS 1301 Individual Homework 7 Ascii Art Due: Monday April 4 th, before 11:55pm Out of 100 points

CS 3030 Scripting Languages Syllabus

Overview. CSE 101: Design and Analysis of Algorithms Lecture 1

Course: Honors AP Computer Science Instructor: Mr. Jason A. Townsend

Course and Contact Information. Course Description. Course Objectives

Instructor: Anna Miller

BOSTON UNIVERSITY Metropolitan College MET CS342 Data Structures with Java Dr. V.Shtern (Fall 2011) Course Syllabus

Linear Algebra Math 203 section 003 Fall 2018

CS 106A, Lecture 14 Events and Instance Variables

Syllabus Revised 08/21/17

Snowflake Numbers. A look at the Collatz Conjecture in a recreational manner. By Sir Charles W. Shults III

IS Spring 2018 Database Design, Management and Applications

CSc 2310 Principles of Programming (Java) Jyoti Islam

Final Exam Time: Friday, August 12th, 12:15pm - 3:15pm Final Exam Location: Split by last name

Transcription:

SSEA August 2016 Cynthia Lee CS106A Homework Assignment 2: Java Console and Graphics Based on past assignments created by Marty Stepp, Mehran Sahami, Keith Schwarz, Eric Roberts, Stuart Reges, and others. DUE: MONDAY, AUGUST 22, 1:30pm (Problem 3 do not start until after lecture Friday; it is due Tuesday 8/23 11:59pm) PURPOPSE: The purpose of this assignment is to acquaint you with writing Java console programs, practicing essential programming skills of well-designed decomposition into helper methods, good commenting of file and each method, and creative expression through code. ASSIGNMENT: This assignment has 3 parts. Read each part carefully, then read the general instructions. PROBLEM 1: HAILSTONE SEQUENCE Write an interactive ConsoleProgram named Hailstone that displays information about a "Hailstone sequence". Douglas Hofstadter s Pulitzer-prize-winning book Gödel, Escher, Bach mentions a cumulative algorithm for generating a series of integers called a Hailstone sequence, which can be described as follows: Pick a positive integer and call it n. Repeat the following process until n is 1: o If n is even, divide it by two. o Otherwise (if n is odd), multiply it by 3 and add 1. For example, if you start with n of 7, the sequence is 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1. As you can see, the number goes up and down, but eventually ends at 1. 1 It reminiscent of the formation of hailstones, which are carried upward by wind over and over again before they finally descend to the ground. Your program should prompt the user to type a value for n as an integer (you may assume that the user will type a positive integer) and then prints the Hailstone sequence for that n. Your Hailstone sequence should print each number on the same line with commas between the values. You should also print the number of steps it took for the sequence to reach 1. Your program should exactly duplicate the output of the following sample run, plus be able to run properly with other values. (User input as read from a call to readint is shown in bold with an underline to help distinguish it from normal output text. But the text doesn't actually show up as underlined on the screen when you run the program.) 1 The Collatz conjecture claims that this sequence always eventually reaches 1; no one has yet proven or disproven it.

If the user enters 1 as the initial value for n, the program's output should be: A Hailstone sequence can certainly get very long. For example, how many steps does it take when n is 27? PROBLEM 2: EXAM SCORES Write an interactive ConsoleProgram named ExamScores that displays information about exam scores. The program should repeatedly prompt the user to enter exam scores until a particular "sentinel" value is entered. By default this sentinel value is -1. You may assume that the user will type positive integers other than the sentinel itself. Once the sentinel value is entered, the program should display the maximum and minimum exam score typed, as well as the average score and the number of scores that failed the exam. "Failing" the exam in this context is receiving a score of 59 or lower. Your program should exactly duplicate the output of the following sample run (user input underlined), plus be able to run properly with other values: This program should be written to use a class constant to represent the sentinel value of -1, so that by changing only that constant's value and recompiling / running the program, it will now use the new sentinel value throughout the code and output. For example, if the constant's value is changed to -42, the program's output would look like:

If only one score is entered, that score is the maximum, minimum, and average. For example: If no scores are entered, the program should instead print the following message saying that no scores were entered: PROBLEM 3: ASCII ART ROCKET In the old days, when computers didn t always have graphics capabilities but only hand text consoles for interaction, programmers and users became quite clever in how to draw graphics just using letters, numbers, and punctuation. This was called ASCII art (ASCII being the encoding system for text in early computers). You still see ASCII art sometimes today in forum postings, text messages, and other settings. ڰ ڿ- ڰڿஇ and \_( ツ )_/ are examples of ASCII art. Write a ConsoleProgram named Rocket that displays an ASCII art rocket ship, as shown in the figure at right. Unlike the last two parts of this assignment, this problem is not an interactive program; it does not read any input from the user. You must exactly reproduce the format of the output at right, including identical characters and spacing. One way to write a Java program to draw this figure would be to write a single println statement that prints each line of the figure. However, this solution would not receive full credit. A major part of this assignment is showing that you understand nested for loops, methods and class constants. In lines that have repeated patterns of characters that vary in

number from line to line, represent lines and character patterns using nested for loops. (See lecture slides.) Another significant component of this assignment is the task of generalizing the program using a single class constant that can be changed to adjust the size of the figure. You should create one (and only one) class constant named SIZE to represent the size of the pieces of the figure. Use 5 as the value of your SIZE constant. Your figure must be based on that exact value to receive full credit. On any given execution your program will produce just one version of the figure. However, you should refer to the class constant throughout your code, so that by simply changing your constant's value and recompiling, your program would produce a figure of a different size. Your program should scale for any constant value of 2 or greater. The course web site will contain files that show you the expected output if your size constant is changed to various other values. Other guidelines for Rocket: Use methods to represent each part of the rocket, structuring your solution in such a way that the methods match the structure of the output itself. Avoid significant redundancy; use methods so that no substantial groups of identical statements appear in your code. In this problem, no println statements should appear in your run method. You do not need to use methods to capture redundancy in partial lines, such as if a single line has the substring... printed twice. Development strategy: We suggest that you not worry about the constant at first. Write an initial program without a constant that produces the default size-5 output. Make sure you use nested for loops for sequences of repeated characters. After your figure looks correct at the default size, begin modifying the code to use the constant. GENERAL INSTRUCTIONS: You are allowed to work in pairs and submit a joint assignment. Although we are not assigning any grades in this course, you are now officially joining the Stanford community, and we expect that you will take seriously your personal integrity responsibilities under Stanford sڿhonorڿcode.ڿitڿreadsڿasڿfollows: Stanford Honor Code 1. The Honor Code is an undertaking of the students, individually and collectively: a. that they will not give or receive aid in examinations; that they will not give or receive unpermitted aid in class work, in the preparation of reports, or in any other work that is to be used by the instructor as the basis of grading; b. that they will do their share and take an active part in seeing to it that others as well as themselves uphold the spirit and letter of the Honor Code. 2. The faculty on its part manifests its confidence in the honor of its students by refraining from proctoring examinations and from taking unusual and unreasonable precautions to

prevent the forms of dishonesty mentioned above. The faculty will also avoid, as far as practicable, academic procedures that create temptations to violate the Honor Code. 3. While the faculty alone has the right and obligation to set academic requirements, the students and faculty will work together to establish optimal conditions for honorable academic work. Your Honor Code obligations and allowances in this course include the following: If you need help, please seek out our available resources to help you. You are of course permitted to collaborate within your pairs for the assignment. This is an exception to the usual default assumption that everyone should work completely independently. Assisting fellow students those who are not your official partners for the assignment is also encouraged, when that assistance consists of oral conceptual discussions or debugging help. This is an exception to the usual default assumption that everyone should work completely independently. Do not use others ڿsolutions, or overly participate in the solutions of others by, e.g., providing your solutionsڿasڿaڿreferenceڿorڿtakingڿoverڿtheڿkeyboardڿforڿthemڿtoڿ help ڿthem. Although we are not assigning grades, this would defeat the purpose of our summer program. It is very important, for this assignment and for all your Stanford assignments, that you NOT place your solutions on any public website or forum (e.g., GitHub). Some students innocently think to do this as an augmentation to their resumes, but the Stanford CS Department considers this to be a serious Honor Code violation and has and will pursue offenders regardless of intent. If you want to do something like this, please ensure that the repository is private and only provide access to recruiters individually on request.