Remaining Enhanced Labs

Similar documents
Core Competency DOO (Design Object-Oriented)

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Lab 1 Introduction to R

Skill 1: Multiplying Polynomials

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

CMSC 201 Spring 2018 Project 2 Battleship

CMPSCI 187 / Spring 2015 Hangman

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

A cell is highlighted when a thick black border appears around it. Use TAB to move to the next cell to the LEFT. Use SHIFT-TAB to move to the RIGHT.

Topic 2: Decimals. Topic 1 Integers. Topic 2 Decimals. Topic 3 Fractions. Topic 4 Ratios. Topic 5 Percentages. Topic 6 Algebra

Working with Questions in MathXL for School

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

Lab 4: Strings/Loops Due Apr 22 at midnight

Notebook Assignments

Simplifying Expressions

CSci 1113, Fall 2015 Lab Exercise 4 (Week 5): Write Your Own Functions. User Defined Functions

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

Spreadsheet View and Basic Statistics Concepts

Why Use Graphs? Test Grade. Time Sleeping (Hrs) Time Sleeping (Hrs) Test Grade

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Part 1. Summary of For Loops and While Loops

Linux File System and Basic Commands

Course Outline. Introduction to java

Claremont McKenna College Computer Science

CSCI 355 LAB #2 Spring 2004

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Millionaire. Input. Output. Problem limit seconds

MATH 021 UNIT 2 HOMEWORK ASSIGNMENTS

CIS 121 Data Structures and Algorithms with Java Spring 2018

Computational Mathematics/Information Technology. Worksheet 2 Iteration and Excel

APCS-AB: Java. Recursion in Java December 12, week14 1

EDIT202 Spreadsheet Lab Prep Sheet

Pacific Northwest Region Programming Contest Division 2

1

Assignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00)

Spreadsheets for Geniuses

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

Honors Computer Science Python Mr. Clausen Programs 4A, 4B, 4C, 4D, 4E, 4F

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

Principles of computer programming. Profesor : doc. dr Marko Tanasković Assistent : doc. dr Marko Tanasković

CMSC 201 Spring 2017 Project 1 Number Classifier

EECE.2160: ECE Application Programming Spring 2018

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

CSCI 355 Lab #2 Spring 2007

SCRATCH MODULE 3: NUMBER CONVERSIONS

Math 101 Exam 1 Review

Assignment 5: Part 1 (COMPLETE) Sprites on a Plane

Chapter 1. Math review. 1.1 Some sets

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

cd h: mkdir -p CS101 cd CS101 curl -O unzip zipfile cd CS101_Exam4

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Beginning of Semester To Do List Math 1314

This is an individual assignment and carries 100% of the final CPS 1000 grade.

More About WHILE Loops

1. The programming language C is more than 30 years old. True or False? (Circle your choice.)

Lab 1: Setup 12:00 PM, Sep 10, 2017

CSE100 Principles of Programming with C++

Using Mathcad to Perform Mathematics Charles Nippert

Hi everyone. Starting this week I'm going to make a couple tweaks to how section is run. The first thing is that I'm going to go over all the slides

Question 2. [2 points] True False By default, structures are passed-by-reference.

Advanced Algebra I Simplifying Expressions

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

SPRING 2017 CSCI 304 LAB1 (Due on Feb-14, 11:59:59pm)

Exam 1 Review. MATH Intuitive Calculus Fall Name:. Show your reasoning. Use standard notation correctly.

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

Note that ALL of these points are Intercepts(along an axis), something you should see often in later work.

= 3 + (5*4) + (1/2)*(4/2)^2.

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Post Experiment Interview Questions

Midterm 2 Solutions. CS70 Discrete Mathematics and Probability Theory, Spring 2009

How Do I Choose Which Type of Graph to Use?

Divisibility Rules and Their Explanations

CS 211 Programming Practicum Fall 2018

AP Computer Science Unit 3. Programs

CS 051 Homework Laboratory #2

