Programming Assignment 5 (100 Points) START EARLY!

Similar documents
Programming Assignment 8 ( 100 Points )

Programming Assignment 2 ( 100 Points )

Programming Assignment 4 ( 100 Points )

Programming Assignment 7 (100. Points)

Programming Assignment 3 ( 100 Points ) START EARLY!

Programming Assignment 2 ( 100 Points ) Due: Thursday, October 12 by 11:59pm

Programming Assignment 2 (PA2) - DraggingEmoji & ShortLongWords

This is a combination of a programming assignment and ungraded exercises

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Programming Assignment 4 (PA4) - myxd Milestone Due: Final Due:

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

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

find starting-directory -name filename -user username

Programming Assignment Multi-Threading and Debugging 2

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

Programming Assignment 3 (PA3) - Popular Names

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

EECE.2160: ECE Application Programming

Project 1: Implementation of the Stack ADT and Its Application

Lab 03 - x86-64: atoi

CS451 - Assignment 3 Perceptron Learning Algorithm

Programming Assignment 1: CS11TurtleGraphics

Lab 1 Introduction to UNIX and C

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

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

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm

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

Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm

Spring 2012 Homework 10

Important Project Dates

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

Homework 7: Subsets Due: 11:59 PM, Oct 23, 2018

CS451 - Assignment 8 Faster Naive Bayes? Say it ain t so...

Lab 4 - Linked Lists

Programming Project 1: Lexical Analyzer (Scanner)

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists

Lab 1 Introduction to UNIX and C

Graduate-Credit Programming Project

Practical Session 0 Introduction to Linux

Due Friday, March 20 at 11:59 p.m. Write and submit one Java program, Sequence.java, as described on the next page.

Command Line Interface The basics

Lab 5 - Linked Lists Git Tag: Lab5Submission

CS 116. Lab Assignment # 1 1

CS 463 Project 1 Imperative/OOP Fractals

Lab: Supplying Inputs to Programs

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

EECE.2160: ECE Application Programming

CS52 - Assignment 8. Due Friday 4/15 at 5:00pm.

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

Fall CSEE W4119 Computer Networks Programming Assignment 1 - Simple Online Bidding System

CMSC 201 Spring 2017 Lab 01 Hello World

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

Introduction to Linux

Assignment 3 ITCS-6010/8010: Cloud Computing for Data Analysis

CMSC 201 Spring 2018 Project 3 Minesweeper

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

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

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

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

Shell Programming (Part 2)

Deliverables. Problem Description

Programming Assignment #3 Event Driven Simulation

Programming Assignment 1 (PA1) - Display Bowtie

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

CSE115 Lab 9 Fall 2016

CS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005

Programming Assignment 1

// class variable that gives the path where my text files are public static final String path = "C:\\java\\sampledir\\PS10"

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

3. A Periodic Alarm: intdate.c & sigsend.c

Lab 3 : Sort program

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

ASSIGNMENT 5 Objects, Files, and More Garage Management

Reading and manipulating files

CMSC 201 Spring 2018 Lab 01 Hello World

CS 1510: Intro to Computing - Fall 2017 Assignment 8: Tracking the Greats of the NBA

Lab 4: On Lists and Light Sabers

Cosc 242 Assignment. Due: 4pm Friday September 15 th 2017

Part I: Written Problems

CMSC162 Intro to Algorithmic Design II Blaheta. Lab March 2019

Decaf PP2: Syntax Analysis

Lab 1 Implementing a Simon Says Game

CS159 - Assignment 2b

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Lab 1 Implementing a Simon Says Game

PROGRAMMING PROJECT ONE DEVELOPING A SHELL

Project 1 Balanced binary

Homework # 7 DUE: 11:59pm November 15, 2002 NO EXTENSIONS WILL BE GIVEN

Programming Assignment 2 (PA2) - Binary Clock

Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017

CIS 505: Software Systems

