AP Computer Science Homework Set 5 2D Arrays

Similar documents
AP Computer Science Homework Set 5 2D Arrays

AP Computer Science Homework Set 1 Fundamentals

AP Computer Science Homework Set 3 Class Methods

AP Computer Science Homework Set 2 Class Design

Homework Set 1- Fundamentals

Homework Set 2- Class Design

AP Computer Science Homework Set 2 Class Design

AP Computer Science Homework Set 1 Fundamentals

AP Computer Science Homework Set 3 Class Methods

Conditionals. For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations:

Set<Integer> s = new TreeSet<Integer>(); s.add( 7 ); s.add( 7 ); System.out.println( s.size() );

Object Oriented Programming 2013/14. Final Exam June 20, 2014

In this lab, you will learn more about selection statements. You will get familiar to

Registration and Login

Discrete Structures Lecture The Basics of Counting

St. Edmund Preparatory High School Brooklyn, NY

ECE15: Homework 10. void wordstats(file *fp, char string[]) { void printfrequencies(file *fp) {

Arrays. Chapter 7 Part 3 Multi-Dimensional Arrays

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

N.B. These pastpapers may rely on the knowledge gained from the previous chapters.

Using Formulas and Functions in Microsoft Excel

Web Client Instructions Simplifying the Process

Chapter 1 Introduction to Java

Programming Assignment - 1

CS 251 Intermediate Programming Coding Standards

IT 374 C# and Applications/ IT695 C# Data Structures

EXAM Computer Science 1 Part 1

Lesson 2A Data. Data Types, Variables, Constants, Naming Rules, Limits. A Lesson in Java Programming

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

CS 113 MIDTERM EXAM 2 SPRING 2013

MATLAB - Lecture # 4

Chapter 4: Control structures. Repetition

NATIONAL SENIOR CERTIFICATE GRADE 12

TeenCoder : Java Programming (ISBN )

LAB 4.1 Relational Operators and the if Statement

Topics. Chapter 5. Equality Operators

Evil Hangman Project

APCS Semester #1 Final Exam Practice Problems

Chapter 4: Control structures

SIS Modernization Faculty Portal Training Guide

Configuration of Microsoft SQL Server Express

CS 101 Exam 1 Spring 200 Id Name

SIS Modernization Faculty (Instructor) Portal Training Guide

Figure 1 - The password is 'Smith'

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

Counting: Basics. Rosen, Chapter 6.1

Computer Science II CSci 1200 Test 2 Overview and Practice

Logical Operators and switch

Lecture 13: Two- Dimensional Arrays

CUSTOMISE FIELDS AND LAYOUTS 2010

Programming Assignment Unit 7

More non-primitive types Lesson 06

COS 126 General Computer Science Spring Written Exam 2

Full file at

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

CS 351 Design of Large Programs Coding Standards

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

Array. Prepared By - Rifat Shahriyar

1. Look carefully at the program shown below and answer the questions that follow.

Create formulas in Excel

MCS Workstation Software Installation Guide

VBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide

IMPRESS System Inventory Add, Edit, & Delete Sets & Countsheets Cheat Sheet

Basic Operations and Equivalent Expressions - Step-by-Step Lesson

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Navigate Your Kindle (2nd Generation)

CompuScholar, Inc. 9th - 12th grades

Lecture 10: for, do, and switch

The toolbars at the top are the standard toolbar and the formatting toolbar.

Reviewing all Topics this term

Comp Assignment 2: Object-Oriented Scanning for Numbers, Words, and Quoted Strings

CMPSCI 187 / Spring 2015 Hangman

Welcome to Wilfrid Laurier University!

What does this program print?

Coding Standards for Java

CS-140 Fall 2018 Test 2 Version A Nov. 12, Name:

CS 152 Computer Programming Fundamentals Coding Standards

AP Computer Science in Java Course Syllabus

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

What methods does the String class provide for ignoring case sensitive situations?

Electrical Circuits and Random Walks

LECTURE 04 MAKING DECISIONS

REPETITIVE EXECUTION: LOOPS

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

PowerSchool 7.x Student Information System

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

CS152 Computer Architecture and Engineering VLIW, Vector, and Multithreaded Machines

Some Basic Aggregate Functions FUNCTION OUTPUT The number of rows containing non-null values The maximum attribute value encountered in a given column

COMPUTER APPLICATIONS

More on variables and methods

Solve the matrix equation AX B for X by using A.(1-3) Use the Inverse Matrix Calculator Link to check your work

IBM Software Group Information Management Software. The Informix Detective Game (Student Handout)

ME 142 Engineering Computation I. Unit 1.1 Excel Basics

CS100M November 30, 2000

Student Performance Q&A:

RANDOM NUMBER GAME PROJECT

Transcription:

AP Computer Science Homework Set 5 2D Arrays Note: all programs described below should work if the size of the 2D array is changed. P5A. Create a 3x4 2D array of integers and fill it with random numbers between 0 and 9. Use a nested for loop to print the array in a rectangular format. Finally, print the row, column pair of coordinates of all instances of the number 5. Use nested for loops to populate the 2D array and print out its contents. The strategic use of if statements and tabs will allow you to print the array in a rectangular format (i.e. 3 rows deep and 4 columns wide ) P5B. Create a 3x5 2D array of integers and fill it with numbers 1-15 in row-major (left to right, top to bottom) order. After you have printed out the 2D array in rectangular format, perform the following operations: a. Calculate and print the sum total of all 15 elements of the array. b. Calculate and print the sum total of each row in the array. c. Calculate and print the sum total of each column in the array. Be sure to preface each printout with a clear statement of what quantity is being printed. Page 1

P5C. Got Multiplication Tables? Write a program that will create and print a multiplication table using a 2D array. The program should be able to accept any number of rows and/or columns and correctly generate the multiplication table. Row and column numbers should be displayed along the top and left side of the multiplication table. See the example below: Page 2

P5D. Write a program that will fill a 2D array with the letters of the alphabet a-z in row major order (i.e. left-right, top-down as you would read a book.) Once the letter z is reached, the cycle begins again with an a until all elements of the 2D array are filled. Print your array after using nested for loops to test your result. The program should work for any size 2D array. An optional challenge Add a space between every letter that is printed AND the ability to choose from lowercase letters (a-z), capital letters (A-Z), or digits 0-9. Prompt the user for the number of rows, columns, and types of characters to print (lowercase, uppercase, or digits. Example output is shown below: Page 3

P5E. Create a class called Jukebox. A Jukebox will consist of a 2D array of MySong objects called songlist. Write a program to perform the following tasks: a. Write a zero-argument constructor to fill the jukebox with the following MySong objects and ratings or fill with your own songs. You can cut and paste the following code to quickly fill up your jukebox free of charge songlist[0][0] = new MySong( "Jet Airliner", 5 ); songlist[0][1] = new MySong( "Slide", 4 ); songlist[0][2] = new MySong( "Tom Sawyer", 3 ); songlist[0][3] = new MySong( "Purple Rain", 2 ); songlist[1][0] = new MySong( "Sing a Song", 1 ); songlist[1][1] = new MySong( "Baba O'Riley", 5 ); songlist[1][2] = new MySong( "Jumper", 4 ); songlist[1][3] = new MySong( "Car Wash", 3 ); songlist[2][0] = new MySong( "Kung Fu Fighting", 2 ); songlist[2][1] = new MySong( "Right as Rain", 4 ); songlist[2][2] = new MySong( "Beat It", 5 ); songlist[2][3] = new MySong( "Bust a Move", 4 ); b. Write a tostring() method that will traverse the 2D array songlist and print all songs in the Jukebox. Design your tostring() method to print out the songs in the Jukebox in a user-friendly format. c. Write a method randomsong() that randomly picks a song to play. This can be done by using Math.random() to pick random numbers for a row and a column in the Jukebox and prints the name of the song at that location. Make sure that your code picks row/column combinations that are within the bounds of the 2D array. d. Finally, write a method playsongofrating( int rating ) that takes an integer argument and prints only those songs in the Jukebox whose rating is equal to the parameter rating. Page 4

P5F. Time to upgrade your PasswordCreator program and stay one step ahead of the Black Hats. This version should: a. use JOptionPanes to separately ask for the user s last name and proposed password. b. prevent the user from creating a password that contains his/her last name. This will be in addition to the alphanumeric requirement in the first version of your PasswordCreator program. c. continually ask the user to enter a valid proposed password (but not last name) until a valid password is entered. For example, if the user s last name is Smith, then any form of Smith in the proposed password will render the password invalid. For instance, 2smith, SMITH123, smith*321, etc., should all render the password invalid. The password Sm123!abcith should be accepted since the last name Smith has been broken up into two segments, and therefore does constitute the last name Smith in its entirety. Hint: convert both the last name and proposed password to lowercase and perform the necessary comparisons. See the code below: String lastname = new String( "SMIth5" ); String lastnamelowercase = lastname.tolowercase(); System.out.println( lastname ); System.out.println( lastnamelowercase ); // prints SMIth5 // prints smith5 Below is a summary of the String methods from the AP Computer Science quick reference that might be of help. Page 5

P5G. QR Codes (coming soon) P5H. 2D Image Processing (coming soon) By the end of the lesson students should be able to: a. Write the Java code to create and populate a 2D Array. b. Write nested for loops to populate and process 2D Arrays. Page 6