Part 1: Group Brainstorm (NO computers during this time) Part 2: Submit Individual Brainstorm (You can now use a computer)

Similar documents
CSCI 1301: Introduction to Computing and Programming

Recommended Group Brainstorm (NO computers during this time)

CSCI 1301: Introduction to Computing and Programming Spring 2019 Lab 10 Classes and Methods

CSCI 1301: Introduction to Computing and Programming Summer 2018 Lab 07 Classes and Methods

Lab Exercise 6: Abstract Classes and Interfaces CS 2334

Activity 11: Designing Classes

CSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017

EE 422C HW 6 Multithreaded Programming

San José State University Department of Computer Science CS-144, Advanced C++ Programming, Section 1, Spring 2018

CSE100 Principles of Programming with C++

CSc 2310 Principles of Programming (Java) Jyoti Islam

CS 142 Style Guide Grading and Details

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

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

Cmpt 135 Assignment 2: Solutions and Marking Rubric Feb 22 nd 2016 Due: Mar 4th 11:59pm

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

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

EECE.2160: ECE Application Programming Spring 2017

Defining Classes and Methods

Readings for This Lecture

Programming Assignment 1

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

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

CSCI 1100L: Topics in Computing Spring 2018 Web Page Project 50 points

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

EECS168 Exam 3 Review

Lab Exercise 4: Inheritance and Polymorphism CS 2334

CS446: Machine Learning Fall Problem Set 4. Handed Out: October 17, 2013 Due: October 31 th, w T x i w

CMPSCI 187 / Spring 2015 Hangman

EECE.2160: ECE Application Programming Spring 2019

CS 342 Software Design Fall 2018 Term Project Part II Addition of Artifacts and Data File Processing

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology

San Jose State University College of Science Department of Computer Science CS151, Object-Oriented Design, Sections 1,2 and 3, Spring 2017

Computer Science 210: Data Structures

CS445 Week 9: Lecture

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

Procedural Abstraction

CS112 Lecture: Defining Instantiable Classes

Please Turn Your Mobile Phone Silent. August 29, 2017 CSc 242 1

Exercise 4: Loops, Arrays and Files

You must pass the final exam to pass the course.

CS 051 Homework Laboratory #2

CS 342 Software Design Spring 2018 Term Project Part III Saving and Restoring Exams and Exam Components

Get Started with Blackboard For Instructors

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

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

