CS115_Fall_2023_Lab10_Description

docx

School

Illinois Institute Of Technology *

*We aren’t endorsed by this school

Course

115

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

7

Uploaded by DeaconResolveSquid36

Report
Lab Partner 1 Name Lab Partner 2 Name CS 115 Fall 2023 Lab #10 Due: Monday, November 27, 2023 at 11:59 PM CST Points: 20 Instructions: 1. Use this document template to report your answers and create separate java files for your classes. Enter all lab partner names at the top of first page. 2. You don’t need to finish your lab work during the corresponding lab session. 3. ZIP your Java files and lab report into a single file. Name the file as follows: LastName_FirstName_CS115_Lab10_Report.zip 4. Submit the final document to Blackboard Assignments section before the due date. No late submissions will be accepted. 5. ALL lab partners need to submit a report, even if it is the same document. Objectives: 1. (6 points) Demonstrate the ability to use while loops. 2. (7 points) Design, code and test a user-defined object containing an array. 3. (7 points) Demonstrate the ability to read a text file using loops and Java Scanner class. Problem 1 [6 points]: Write a program to play the game of craps (without the betting). In this game, two die are first rolled ( use the Die class provided below for that purpose ) to determine the roller's target. If you roll a sum of 7 on the target roll, you win. Otherwise, the 1
roller keeps rolling the two die to try to match the target sum before he rolls a sum of 7 (and craps out). Java Die class : public class Die { private int side; public Die() { setSide(1); } public Die(int newSide) { setSide(newSide); } public int getSide() { return side; } public void setSide(int newSide) { side=newSide; } public void roll() { side = (int)(Math.random()*6+1); } public String toString( ) { return "Die=" + side; } } 2
Sample Plays: Sample plays : Target Roll: 6 + 1 = 7 You won on the first roll! Press any key to continue . . . Target Roll: 2 + 3 = 5 You rolled: 1 + 2 = 3 You rolled: 4 + 6 = 10 You rolled: 3 + 3 = 6 You rolled: 2 + 1 = 3 You rolled: 4 + 4 = 8 You rolled: 6 + 2 = 8 You rolled: 1 + 2 = 3 You rolled: 6 + 6 = 12 You rolled: 5 + 6 = 11 You rolled: 3 + 5 = 8 You rolled: 2 + 5 = 7 CRAPS! You lost. Press any key to continue . . . Target Roll: 4 + 4 = 8 You rolled: 5 + 5 = 10 You rolled: 3 + 6 = 9 You rolled: 1 + 4 = 5 You rolled: 5 + 3 = 8 You rolled your target. You won! Press any key to continue . . . Target Roll: 4 + 5 = 9 You rolled: 4 + 4 = 8 You rolled: 5 + 3 = 8 You rolled: 2 + 1 = 3 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
You rolled: 6 + 2 = 8 You rolled: 6 + 5 = 11 You rolled: 5 + 4 = 9 You rolled your target. You won! Press any key to continue . . . Your task is to: Create a Craps class (containing your "main" program) from the description given above. Compile and run your program to see if it runs (no run-time errors), Problem 2 [7 points]: Write a DailySales class to store a collection of a company's daily sales records for a single month (up to 31 days). All daily sales are of integer data type . You do not have to worry about verifying the number of days actually in the month . Please code a class with the following methods: DailySales() - non-default, non-parameterized constructor , DailySales (int daysInMonth) - non-default, non-parameterized, constructor, public boolean addSales(int dayNumber, int sales) - add "sales" to the current sales for "dayNumber". Return true of successful, else return false (if invalid sales amount or invalid dayNumber), public int maxDay() - return the day number with the maximum sales, public int[] daysBelowGoal() - return an array of day numbers that have less than 100 units sold, Your tasks: Provide basic design of your program (define the fields/attributes and methods, include data type and valid ranges for attributes, and access control, arguments and return types for methods) in the box below [1 out of 7 points] : 4
Program design : Initialize our daily says arrays that will store integers. To add sales to their corresponding days : use a for loop that will assign dailySales[dayNumber] = sales. While also making sure that the sale>0 and that days < dailySales.length and days >0. To find the biggest value in our array : We use a for loop that compares each value and if it is bigger, it would be replaced and assigned as our max value. Finally we will be using two for loops : 1- to find our final array length while checking if the sales < 100. 2- The second loop will store the values in our array. Complete the Test Plan table below (the number of test cases is up to you, but should be fairly exhaustive) [1 out of 7 points] : Test plan Test case Sample data Expected result Verified? 1 1 dayNumber, 30 max 1 low 1 yes 2 5 dayNumber, (5,200) max 5 low 4 yes 3 15,110),(16,100), (17,300) max 17 low 27 yes 4 60 dayNumber, max 1 low 60 yes 5 (1,1) max 1 low 30 yes Code your program [5 out of 7 points] . 5
Problem 3 [7 points]: Finding duplicate data in a sorted file is the first step to removing duplicates. Given an input file with each line representing a record of data and the first token (word) being the key that the file is sorted on, we want to load it and output the line number and record for any duplicate keys we encounter. Remember we are assuming the file is sorted by the key and we want to output to the screen the records (and line numbers) with duplicate keys. Download input1.txt and input2.txt files from Blackboard (Blackboard > Class Notes > Lab Code and Other Files > Lab #10 files). Note: the input text files must be in the same directory as your program. Use Scanner class to load them. Sample run Enter File Name: input1.txt FileName:input1.txt DUPLICATES 12 102380 CS US W 2.8 3.267 125 14 102395 PPCI US W 2.769 2.5 115 25 102567 PPCI US W 3.192 3.412 112 35 102912 CS US Z 3.81 3.667 88 44 103087 CS US Z 2.956 2.688 90 76 103944 CS US W 3.134 3.294 134 77 103944 CS US W 3.698 3.7 94 86 104046 CS US W 2.863 3.133 65 88 104047 CS US W 3.523 3.524 77 89 104047 CS US O 3.825 3.824 49 91 104048 CS US W 3.071 3 94 92 104048 CS US W 3.114 3.111 44 93 104048 CS US W 3.375 3.6 71 Press any key to continue . . . 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Your task is to create a FindDuplicates class with the following: Declaration of an instance variables for the String filename non-default parameterized Constructor - creates an object for user passed filename argument Accessor methods return the value of each instance variable Mutator methods that allows the user to set each instance variable (no validation required), a "getDuplicates()" method that reads from the file (until end-of-file) using Scanner class, finds duplicate records based on the first token on each line (the key), and returns as a String the record number and entire duplicate record one to a line (see above Sample output) toString() - returns a String message with the value of the instance variable Create a FindDuplicatesApp driver class / program to test your FindDuplicates class. Compile and run your program to see if it runs (no run-time errors). Note: use Java exceptions! 7