CS161: Introduction to Computer Science Homework Assignment 10 Due: Monday 11/28 by 11:59pm

Similar documents
Moodle 2.2 Student User Guide My Private Files

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

Tips from the experts: How to waste a lot of time on this assignment

EE 422C HW 6 Multithreaded Programming

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

CMPSCI 187 / Spring 2015 Hangman

Tips from the experts: How to waste a lot of time on this assignment

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

CS 2223 B15 Term. Homework 1 (100 pts.)

Tips from the experts: How to waste a lot of time on this assignment

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

CPSC 233: Assignment 4 (Due March 26 at 4 PM)

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

You Can Make a Difference! Due April 11/12 (Implementation plans due in class on 4/9)

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

CMPSCI 187 / Spring 2015 Sorting Kata

CS159 - Assignment 2b

Our second exam is Monday, April 3. Note that it will not be possible to get all the homework submissions graded before the exam.

Unit 1: Working With Tables

CS1110 Spring 2010 Assignment A6. Images. Due Sat. Apr 17, 11:59pm on the CMS 1

UNIVERSITY OF MASSACHUSETTS LOWELL Department of Electrical and Computer Engineering. Program 9 EECE.3220 Data Structures Fall 2017

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

Anatomy of a Method. HW3 is due Today. September 15, Midterm 1. Quick review of last lecture. Encapsulation. Encapsulation

EECS168 Exam 3 Review

Computer Science 136 Assignment 2 Mazes Due: Monday, at noon.

Interactive PDFs Start

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CS 161 Computer Security

CMPSCI 187 / Spring 2015 Hanoi

Educational Fusion. Implementing a Production Quality User Interface With JFC

Address book. Presenting the Java assignment about an Address Book v

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

Advanced Techniques. Criterion E: Product development. Three or more related tables. Complex queries / Calculated fields. Use of graphics fields

The first time you open Word

Tips from the experts: How to waste a lot of time on this assignment

CIS 162 Project 4 Farkle (a dice game)

EPORTFOLIO CHECK-IN & FINAL ASSIGNMENTS

Chapter 4: Writing Classes

Lab 3: Call to Order CSCI 2101 Fall 2018

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm)

Programming Project 5: NYPD Motor Vehicle Collisions Analysis

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Writeup for first project of CMSC 420: Data Structures Section 0102, Summer Theme: Threaded AVL Trees

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

UNIVERSITY OF MASSACHUSETTS LOWELL Department of Electrical and Computer Engineering. Program 8 EECE.3220 Data Structures Fall 2017

CS 051 Homework Laboratory #2

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

CS 101 Exam 1 Spring 200 Id Name

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

Computer. CSE 373 Summer 2017 Due 5:00pm on Friday, July 14th

Homework Assignment: Sudoku Board

Text Generator Due Sunday, September 17, 2017

Creating accessible forms

I. True/False: (2 points each)

E-Business Systems 1 INTE2047 Lab Exercises. Lab 5 Valid HTML, Home Page & Editor Tables

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Computer Basics. Need more help? What s in this guide? Types of computers and basic parts. Why learn to use a computer?

Homework 2: Imperative Due: 5:00 PM, Feb 15, 2019