Spring CISM 3330 Section 01D (crn: # 10300) Monday & Wednesday Classroom Miller 2329 Syllabus revision: #

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

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

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Configuration Manager Help Guide

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

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

In this course, you need to use Pearson etext. Go to "Pearson etext and Video Notes".

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

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

CS 152 Computer Programming Fundamentals Lab 7: Book and Author Objects

CS1004: Intro to CS in Java, Spring 2005

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

CSE 143, Winter 2010 Final Exam Thursday, March 18, 2010

Spring, 2014 CIT 590. Programming Languages and Techniques Homework 7

Programming II (CS300)

In this course, you need to use Pearson etext. Go to "Pearson etext and Video Notes".

CAT.woa/wa/assignments/eclipse

San Jose State University College of Science Department of Computer Science CS151, Object-Oriented Design, Sections 1, 2, and 3, Spring 2018

CS 302 Week 9. Jim Williams

COSC 115A: Introduction to Web Authoring Fall 2014

Chapter 6 Lab Classes and Objects

Project #2: Linear Feedback Shift Register

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Chapter 4 Defining Classes I

Exercise 0.1 (Review from lectures no submission required)

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

Chapter 6 Lab Classes and Objects

CMPT 126: Introduction to Computing Science and Programming Fall 2007, Harbour Centre

CS 201, Fall 2016 Sep 28th Exam 1

Frequently Asked Questions last updated 3/17/17 Click the link below for questions related to: Course Exams

SAMPLE. ITS405: Intermediate Networking. Course Description and Outcomes. Participation & Attendance. Credit Hours: 3

CS100M November 30, 2000

CMSC 201 Spring 2016 Lab 12 Classes and Objects

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

Software and Programming 1

BEMIDJI STATE UNIVERSITY COLLEGE OF BUSINESS, TECHNOLOGY AND COMMUNICATION Course syllabus Fall 2012

Advanced Object Oriented Programming EECS2030Z

ASSIGNMENT 5. COMP-202, Winter 2015, All Sections. Due: Tuesday, March 31st, 2015 (23:59)

ECE 122 Engineering Problem Solving with Java

Lab 9 - Classes and Objects Directions

San José State University Department of Computer Science CS-144, Advanced C++ Programming, Section 1, Fall 2017

Documentation Requirements Computer Science 2334 Spring 2016

Object Oriented Programming

CSCE 441 Computer Graphics Fall 2018

Defining Classes. Chap 1 introduced many concepts informally, in this chapter we will be more formal in defining

INFS 2150 (Section A) Fall 2018

I. PREREQUISITE For information regarding prerequisites for this course, please refer to the Academic Course Catalog.

CSCI 355 LAB #2 Spring 2004

Administrivia. IBM Info Session Date: Wed,, Jan 13 Time: 5:30 7 pm Location: Wesbrook 100

How to Access If Rubrics does not appear on your course navbar, click Edit Course, Tools, Rubrics to activate..

Transcription:

Part 1: Group Brainstorm (NO computers during this time) Good programmers think before they begin coding. Part I of this assignment involves brainstorming with a group of peers with absolutely no computers to talk about a strategy for solving this week s lab. Breakup into groups based on your seating (3-4 people per group) and brainstorm about how to solve the problem in Part 2 below. Make sure everyone understands the problem and sketch out potential ways to move toward a solution. Write up a detailed description of your approach in English / pseudocode (English that is structured like a program). This should be 1-2 paragraphs in length (enough to convince the grader that you have a plan for moving toward a solution). You may find it helpful to look over the required readings for this week. Make sure to get the last names of those you have worked with you will need to provide it in your write-up for Part 2. Include in your write-up which course topics you think will be useful for the lab and a detailed plan for completing the exercise & answer the following questions: How will you write the getdata and setdata methods that each have to make a copy of an array? See the underlined text on page 2. Discuss how you will implement the equals method. Is it enough to compare instance variables with ==? Discuss a general approach for the mode method. Discuss test cases for your lab. What types of tests do you think will be in the rubric? Part 2: Submit Individual Brainstorm (You can now use a computer) Login to elc and submit a version of your group's brainstorm, written in your own words under the Assignment Dropbox titled Lab 12 Brainstorm. *Note this is different than the Lab 12 Dropbox where you will submit your.java file for this assignment. Feel free to add any additional information that was not specified to your write-up. We prefer that you submit the brainstorm before the end of the first lab period for the week. However, you can submit until Tuesday night at 9PM. Note: Brainstorms that are submitted without a student attending the lab will not be graded unless the student provides a documented excuse to the graduate TA. Introduction In this lab you will continue to practice defining your own classes, in this case implementing a class called Stat that is described using a UML 1 class diagram. A class diagram describes the fields (variables) and methods defined for a class. It also specifies the parameters and return types for methods, and it describes whether particular fields and methods are public or private. Collectively, the fields and methods of a class are called the members of the class, and the public members define an interface for the class. It is through this interface that interaction with the class and its instances is made possible. UML is widely used in software engineering to specify the structure and behavior of software systems. We will only deal with a single UML class diagram in this lab, but UML allows one to visually represent large numbers of classes and other structures as well as how they interrelate (for instance, that one class is 1 Note that the textbook states that UML stands for Universal Modeling Language. However, Unified Modeling Language is another common name.

a specialization of another). For large software projects, formalisms such as UML are essential if one is to cope with the complexity of the software system. The Stat class stores an array of double values called data. As indicated by the class diagram, you will need to implement public methods to compute the min, max, mode, and average of these values. You will also implement methods to get and set the values held by data. Importantly, data should be a private instance variable, meaning that each instance of the Stat class should have its own copy of the data variable (each object would store different arrays of double values). As indicated in the UML diagram, data has type double[]. This is a reference type, meaning that data will store a reference to the memory location where that array is stored. That is, data will not store the array itself. We want to ensure that each distinct instance of the Stat class uses its own array of doubles, and in order to do that, you should define getdata()so that it creates a copy of the data array and returns a reference to the copy and not a reference to the original. Otherwise, it would be possible to modify the contents of the data array without going through the methods of the Stat class (and this is considered bad design). Similarly, setdata(double[] d) should create a copy of the array d and assign to data a reference to the copy. Review Section 5.3 of the textbook for more information on objects and references. Lab Objectives By the end of the lab, you should be able to create classes utilizing: constructors access modifiers; instance variables; void methods and methods which return values; methods calling other methods; accessor and mutator methods (getters and setters); The equals() method. Prerequisites The lab deals with material from Chapter 5, 6, and 7.1 (one-dimensional arrays). What to Submit The Stat.java file should be submitted to elc for grading. Instructions Use the UML diagram and method descriptions below to create your Stat class.