Due: Tuesday 29 November by 11:00pm Worth: 8%

Programming Assignment #4 Arrays and Pointers

Programming assignment A

Fishnet Assignment 1: Distance Vector Routing Due: May 13, 2002.

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

CSCI 1301: Introduction to Computing and Programming Spring 2018 Project 3: Hangman 2.0 (A Word Guessing Game)

Transcription:

Programming Assignment 5 (100 Points) Due: 11:59PM Thursday, November 2 START EARLY! Mining is arduous and dangerous work. Miners need to be taught how to mine minerals in the most efficient manner possible. For this PA, we will be creating a MiningTrainer where various miners will be evaluated on their mining speed and ability to extract the highest value from mineral veins. This program focuses on using interfaces, handling simple exceptions, handling command-line arguments, and reading from files. You will be creating a command-line java application that reads in mineral patterns from a file (or System.in) and processes them through various miners. There are 5 miner classes that we will be writing:,,, OddFirstEvenReverseMiner and. Miner is an interface and must be implemented by all miner classes. MiningTrainer is the command line program that will evaluate the various miners. README ( 10 Points ) You are required to provide a text file named README, NOT Readme.txt, README.pdf, or README.doc, with your assignment in your pa5 directory. There should be no file extension after the file name "README". Your README should include the following sections: Program Description ( 2 points ) : Provide a high level description of what your program does and how you can interact with it. Make this explanation such that your grandmother or uncle or someone you know who has no programming experience can understand what this program does and how to use it. Write your READMEs as if it was intended for a 5 year old. Do not assume your reader is a computer science major. Short Response ( 8 points ) : Answer the following questions in a couple of sentences: 1. (AI) How do you maintain your integrity even when you're stressed, pressured, or tired? 2. Why is so slow? 3. (Unix) What is the difference between Ctrl-C and Ctrl-D? 4. (Unix) How can you determine the number of lines in a file from the command line? (not opening vim) 5. (Unix) How can you determine the last time each file in a directory was edited? 6. (Vim) How do you search for all occurrences of the word taco in vim? (give the 1 line command) 7. (Vim) You have almost finished with PA5 when you realize that you misspelled PA5Strings as PA5strings (incorrect capitalization) in one of your files. In that file, you ve typed PA5strings a lot and so you don t want to have to change every misspelling by hand. What vim command can you use to change all instances of PA5strings to PA5Strings? 8. (Java) What is an interface?

STYLE ( 20 points ) Please refer to the style guidelines in the PA2 write-up. Note: Some of the guidelines have changed since PA1. In terms of grading, we will be using the style guidelines in PA2 for the rest of the PAs. CORRECTNESS ( 70 points ) Setting up your PA5 directory: We have provided two starter files for your use. You must copy them to your pa5 directory. mkdir ~/pa5 cp PUBLIC/pa5StarterFiles/PA5Strings.java ~/pa5/ cp PUBLIC/pa5StarterFiles/Miner.java ~/pa5/ Program Overview - About Mining Mineral patterns are modeled as strings. Here are the possible characters in a mineral pattern and their significance. '*' - Gem. The most valuable mineral in the mine. 'O' or 'o' - Ore. The least valuable mineral in the mine. 'X' or 'x' - Empty space. Miners don t want to mine this because they will get a penalty for wasting time (PENALTY). Sample mineral pattern: xoxoxoxox*** Note: All other characters are worth 0, and don t incur a penalty. For instance, if there is a mineral pattern oxmxo*, then the miners will mine the sequence normally, but would get 0 money for mining the m. Each character of the string represents a mining location. To get a character value from a string at a specified index, we can use charat()from the String class. MiningTrainer.java This class is the main driver of the program, where you parse the command line arguments, set up an input stream, create an instance of each miner type, make each miner mine according to their unique algorithm, and finally collect information about their mining time and earnings. Note: To avoid losing points because of mismatch of error messages and any other format strings with the reference output, make sure to use strings provided in PA5Strings.java. Refer to the SAMPLE OUTPUT section (see below) for more details of how the program should behave in different scenarios. Stage 1 : Parse the command line arguments Usage: java MiningTrainer SEED [-i INFILE] All command line options are case-sensitive (-i not -I). SEED is an integer that is to be used as the seed for random number generation -i INFILE : infile is the name of the input file.