Name: Unit 3 Beaumont Middle School 8th Grade, Introduction to Algebra

It is important that you show your work. There are 134 points available on this test.

_APP A_541_10/31/06. Appendix A. Backing Up Your Project Files

Integers and the Coordinate Plane

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018

CS 150 Introduction to Computer Science 1

Applied Calculus. Lab 1: An Introduction to R

Lab 4: Strings/While Loops Due Sun, Apr 17 at midnight

CSIS 104 Introduction to Computer Science

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

In math, the rate of change is called the slope and is often described by the ratio rise

CS61BL: Data Structures & Programming Methodology Summer Project 1: Dots!

Australian Informatics Olympiad Thursday 23 August, Information Booklet

User Manual. Version 3.1. Copyright 2000 Academia Software Solutions All Rights Reserved

CS 134 Programming Exercise 2:

LOOPS. Repetition using the while statement

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

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

2. INTRODUCTORY EXCEL

COMP 202 Java in one week

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

Summer Math Assignments for Students Entering Algebra II

Transcription:

Here are some announcements regarding the end of the semester, and the specifications for the last Enhanced Labs. Don t forget that you need to take the Common Final Examination on Saturday, May 5, from 1:00 3:00 p.m. in one of these rooms (depending on your professor): Section Location of Final Exam 1 (Shultz) Plaza 136 2, 3 (Kramer) Plaza 238 A number of Computer Science faculty are collaborating to produce this exam. The Core Competencies should cover the required material, but note that each problem on the exam may overlap one or more Core Competencies. You will be receiving a copy of my records for which Labs, Participation Activities, and Challenge Activities you have completed. Please check this record against your memory of what you have done and let me know of any errors. This record will also let you see where you stand, grade-wise, in the course, and determine how much last-minute (not really, we still have three whole weeks) work you need to do. Core Competencies WSMA and EAC have been cancelled. They represent important material, but we wanted to cut the number of CC s, and these seemed less essential (WSMA is a lot like the TAP CC s, and EAC is probably pointlessly easy). Also, for Core Competency DOO you will only be required to identify classes and some of their instance variables, not their instance methods. Remaining Enhanced Labs The last Enhanced Labs that you might chose to do are grouped into two categories. Each lab in each category is worth 4 lab points, but we are only adding 8 more lab points to the total. Thus, to get a perfect Lab score, you only have to do 8 points out of these remaining 24 points of Enhanced Labs. And, if you complete more of these, you can get extra credit. Category 1: Working with ArrayList and Creating New Classes Enhanced Lab 99.1 [4 lab points] Your goal on this Lab is to create an application named WordCounter that will ask the user for the name of a file and will then scan that file, counting the number of different words occurring, and produce a report in a data file whose name is the original file name with -counts appended, that lists all the words occurring in alphabetical order, with the number of times each word written next to it. You should assume that the input file has been produced by running the application RemoveNonWords (available in the Labs folder) to remove all bothersome symbols, leaving CS 1050 Spring 2018 Page 83

a file that just has a bunch of words (sequences of 0 or more lowercase letters) separated by spaces and end-of-lines. For example, if the user enters the name story where the file story looks like this: good dogs like to eat hot dogs all dogs run and play with dogs hot good time then a file named story-counts should be created that looks like this: all 1 and 1 dogs 4 eat 1 good 2 hot 2 like 1 play 1 run 1 time 1 to 1 with 1 Here are some hints on how to approach this lab: You will need to make a class WordWithCount (or whatever you want to call it) that has as its instance variables a word and the number of times it has been seen. You will need an ArrayList<WordWithCount> variable that stores the list, in alphabetical order, of all the words seen so far. You will need a loop to repeatedly get the next word in the input file. Then you will need to take that string and scan the list until you either find an item in the list that matches the string and increment that object s count, or you find an item in the list that has a word occurring after the string, in which case you need to insert a new item right there, or you hit the end of the list without either of the first two things happening, in which case you need to add a new item on the end of the list. Here is an example showing how the list should look after each word is processed (the WordWithCount objects are shown like <dog,1> and the ArrayList is showing as usual): CS 1050 Spring 2018 Page 84