- data: double[] Stat + Stat() + Stat(double[] d) + getdata(): double[] + setdata(double[] d): void + equals(stat s): boolean + tostring(): String + min(): double + max(): double + average(): double + mode(): double + append(double[] d): void + variance(): double + standarddeviation: double Observe that data should be private; you should define your class so that data (and its values) can only be altered through getdata and setdata. Method Descriptions: Stat() The default constructor for Stat. It should create a double array having a single element 0.0. Stat(double[] d) Constructs a Stat object using the values held in d. The constructor should create a double array of the same length as d and holding copies of the values of d. A reference to this new array should be assigned to data. getdata() This is an accessor (get or getter) method used to retrieve the values of data. This method should not return a reference to data. Instead, it should create a new array containing exactly the values contained in data, and then return a reference to this new array. setdata(double[] d) This is a mutator (set or setter) method used to set the values of the data array. The method should create a new array containing exactly the elements of d and assign to data a reference to this new array (that is, the method should not simply assign d to data). equals(stat s) Returns the boolean value true if the data objects of both the calling Stat object and the passed Stat object s have the same values (and in the same order). Otherwise, it returns false. tostring() Returns a String representation of the data elements stored in the Stat object. Use the samples listed below as guidelines for formatting. min() Returns the minimum of the data array. max() Returns the maximum of the data array. average() Returns the average of the data array. The average is defined to be a double value that returns the mean value of a given array of numbers. mode() The mode is the value that occurs most frequently in a collection of values. In the Stat class, if one value occurs more frequently in data than all others, then mode() should return this value. Otherwise, mode() should return Double.NaN, indicating that no unique

value exists. Note: this method is more difficult to code than the other methods, and it should be completed last. append(double[] d) These methods should create a new double array containing exactly those elements of data followed by those of the array passed as parameter. A reference to this array should be assigned to data. If the parameter is null, then the method should do nothing (no new array created). variance() Returns the variance of the data in the data array. To compute this, find the difference between the value of each element of the data array and the mean, square this distance, and then sum these squared values. The variance is this sum divided by the number of elements in data. Note that if the data array is empty, then Double.NaN should be returned. standarddeviation(): Returns the square root of the variance. If the data array is empty, then Double.NaN should be returned. Once you have created your Stat class, write a main method within the same class to thoroughly test each method in your class. elc Submission and Grading After you have completed and thoroughly tested your program, upload Stat.java to elc to receive credit. Always double check that your submission was successful on elc! The lab will be graded according to the following guidelines. A score between 0 and 100 will be assigned. If the required comment for all labs describing the program and the academic honesty statement is not included at the top of the file, then 10 points will be deducted. Note: this required comment can be found in Lab 02. The program will be evaluated using a separate testing file. Multiple instances of the Stat class will be created and their methods invoked.