If the -i flag was provided then it should have only one argument. If infile is put as -, then System.in should be used as the input stream. If the -i flag is not given, System.in is used. Stage 2 : Construct miners, perform mining tasks and print info Create an instance of Scanner class using the input stream. (Hint: you will find Scanner s hasnext() and next() methods helpful for implementing your program.) Create an array of miners. Iterate until the scanner has no more tokens to read and have each miner mine the read in sequence. If the input stream is System.in, print the instructions and prompt before accepting user input (string provided PA5Strings.java). Iterate over the miner array and perform mining tasks for each miner type (,,, and ). Print info about the time taken mining and total earnings for each miner when they finish mining. To print the miner s name, you can use minerobj.getclass().getname() Miner.java This is the interface that defines behaviors of a Miner. We make all Miner types (,,, and ) implement this interface so that they will have common defined behavior (i.e. method names). This makes it really convenient when you, say, want all Miner types to perform the mine() task. Now that they all have the same method named mine(), we can just call mine() for each of them in a simple loop in MinerTrainer. This interface defines the following public methods - 1. int mine(string minerals, int numgems) This method will process the string based on a mining algorithm until the entire string has been explored or all the gems have been found. It will return the time taken to mine all the gems. The miner will stop mining once it has found all the gems. 2. int gettotalearnings() This method returns the total money earned from all the mining operations. 3. default int appraisemineral(char mineral) This method will take in a character and determine its worth. It returns the monetary value of the mineral. Since this is a default method, it will be implemented in the interface itself. (You will have to implement this method yourself)..java This miner takes in a seed that is used to generate random numbers. You need to create a Random object in the constructor based on that seed (see how this was done in PA2Simulator). To begin, implement the mine(string minerals, int numgems) method. works by the following algorithm:

1. Pick a random location to mine at by calling nextint()to generate a random integer. 2. If we have already mined that location, apply a penalty (REPEAT_PENALTY = 2) to our total earnings for having wasted time and try a new random location (return to step 1) 3. If we have not mined that location, mark the location as visited, and get the value of the mineral at that location using appraisemineral and add it to the total earnings 4. If there are still gems left to mine, pick a new random location (return to step 1) 5. Return the time taken to mine the mineral sequence. Here are a few things that you need to keep track of: Locations you have already mined (an array might be helpful here). Number of gems found and how many yet to find. Total earnings made by This value does NOT reset each time mine() is called, it should be a running total. The time a takes to mine This value DOES reset each time mine() is called. Each time you pick a new location, the time should increase by MINE_RATE At the end of this method, you should return the time taken to mine all of the gems The last thing you need to do for is to implement the gettotalearnings() method..java This miner will sequentially mine all the EVEN indices in the string (beginning at 0), and then mine all ODD indices (starting at 1). First implement the mine(string minerals, int numgems) method. This method follows the following algorithm: 1. Go through all of the even indices, taking note of the value of each mineral and updating the total earnings accordingly. For each index you visit, the amount of time taken to mine should increase by MINE_RATE. 2. After you have either found all the gems, or visited all of the even indices, start visiting the odd indices. Complete the same process as you did with the even indices. 3. Once you have found all of the gems, or visited every index, the time spent mining should be returned. Lastly, implement the gettotalearnings() method..java The next miner you will be implementing is similar to the previous, except you need to visit the of the ODD indices first, then visit the EVEN indices. As with before, implement the mine() method first, then complete the gettotalearnings() method..java The next miner wants to try something different -- they want to visit all of the odd indices then visit all of the even indices IN REVERSE order.