Word processed Resulting List [ ] dog [ <dog,1> ] cat [ <cat,1>, <dog,1> ] zebra [ <cat,1>, <dog,1>, <zebra,1> ] cow [ <cat,1>, <cow,1>, <dog,1>, <zebra,1> ] dog [ <cat,1>, <cow,1>, <dog,2>, <zebra,1> ] Once the input file has been scanned into the list, you will need another loop to create the report file. Enhanced Lab 99.2 [4 lab points] In this Lab you will be using ArrayList to calculate GPA s for a collection of students. Read the entire specification before you design and code your program! Specification Write a Java program to read grades from a file, calculate the grade point averages (GPAs) and write input data and results to an output file (see below for the input data). Use an ArrayList to hold the data stored in instances of the Gpa class you will create. The class has instance variables name (string), a GPA (double), and the total number of credit hours that the student passed with grades of A, B, C or D (integer). Any other grade is not a passing grade and its credit hours should not be counted in the total credits. Each input line contains the name of a student followed by a # and then by unknown number of pairs in the form a blank, an integer representing number of credits followed by a blank and then a letter representing the grade. After all the pairs of credits/grades is a #. Do not assume that there is at least one pair on a line. For example, there could be a line with only John Doe # #. Do NOT store the pairs anywhere in the program; process them fully as you encounter them. To calculate the GPA, assume an A is worth 4 points, a B is 3, C is 2, D is 1 and F is 0. If the pair contains any other value for a grade, the pair should be ignored and move on to the next pair (or the end of the data line denoted by a #). If there are no pairs on a line, the GPA is 0. As soon as it s read, echo the input data to the output file. After all the data has been read, write to the output file three blank lines, then a formatted table with headings giving the student names, GPAs, and the number of hours passed. At the end of the table, print the CS 1050 Spring 2018 Page 85

number of students, the average GPA, and the total of the hours passed. If you encounter an error in the input like an invalid letter, output a message to that effect to the output file. The main program consists mostly of calls to methods. Do not use global variables except for any formatting constants you might declare. The file names for this lab are: GPACalculator.java Gpa.java LabGPA-input.txt LabGPA-output.txt The main program The class file containing GPA information The input file The output file Note that the class Gpa contains only the three instance variables described above and a constructor to initialize the instance variables. Use the split method to parse each input line. Help on parsing the input line is at the end of this document. The input data follows. Van Zell David # 4 A 4 B # Toole Nancy # 3 X 3 B 5 A 4 A # Tucker Henry # 5 A 3 F 2 U 4 F # Van Zell Sally # 4 C 6 B # Tucker Becky # 4 A 3 A 2 A 5 A 3 A # Stratton Charles # 2 S 2 D 5 B 4 D 1 C # Toole Charles # 4 U # Nulle, Nellie # # Thomas William # 4 B 5 A 2 D 3 B # Sample output is below. Use leftpad and padstring (or printf) as needed to line up the columns. Do not use tabs. The GPA should be formatted to two decimal places. CS 1050 Spring 2018 Page 86

Example: Name GPA Total Credits ------------------------- ------- ------------------ Van Zell David 3.50 8 etc. Totals Average Sum of all credits GPA Hints on Parsing an Input Line The first input line is Van Zell David # 4 A 4 B # Use the split method once with a # as the separator. This creates a 2-element array, say split1, with split1[0] equal to the name (that needs to be trimmed) and split1[1] which contains # 4 A 4 B #. Now, use the split method again on split1[1] with a separator of a blank. This creates a 6-element array, say split2, that has: Index Contents 0 # 1 4 2 A 3 4 4 B 5 # Process the split2 array accordingly. Remember split2 is a string array, so digits must be converted to integers to be able to process them as integers. CS 1050 Spring 2018 Page 87