Examples Example 1 double[] data = {-5.3, 2.5, 88.9, 0, 0.0, 28, 16.5, 88.9, 109.5, -90, 88.9}; double[] data2 = {100.34, 50.01, 50.01, -8}; Stat stat1 = new Stat(); System.out.println("stat1 data = " + stat1.tostring()); stat1 = new Stat(data); System.out.println("stat1 has been altered."); System.out.println("stat1 mode = " + stat1.mode() + "\n"); Stat stat2 = new Stat(); stat2.setdata(data2); Stat stat3 = new Stat(stat1.getData()); System.out.println("stat2 data = " + stat2.tostring()); System.out.println("stat3 data = " + stat3.tostring()); System.out.println(); System.out.println("stat1 is equal to stat2 using \"equals()\"? " + stat1.equals(stat2)); System.out.println("stat1 is equal to stat3 using \"equals()\"? " + stat1.equals(stat3)); System.out.println("stat1 is equal to stat3 using \"==\"? " + (stat1 == stat3)); stat1 data = [0.0] stat1 has been altered. stat1 data = [-5.3, 2.5, 88.9, 0.0, 0.0, 28.0, 16.5, 88.9, 109.5, -90.0, 88.9] stat1 min = -90.0 stat1 max = 109.5 stat1 average = 29.80909090909091 stat1 mode = 88.9 stat2 data = [100.34, 50.01, 50.01, -8.0] stat3 data = [-5.3, 2.5, 88.9, 0.0, 0.0, 28.0, 16.5, 88.9, 109.5, -90.0, 88.9] stat1 is equal to stat2 using "equals()"? false stat1 is equal to stat3 using "equals()"? true stat1 is equal to stat3 using "=="? false

Example 2 double[] data = {10.0, 20.0, 30.0}; Stat stat1 = new Stat(data); data[0] = 100.0; data[1] = 200.0; data[2] = 300.0; Stat stat2 = new Stat(data); System.out.println("stat2 data = " + stat2.tostring()); System.out.println("The two arrays should be different"); stat1 data = [10.0, 20.0, 30.0] stat2 data = [100.0, 200.0, 300.0] The two arrays should be different Example 3 double[] data1 = {10.0, 20.0, 30.0}; Stat stat1 = new Stat(data1); double[] data2 = stat1.getdata(); System.out.println("The arrays are identical: " + (data1 == data2)); The arrays are identical: false Example 4 double[] data1 = {10.0, 20.0, 30.0}; Stat stat1 = new Stat(); stat1.setdata(data1); Stat stat2 = new Stat(data1); double[] data2 = stat1.getdata(); System.out.println("The arrays are identical: " + (data1 == data2)); System.out.println("stat2 equals stat1: " + stat2.equals(stat1)); System.out.println("stat1 equals stat2: " + stat2.equals(stat1)); The arrays are identical: false stat2 equals stat1: true stat1 equals stat2: true

Example 5 Stat stat1 = new Stat(); stat1 data = [0.0] stat1 min = 0.0 stat1 max = 0.0 stat1 average = 0.0 stat1 mode = 0.0 stat1 data = [0.0] Example 6 double[] data = {1,2,2,3,3,4}; Stat stat1 = new Stat(data); stat1 data = [1.0, 2.0, 2.0, 3.0, 3.0, 4.0] stat1 min = 1.0 stat1 max = 4.0 stat1 average = 2.5 stat1 mode = NaN stat1 data = [1.0, 2.0, 2.0, 3.0, 3.0, 4.0] Example 7 double[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Stat stat1 = new Stat(data1);

System.out.println("stat1 variance = " + stat1.variance()); System.out.println("stat1 standard deviation = " + stat1.standarddeviation()); stat1 data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] stat1 min = 1.0 stat1 max = 9.0 stat1 average = 5.0 stat1 mode = NaN stat1 variance = 6.666666666666667 stat1 standard deviation = 2.581988897471611 Example 8 double[] data1 = {10.0,10.0}; Stat stat1 = new Stat(data1); System.out.println("stat1 variance = " + stat1.variance()); System.out.println("stat1 standard deviation = " + stat1.standarddeviation() + "\n"); double[] data2 = {80.0, 60.0}; stat1.append(data2); System.out.println("stat1 variance = " + stat1.variance()); System.out.println("stat1 standard deviation = " + stat1.standarddeviation() + "\n"); stat1 data = [10.0, 10.0] stat1 min = 10.0 stat1 max = 10.0 stat1 average = 10.0 stat1 mode = 10.0 stat1 variance = 0.0 stat1 standard deviation = 0.0 stat1 data = [10.0, 10.0, 80.0, 60.0] stat1 min = 10.0

stat1 max = 80.0 stat1 average = 40.0 stat1 mode = 10.0 stat1 variance = 950.0 stat1 standard deviation = 30.822070014844883