To implement the mine(string minerals, int numgems) method, first visit all of the odd indices as you have done before, then, starting from the last even index, visit every even location in reverse until index 0. Don t forget to complete the gettotalearnings() method..java The last miner is very traditional, they don't want to do any fancy optimizations. This miner will simply visit each mining location in linear order until all of the gems are found, or every location has been mined. As with the other miners, first implement mine(), then complete the gettotalearnings() method. General notes: 1. After you have found all of the gems in the sequence, you should stop looking for more minerals (don't visit another index). 2. The total earnings for each Miner accumulate, this means that you should not reset the total earnings after or before each call to mine(), but earnings should start at 0 before the very first call to mine() 3. Every time you visit an index, you need to increase the total time spent mining by MINE_RATE. Note that this value should start at 0 at the beginning of each call to mine(). Sample Output Note: bolded text is what you type in the terminal. represents command prompts. 1. Command line parsing errors 1.1 Wrong number of arguments java MiningTrainer Usage: java MiningTrainer SEED [-i INFILE] 1.2 Invalid seed java MiningTrainer NotInteger Error: Invalid Integer Seed NotInteger 1.3 Invalid Flag java MiningTrainer 1234 -o Error: Unrecognized flag -o Usage: java MiningTrainer SEED [-i INFILE]

1.4 Missing argument to -i flag java MiningTrainer 1234 -i Error: Expected argument for -i flag Usage: java MiningTrainer SEED [-i INFILE] 2. User input via System.in 2.1 Program run with a seed value 17 and invalid sequence of minerals entered by the user via stdin: java MiningTrainer 17 Please enter a sequence of minerals. Minerals can be represented by the following characters: x,x: No minerals o,o: Low value ore. *: High value gems. End sequences by pressing the <ENTER> key. Finish by typing ctrl-d > mmmmmm Mining Minerals... mmmmmm Time taken for this sequence: 0 Money earned so far: 0 Time taken for this sequence: 0 Money earned so far: 0 Time taken for this sequence: 0 Money earned so far: 0 Time taken for this sequence: 0 Money earned so far: 0 Time taken for this sequence: 0 Money earned so far: 0 > ^d 2.2 Program run with a seed value 17 and the sequence "xo*" entered by the user via stdin: java MiningTrainer 17 Please enter a sequence of minerals. Minerals can be represented by the following characters: x,x: No minerals o,o: Low value ore. *: High value gems. End sequences by pressing the <ENTER> key. Finish by typing ctrl-d > xo* Mining Minerals...

xo* Time taken for this sequence: 8 Money earned so far: 7 Time taken for this sequence: 4 Money earned so far: 5 Time taken for this sequence: 6 Money earned so far: 9 Time taken for this sequence: 4 Money earned so far: 11 Time taken for this sequence: 6 Money earned so far: 9 > ^d 2.3 No input provided ( java MiningTrainer 1234) java MiningTrainer 1234 Please enter a sequence of minerals. Minerals can be represented by the following characters: x,x: No minerals o,o: Low value ore. *: High value gems. End sequences by pressing the <ENTER> key. Finish by typing ctrl-d > ^d 2.4 Input redirected from a file cat infile xooxxo***xooo*x**** java MiningTrainer 1234 < infile Please enter a sequence of minerals. Minerals can be represented by the following characters: x,x: No minerals o,o: Low value ore. *: High value gems. End sequences by pressing the <ENTER> key. Finish by typing ctrl-d > Mining Minerals... xooxxo***xooo*x**** Time taken for this sequence: 62 Money earned so far: 40