Enhanced Lab 99.3 [4 lab points] Using an ArrayList, find the sum, average, minimum and maximum of the elements. Specification Write a Java program that does the following: 1. Perform these steps until the user enters a 0. a. Read an integer value from the console. The value can be positive or negative. b. Add the value to an ArrayList. Note that the 0 is not entered into the ArrayList and all this step does is gather the data. No processing as in step 2 is performed. 2. After the user enters a 0, process the ArrayList with one for loop as follows: a. Calculate the total of the values entered. b. Calculate the average of the values entered. Ensure you handle the case of no entries correctly. c. Find the minimum value. d. Find the maximum value. Output to the console, with appropriate messages, the number of values read, the total, average, minimum and maximum values. To get your program checked off, it must be able to handle at least these cases: a. A program run with at least five non-zero numbers entered. b. A program run with only a 0 entered, meaning there are no numbers in the list to process. Write the program as one main method or use a few methods, at your discretion. CS 1050 Spring 2018 Page 88

Category 2: Some Fun Projects that Don t Use ArrayList Enhanced Lab 99.4 [4 lab points] This one is for the hard-core mathematicians! You might have seen this algorithm in a calculus class, but if you have only had algebra, you can still do this lab. This Lab asks you to implement an application that will let the user enter a starting guess for the root of a function f(x), and will then use finite-difference Newton s method to efficiently find a root of f to the full accuracy allowed by the machine arithmetic. The idea for this lab is that if you have a number a that you think is a decent guess for the root of some function f(x), then you can find the equation of the line passing through the points (a, f(a)) and (a + h, f(a + h)), and then compute the value of x for which that line crosses the x axis and use it as a better approximation to a root of f. This can all be done inside a loop so that it quickly finds a very accurate approximation to a root of f. Because this isn t a math class, here are all the details that you can use to quite easily implement this application. Note that the user has to actually type in the formula for f(x) and compile and run the application, so it s not for users who don t know how to program in Java at least a little. The slope of the line through (a, f(a)) and (a + h, f(a + h)) is m = f(a + h) f(a), h so the equation of that line is or y f(a) x a = m, y = m(x a) + f(a). If we set y equal to 0 and solve for x, we obtain x = a f(a) m. Then we can use that value as the next value of a and repeat the process. For a typical function f, a good value for h is 10 7. We want to display the values of a and f(a) inside the loop, and exit the loop when f(a) is less than 10 12, say. Implement these ideas and test them on some function(s) that you know have roots. For example, use f(x) = x 2 3, use 2 as the first value of a and verify that the root, which is 3, is obtained to about 12 decimal places. CS 1050 Spring 2018 Page 89

Enhanced Lab 99.5 [4 lab points] The application you will create in this Lab will convert a given dollar amount to words. Specification Convert a number between $0.01 and $9999.99 inclusive to words as if you are writing a check. Examples: Data In words $3.14 Three and 14/100 dollars $54.54 Fifty-Four and 54/100 dollars $100.00 One Hundred and 00/100 dollars $1024.54 One Thousand Twenty-Four and 54/100 dollars $2718.28 Two Thousand Seven Hundred Eighteen and 28/100 dollars The program will repeatedly read numbers from the keyboard, displaying on-screen each one converted to words, stopping when an out-of-range number is entered. You should use at least the test cases given above, but note that your logic should cover every possible in-range number. Enhanced Lab 99.6 [4 lab points] Your job on this Lab is to implement the game Lights Out. Your program must display graphically a 5 by 5 grid of squares, each of which is yellow to represent a light that is on or black to represent a light that is off. When the game starts, each light is randomly (50-50 chance) turned on or off. When the user presses the mouse button on one of the squares, it changes state (off to on or on to off) and similarly flips the state of all 2, 3, or 4 of its horizontal and vertical neighbors. The player wins when they manage to turn off all of the lights (hence the name!). CS 1050 Spring 2018 Page 90