public static String[] manyme() {

Excel & Business Math Video/Class Project #01 Introduction to Excel. Why We Use Excel for Math. First Formula.

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Tutorial: Input Grades in Blackboard

Com S 227 Assignment Submission HOWTO

Pace University. Fundamental Concepts of CS121 1

Alternate Appendix A: Using the TI-92 Calculator

CS 302: Introduction to Programming in Java. Lecture 15

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Programming Assignment #2

COMP 250 Winter 2011 Reading: Java background January 5, 2011

CISC 181 Lab 2 (100 pts) Due: March 4 at midnight (This is a two-week lab)

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

CS201 - Assignment 7 Due: Wednesday April 16, at the beginning of class

Computer learning Center at Ewing. Course Notes - Using Picasa

CS/ENGRD 2110 SPRING Lecture 3: Fields, getters and setters, constructors, testing

Problem 1: Building the BookCollection application

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

CS 134 Programming Exercise 2:

CSE 8B Intro to CS: Java

CS1 Studio Project: Connect Four

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

EKTRON 101: THE BASICS


Assignment 1 due Monday at 11:59pm

These bit positions are represented by numerical values, as defined in list.h.

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

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

Lab 3: Call to Order CSCI 2101 Fall 2017

Assignment #1 Simple C++

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

AberLearn Blackboard User Guide

CS 134 Programming Exercise 9:

Slide 1 CS 170 Java Programming 1

CS 134 Test Program #2

Use the Move tool to drag A around and see how the automatically constructed objects (like G or the perpendicular and parallel lines) are updated.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Thursday, February 16, More C++ and root

Windows 8.1. Tiles come in four shapes: small, medium, wide, and large. The red outlined tiles are live tiles.

Transcription:

CS161: Introduction to Computer Science Homework Assignment 10 Due: Monday 11/28 by 11:59pm Many cable packages come with a search interface that let s you search for a show or movie by typing the name one letter at a time using your remote control. For example, consider the keyboard shown below: Suppose we want to know if any of the Harry Potter movies are showing. Starting with the cursor at a and using the up, down, left, and right buttons on our remote control, we would push the following sequence of buttons: h ( down, right, select ) a ( up, left, select ) r ( right 5 times, down 2 times, select, select ) y ( down 2 times, left 5 times, select ) ( up 5 times, select ) p ( down 3 times, right 3 times, select ) o ( left, select ) t ( left, down, select, select ) e ( up 3 times, right 3 times, select ) r ( down 2 times, right, select ) In total, we had to push 52 buttons just to type the 12-character title Harry Potter. You can imagine how tiring and tedious this becomes! One idea to reduce the number of button pushes is to examine different arrangements of the keys on the keyboard. Here are some examples of different arrangements we could try: u v w x y z 0 1 2 Here, the keys are all laid out in a single row. Another idea is to arrange the keys using a QWERTY layout: 1

Assuming the cursor started at the upper-left key ( q ), this arrangement would require only 45 buttons to type Harry Potter. In general, there are lots of different arrangements we could experiment with to find the one that requires (on average) the fewest number of key presses. In this assignment, you will implement two classes: Key and Keyboard. The Key class represents a key on the keyboard. The Keyboard class will use a two-dimensional array to represent the keyboard itself. Your Keyboard class should be general enough that it can represent different arrangements. Finally, you will experiment to see which arrangements are the best i.e., which arrangements require the fewest button pushes. The starter code for this assignment contains a Controller class which you can read about at the end of this writeup. The Key class Create a new Java class named Key. This class should represent a single key on the keyboard. Looking at the pictures above, what state (i.e. instance variables) and what methods should a key have? It s extremely important that you stop and spend some time thinking about this question. When I thought about this question, I came up with the following: a key can be represented using a symbol, a row index, and a column index. These then should be the instance variables in your Key class. In terms of methods, it seems like a key needs only basic methods such as a constructor, accessors, and a tostring method. Note that it doesn t make sense for a key to have mutator methods once the instance variables are initialized in the constructor they shouldn t change. 1 It would also be useful to have a method that takes in another key and computes the distance between this key and the other key. As such, you should add the following method to your Key class: public int distance(key other) The distance between two keys on a keyboard is simply the difference between their rows plus the difference between their columns. For example, suppose we had a key at position (3,2) i.e. row 3, column 2 and another key at (5,4) i.e. row 5, column 4. Then the distance between these two keys is: 3 5 + 2 4 = 2 + 2 = 4 You can use the abs method in the Java Math class to take the absolute value. 1 You might have thought the Key class should have a push method. Depending upon the application, this could definitely be useful. 2

Keyboard class The second Java class is a Keyboard class that represents the keyboard itself using a 2-dimensional array. This class should have the following methods: 1. public Keyboard(String chars, int numcolumns) A constructor that takes a string containing the sequence of characters on the keyboard, and the number of columns in each row. Look at the Controller class to see an example of how the constructor is called. The constructor should create and initialize the 2-dimensional array. Given the number of columns and the sequence of characters, you will need to compute the number of rows. You may need to use the ceil function in the Math class to help you round up. 2. public int pressesrequired(string text) A method that takes a piece of text (e.g. Harry Potter ) and computes the number of key presses required to navigate to and select each character in the string. The cursor should always start at row 0, column 0 on the keyboard. You can ignore any characters in the text that are not in the keyboard. 3. public String tostring() - A method that returns a string representation of the keyboard. Feel free to add private methods to help you keep your code organized and your methods short. Below is what my solution outputs when I run the Controller class: It took 58 key presses to type It took 97 key presses to type It took 45 key presses to type It took 87 key presses to type It took 309 key presses to type It took 727 key presses to type 3

It took 331 key presses to type It took 907 key presses to type It took 224 key presses to type It took 544 key presses to type It took 247 key presses to type It took 568 key presses to type 4

The Controller class Come up with your own keyboard arrangement that takes fewer key presses than KEYS1 and KEYS2 on the text LONG TEXT. This variable contains the opening lines of the book Moby Dick. You can experiment with the ordering of the characters as well as the number of columns. You should add your keyboard as a new static variable called KEYS3. Style Guide Before you submit your assignment, go through the checklist below and make sure your code conforms to the style guide. Checklist All unused variables are deleted All instance variables are used in more than one method (if not, make them local) Javadoc comment for all classes All methods have Javadoc comments (except for the main method) All numbers have been replaced with constants (i.e. no magic numbers) Proper capitalization of variables, methods, and classes Use white space to separate different sections of your code Read the Style Guide (under Resources on the course website) for more information. Submitting your homework assignment You should submit your hw10 folder with the Key, Keyboard, and Controller class inside. Please rename your folder before you zip it and upload to Moodle. 5