Time taken for this sequence: 32 > 2.5 Input piped into a different command echo '***oxoxxxxxoo*' java MiningTrainer 1234 Please enter a sequence of minerals. Minerals can be represented by the following characters: x,x: No minerals o,o: Low value ore. *: High value gems. End sequences by pressing the <ENTER> key. Finish by typing ctrl-d > Mining Minerals... ***oxoxxxxxoo* Time taken for this sequence: 126 Money earned so far: -72 Time taken for this sequence: 28 Money earned so far: 32 Time taken for this sequence: 18 Money earned so far: 36 Time taken for this sequence: 28 Money earned so far: 32 Time taken for this sequence: 28 Money earned so far: 32 > 3. User input via file 3.1 Program run with a seed 17 and an input file named infile cat infile xooxxo***xooo*x**** java MiningTrainer 17 -i infile Mining Minerals... xooxxo***xooo*x****

Time taken for this sequence: 150 Money earned so far: -42 Time taken for this sequence: 32 3.2 File with multiple lines cat infile_multiline oooxoxoxoxox***xoo *xoxoxo***xoxoxxxx java MiningTrainer 1234 -i infile_multiline Mining Minerals... oooxoxoxoxox***xoo Time taken for this sequence: 36 Money earned so far: 27 Time taken for this sequence: 32 Money earned so far: 43 Time taken for this sequence: 34 Money earned so far: 41 Time taken for this sequence: 24 Money earned so far: 21 Time taken for this sequence: 30 Money earned so far: 39 Mining Minerals... *xoxoxo***xoxoxxxx Time taken for this sequence: 70 Money earned so far: 17 Time taken for this sequence: 28 Money earned so far: 69 Time taken for this sequence: 28 Money earned so far: 79

Time taken for this sequence: 36 Money earned so far: 51 Time taken for this sequence: 20 Money earned so far: 73 3.3 Empty File touch empty_file java MiningTrainer 1234 -i empty_file 3.4 File doesn t exist java MiningTrainer 1234 -i nosuchfile Error: Could not open stream for reading EXTRA CREDIT ( 5 Points ) We have some new miners in town for the training, and they just so happen to be fans of the TV show Silicon Valley. Implement the following 2 Miners: EC_PiedPiperMiner.java (2.5 Points) Implements the famous middle-out algorithm. Starts from the middle and works its way outwards consuming one position per loop. Eg: Given a sequence of length 5, we would visit indices in the following order: 2 -> 1 -> 3 -> 0 -> 4 EC_HooliMiner.java (2.5 Points) Mines from the edges to the middle or until there are no gems left. This miner will mine the edges and then move one index inward on each side. Eg: Given a sequence of length 5, we would visit indices in the following order: 0 -> 4 -> 1 -> 3 -> 2 Create an EC version of MiningTrainer called EC_MiningTrainer.java that appends these miners to the array of regular miners. (Copy MiningTrainer.java to EC_MiningTrainer.java) Remember to switch the usage to EC_USAGE! SAMPLE OUTPUT: java EC_MiningTrainer 1234 -i infile

Mining Minerals... xooxxo***xooo*x**** Time taken for this sequence: 62 Money earned so far: 40 Time taken for this sequence: 32 EC_PiedPiperMiner EC_HooliMiner Time taken for this sequence: 34 Money earned so far: 68 TURNIN Turnin To turnin your code, navigate to your home directory and run the following command: cse11turnin pa5 You may turn in your programming assignment as many times as you like. The last submission you turn in before the deadline is the one that we will collect. Verify To verify a previously turned in assignment, cse11verify pa5 If you are unsure your program has been turned in, use the verify command. We will not take any late files you forgot to turn in. Verify will help you check which files you have successfully submitted. It is your responsibility to make sure you properly turned in your assignment. Files to be collected:.java

.java Miner.java MiningTrainer.java.java.java PA5Strings.java.java README Additional files to be collected for Extra Credit: EC_HooliMiner.java EC_PiedPiperMiner.java EC_MiningTrainer.java The files that you turn in (in your pa5 dir) must be EXACTLY the same name as those above, and no other.java source files. Any.java source file in your pa5 directory must compile without error for turnin. NO LATE ASSIGNMENTS ACCEPTED! START EARLY! And above all HAVE FUN!