Arrays & Classes. Problem Statement and Specifications

Size: px
Start display at page:

Download "Arrays & Classes. Problem Statement and Specifications"

Transcription

1 Arrays & Classes Quick Start Compile step once always make -k baseball8 mkdir labs cd labs Execute step mkdir 8 java Baseball8 cd 8 cp /samples/csc/156/labs/8/*. Submit step emacs Player.java & submit csc156abc 8 emacs Baseball8.java & Problem Statement and Specifications This is an exercise that will allow us to demonstrate the use of arrays where each array element is an instance of a user-defined class. This model can be thought of as the means of emulating a rudimentary data base, however the linear nature of an array would make such storage strategies difficult with large amounts of data. The input for this program is a sequential file that contains data for a baseball team where a sequence of lines in the file corresponds to the sequence of records in the array. Each line of the file contains four int values. The first of these int values is to be interpreted as a team player s number. Then comes that player s number of hits, that player s number of walks and that player s number of outs from a game on the team schedule. There is a unique number for each player, but there may be more than one line in the input file that has the same player number. This is to be interpreted as the player with that number having played in multiple games. Consequently, the order of the Player numbers can be random in the file. All output should be displayed on the monitor and should consist of each player s Number on the team followed by the accumulation of Hits, Walks and Outs that were stored in the input file under that player s number. Assignment 8 Statement: Write a program in a file named Baseball8.java that uses a Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class is stored in a file named Player.java and supports a constructor that sets the four data attributes (Number, Hits, Walks and Outs) equal to zero. In addition, there are extractor and mutator methods for each of the data attributes. Finally, there is an overload of the method tostring() that provides support to display the data for each Player in a formatted manner using the System.out.print(), System.out.printf() or System.out.println() methods. After connecting to the input file baseball.txt, the array elements should be instantiated under the assumption that the team will contain no more than 20 Players. Then, for each line of data within baseball.txt, the program should input the Player team Number, the number of Hits, the number of Walks and the number of Outs for that particular game and use the Player methods to update the attribute fields for that 1

2 Player with that team Number. Your program will need to implement a sequential search for each Player team Number to determine if that Player already has data stored within the array or not. Upon reading all of the data from the file, the program should display each Player team Number, and the total number of Hits, the total number of Walks and the total number of Outs that were stored on the input lines of the file. Your Player class is already available for you using the files makefile and Player.java. Your main() method will need 2 methods, one for the sequential search of the array and another for the display of the array. 1/2 lab extra credit Implement an overloaded constructor for the Player class that accepts 4 int parameters (Number, Hits, Walks, Outs). You will need to modify the file Player.java Copy your solution to a file named Baseball88.java and further modify the program to produce identical output to Baseball8.java but invoke the overloaded constructor when you come to steps 7) and 7a) in the main() method s algorithm to initialize the corresponding Player data attributes with the values that were input. Use the commands make -k baseball88, java Baseball88 and submit csc156abc 88 to compile, execute and submit your assignment, respectively. This problem is related to an inventory update algorithm whereby different products have arrived within different shipments over periods of time. As the shipments arrive, we need to update the records in the data base so that we have an accurate record of the number of products (identified by the product number) that are within the inventory. So, as the Player on the team[] accumulates more Hits, Walks and Outs, we increase the number of those attributes that are in storage. Of course, in the inventory model, products are also sold or shipped to another warehouse causing us to decrease the numbers that we have on hand. That part of the algorithm will not be necessary in the baseball model. Assignment 8 Specifications: Process connect to the input file baseball.txt and set the team size to 0 Output a descriptive message about the program Process declare an array of length 20 to hold the instances of class Player Process loop over the elements of the array Process instantiate each object within the array of Player Process repeat until the end-of-file Input the Player Number, the Hits, the Walks and the Outs Process search for the Player Number within the initialized array values Process if the Player Number is not already in the array Process store the Player s Number, Hits, Walks and Outs Process else update the Player s Hits, Walks and Outs Output display the Player s Number, the total numbers of Hits, Walks and Outs Process disconnect from the input file baseball.txt Object Analysis and Algorithmic Development The main() method for this program is in the file Baseball8.java. The code in the start-up file connects to the sequential input file baseball.txt and inputs all of the int values in the file, but does not produce any output beyond the informational message. We ll need to remember to disconnect from the input file when we re done. Once again, all output should be displayed to the monitor. 1. process to connect the input file fin to the program and set teamsize to 0 2

3 2. output an informational message to the screen about the program 3. process declare an array of length 20 of type Player named team[] (a) process for each value of i from 0 to 19 (b) process instantiate array element team[i] 4. process while not-end-of-file fin (a) input the Number, Hits, Walks and Runs of a Player (b) process determine if the Number is stored in the first teamsize elements (c) process if the Number is not stored in the array i. process Number of teamsize is argument to setnumber() ii. process Hits of teamsize is argument to sethits() iii. process Walks of teamsize is argument to setwalks() iv. process Outs of teamsize is argument to setouts() v. process increase teamsize by 1 (d) process else if team[index] contains Number i. process Hits + gethits() of index is argument to sethits() ii. process Walks + getwalks() of index is argument to setwalks() iii. process Outs + getouts() of index is argument to setouts() 5. output display Player s Number, Hits, Walks, Outs 6. process disconnect from the file fin Control structures represented above include steps 3.a and 3.b that are coded with a for statement to instantiate the array elements, steps 4.(a) through 4.(d) that are coded as an end of file while statement, and steps 4.(c) and 4.(d) that represent the true and false clauses of an if statement. When we implement the sequential search algorithm below, we ll design it to return -1 if the Player Number is not within the first teamsize elements of the array team[] and the index of the array team[] where Number is stored otherwise. Lines that are displayed in blue represent areas where you ll need to write or modify code to complete this assignment. Pseudo Code for the main() Method Statement Data objects 1a) connect to input file fin Scanner wrapped around a FileReader & String 1b) initialize the teamsize to 0 int objects 2) output an informational message System.out and String objects 3) declare array of type Player of size 20 Player array & int object 3a) loop over int values from 0 to 19 int objects 3b) instantiate i th array element int object, Player array and constructor 4) loop on end of file fin Scanner wrapped around a FileReader methods 5) input the Number, Hits, Walks, & Outs from fin Scanner wrapped around a FileReader & int objects 6) find the index of this Number method findnumber(), Player array & int objects 7) if index < 0 int objects 7a) store Number, Hits, Walks & Outs in Player array methods & int objects team[teamsize] 8) else 8a) update team[index] s Hits, Walks & Outs Player array methods & int objects. 9) output the team[] data by invoking displayarray method Player array & int objects displayarray() 10) disconnect from input file fin fin.close() method 3

4 To clarify the above structure, steps 5)-8) are in the while loop at step 4). Step 7a is in the true path of the if statement of step 7) and steps 8) and 8a) are the false path of that if. The method findnumber() should be coded in the file Baseball8.java and should implement a sequential search of the array team[] looking for the first occurrence of the parameter Number and should return either -1 upon failure to find the Number or the index into team[] where Number is stored otherwise. The method will also need a parameter to know the team size to control the looping through the Player array. 1. process initialize an int variable Save to -1 and assume that Number is not in array team[] 2. process loop over indices 0 through team size if team[index] is equal to Number (a) update Save to the index value (b) break from the loop 4. return Save To clarify the structure above, step 3) is in the loop that is at step 2). Steps 3a) and 3b) are on the true path of the if statement at step 3). Pseudo Code for the findnumber() Method Statement Data objects 1) assume failure and set Save to -1 int objects 2) loop over index from 0 to team size - 1 int objects 3) test Number less than 0 Player team[index] method & int objects 4) set Save to index & break int objects 5) return the value in Save int objects The method displayarray() simply displays some column headings and then loops through the team size elements of the array team[], displaying each Player. It is left as an exercise to develop. Coding for Compilation Logon to your csc.oakton.edu account and create a new subdirectory of the labs directory called 8 to work on your assignment. cd labs mkdir 8 cd 8 You ll need to copy the makefile, Baseball8.java and baseball.txt files that are provided over to your local directory by issuing the following command. cp /samples/csc/156/labs/8/*. emacs Baseball8.java & Examine the contents of Baseball8.java as compared to our discussion above. We ve provided you with a compilable program that loops through the contents of the file. When we use input files, problems or exceptions can arise. There are several ways to deal with such problems using the catch and throw commands that we will not amplify here. What we will do is identify the most common error that occurs with files (it can t be found) and will identify that the main() method throws a FileNotFoundException. Since we ve coded the Player class before the first Checkpoint, we re ready to examine and add to the code in Baseball8.java to complete the assignment. Note that steps in blue represent lines of code that you should author to complete the assignment. 4

5 The Object Player CSC Assignment 8 Baseball Before we discuss the various methods to manipulate the Player objects, we should discuss the construction of the object itself. This occurs in the file Player.java in a Java class. There are 4 data attributes that should be private of type int. Each instance of a Player class will need their own separate copies of these variables. Declare these within the class, but separate from any methods so that they will exhibit class scope. Obvious names for these would be Number, Hits, Walks and Outs. The general format of the Player class requires the use of a class statement in the file Player.java that looks like the following. public class class name declarations; statement 1 ; statement 2 ;. statement n ; We ll want everyone to have access to the class, and so we ll want that to be public. However, we ll not want everyone to have direct access to the data attributes stored in the Player and so we ll need to identify those as private. The code for the class statement necessary that includes the data attributes that we ve described above is as follows. public class Player private int Number, Hits, Walks, Outs; Constructors The support of object declaration and initialization is the responsibility of the constructor method. Typically, constructors support both uninitialized object instantiation as well as initialized. Our constructor will only support default initialization that sets each data attribute to zero. Constructors have no return type and are named after the class. The code for this constructor within the Player class would look as follows. public class Player private int Number, Hits, Walks, Outs; public Player() int Number = Hits = Walks = Outs = 0; Extractors The purpose of the extractor is to return information about the object without modifying the object. This is how we ll support knowledge of what data is stored in the Player without providing direct access to the private data attributes. We can name the extractor any valid Java name, but it is very popular to name an extractor get(). Given the declared Player objects discussed above, we will need one extractor for each data attribute. 5

6 These should be named getnumber(), gethits(), getwalks() and getouts() and should all return type int. We ll show the code for the getnumber() extractor, the others are similar. public class Player private int Number, Hits, Walks, Outs; public Player() int Number = Hits = Walks = Outs = 0; public int getnumber() return Number; Mutators The purpose of the mutator is to modify information stored in the object. This is how we ll support modifying the data stored in the Player without providing direct access to the data attributes. We can name the mutator any valid Java name, but it is very popular to name them set(). You will need 4 mutator methods, each returning void with an int parameter. These simply set each of the data attributes equal to the value of the parameter and should be named setnumber(), sethits(), setwalks() and setouts(). We ll show the code for the sethits() mutator, the others are similar. public class Player private int Number, Hits, Walks, Outs; public Player() int Number = Hits = Walks = Outs = 0; public int getnumber() return Number; public void sethits( int h ) Hits = h; tostring() Methods For output, the Java language takes advantage of the fact that all displayed objects have a String representation. The strategy is to overload a method called tostring() that has no parameters and returns a String representation of the object to be displayed.we ll conclude this discussion by implementing the output of Player objects below. Given that we have numeric data that we wish to display, it may be in our interest have this method return an instance of String.format() so that the values within the return value are formatted appropriately. public class Player 6

7 private int Number, Hits, Walks, Outs; public Player() int Number = Hits = Walks = Outs = 0; public int getnumber() return Number; public void sethits( int h ) Hits = h; public String tostring() String s = new String(); s = String.format("%2d", Number) + "\t" + String.format("%2d", Hits) + "\t" + String.format("%2d", Walks) + "\t" + String.format("%2d", Outs); CSC Assignment 8 Baseball Figure 1 displays a Unified Modeling Language (UML) diagram of the Player class. Player -Number : int -Hits : int -Walks : int -Outs : int +Player() +getnumber() : int +gethits() : int +getwalks() : int +getouts() : int +setnumber(int) : void +sethits(int) : void +setwalks(int) : void +setouts(int) : void +tostring() : String Figure 1: Lab 8 Player Unified Modeling Language Diagram Checkpoint 1 Let s see if we can get this much of our program to compile before proceeding. Save your program to disk by choosing the Save command from the Files menu of your emacs session. Then, compile your program by choosing the Compile... command from the Tools menu and change the make -k that is displayed to make -k baseball8 Compiler errors can be parsed with the keystroke C-x and need to be repaired before proceeding. Execute your program with the command java Baseball8 You should see the display of the informational message. We ll have another Checkpoint later to examine the complete solution of the assignment. 7

8 Declaration of Variables CSC Assignment 8 Baseball The variables to be declared within the main(), findnumber() and displayarray() methods have been discussed in the pseudo-code above. Follow the Pseudo-code for main() Step 1) // connect to input file fin and initialize teamsize to 0 This declaration wraps a FileReader object with a Scanner object so that we can use Scanner methods that were similar to what we used when input came from the keyboard. Scanner fin = new Scanner(new FileReader("baseball.txt")); The variable teamsize is simply an int value that can be initialized at declaration. Step 2) // output an informational message This is no different than other monitor output messages that we ve been coding since the first days of the course. Step 3) // declare array of type Player of size 20 The array should be declared like any other array, so this step will follow the general format for such declarations. We ll assume that the name of this array is team[]. Player [] array name = new Player[array size]; Steps 3a-3b) // loop over int values from 0 to 19 // instantiate the i th array element What you ll now need to do is invoke your constructor Player() for each array element. Code a for loop that loops from 0 to 19 and set the i th array element to new Player(). Step 4) // loop on the end of file condition This code has already been supplied for you in the file Baseball8.java. It is no different that we ve used in previous assignments. Step 5) // input the team number from fin // input that player s hits from fin // input that player s walks from fin // input that player s outs from fin Once again, we take advantage of the Scanner methods for these lines of code. Note that the int variables from the main() method that hold the input values are distinct from the attribute variables for each instance of the Player class (Hits, Walks, Outs). 8

9 Step 6) CSC Assignment 8 Baseball // find the index of this Player s number Our recommendation is that you code this statement as a comment as it will be helpful to compile what you ve coded at the next Checkpoint before you code the method findnumber(). This is an invocation of the method findnumber(). You will need to save this return value as an index into the array when the search is successful. The parameters will include the array team[], the Number that you re searching for and the teamsize. Step 7) // test for new number in the list This is simply an if statement that assumes that the return value of method findnumber() will return a negative value when the Number sent to it at the previous step is not found. Step 7a)-7e) // set the Number field for team[teamsize] // set the Hits field for team[teamsize] // set the Walks field for team[teamsize] // set the Outs field for team[teamsize] // increase teamsize by 1 Since the Number was not found in the list, we ll simply put it at the end of the list. For each of the data attributes, invoke team[teamsize].sethits() or team[teamsize].setwalks() or team[teamsize].setouts() before increasing teamsize by 1. Step 8) // else This is the false path of the if statement of step 7). Steps 8a)-8c) // update the Hits field for team[index] // update the Walks field for team[index] // update the Outs field for team[index] Since the Number was found in the list, there s no need to store Number or increase the teamsize. We ll need to increase the Hits, Walks and Outs data attributes using the index variable that was returned by the method findnumber(). The manned in which to do this is to compose the two methods get with set that are available for each of the data attributes. We ll provide the code for updating the Hits where we assume that the variable hits represents the number of Hits input for this Player s Number in the main() method. The method invocations for Walks and Outs are similar. team[index].sethits(hits + team[index].gethits()); Step 9 // display the results This will be an invocation of the method displayarray(). You will need to send the array team[] and the teamsize as parameters. Step 10 // disconnect from input file fin All files that are opened should be disconnected. This line has been provided for you. 9

10 fin.close(); Checkpoint 2 Save your program to disk by choosing the Save Buffer command from the Files menu of your emacs session. Then, compile your program by choosing the Compile... command from the Tools menu and change the make -k that is displayed to make -k baseball8. Compiler errors can be parsed with the keystroke C-x and need to be repaired before your program can execute. This keystroke will also ensure that the correct file is in the buffer to examine lines that generated compiler errors. When your program has compiled, we ll need to move on to code the method findnumber() before we can execute it. Follow the Pseudo-code for method findnumber() This method returns an int value that will be -1 when the search is not successful, and a value that we ve been referring to as index when it is successful. The post condition of the method is -1 index < team size. The parameters for the method are the array team[], the Player Number, and the team size. Step 1) // assume that this Number is not in the list This is accomplished by declaring a local int variable Save that is initialized to -1. Step 2) // loop over the list length This is a for statement that loops over the indices from 0 through team size - 1. Step 3) // exit the loop if the Number is found This is an if statement that tests the equality of Number and team[i].getnumber(). When this condition is true, you should store the index in the variable Save and exit the for statement. Step 4) // return either the found index or -1 in variable Save If the loop completes its execution and never finds the Number, then the value stored in Save at Step 1 will never have been updated and the method returns -1. If the condition at Step 3 every occurs, the loop is exited immediately and the method returns the index into team[] where the Number is stored. Once you ve coded the method findnumber(), you can remove the comment that you placed in Step 6 with the invocation of the method. At this point, you should recompile and execute your program. Testing for errors The usual source of errors in these types of programs can occur in one of 3 areas. The use of the files, the use of the arrays and the use of the classes. The file activity here was given to you and if you follow the pseudo code that was given with file activity, you should not have a problem with those commands. The most common problem with the use of the arrays is the index variable. If you see an ArrayIndexOutOfBounds error message, the error is in the manner in which you re accessing the array element. The index into the array is either too large or negative. The possible error with the classes could be in the algorithms for the method. Recall that all the constructor should do is to set each attribute variable to 0. Each extractor should simply return its corresponding attribute variable, and each mutator should set it s attribute variable to the value of its parameter. If you re stuck with those simple algorithms, the only other place where something could go wrong is when you 10

11 update the attribute variable within the end of file loop. There is a correct version of the output of this program at this link. Printing and submitting Once you are satisfied with the correctness of your program, print it as you did with previous assignments by using the following command that assumes that you are working in the room 1234 at Oakton. Retrieve your copy from the printer. printer 1234 Player.java printer 1234 Baseball8.java Finally, submit your program with the following command that assumes that you are registered in section abc of CSC 156. submit csc156abc 8 11

Repetition Using the End of File Condition

Repetition Using the End of File Condition Repetition Using the End of File Condition Quick Start Compile step once always javac Scan4.java mkdir labs cd labs Execute step mkdir 4 java Scan4 cd 4 cp /samples/csc/156/labs/4/*. Submit step emacs

More information

Repetitive Program Execution

Repetitive Program Execution Repetitive Program Execution Quick Start Compile step once always mkdir labs javac Vowel3java cd labs mkdir 3 Execute step cd 3 java Vowel3 cp /samples/csc/156/labs/3/* Submit step emacs Vowel3java & submit

More information

Graphics User Defined Forms, Part I

Graphics User Defined Forms, Part I Graphics User Defined Forms, Part I Quick Start Compile step once always mkdir labs javac PropertyTax5.java cd labs mkdir 5 Execute step cd 5 java PropertyTax5 cp /samples/csc/156/labs/5/*. cp PropertyTax1.java

More information

GUI Forms and Events, Part II

GUI Forms and Events, Part II GUI Forms and Events, Part II Quick Start Compile step once always mkdir labs javac PropertyTax6.java cd labs Execute step mkdir 6 java PropertyTax6 cd 6 cp../5/propertytax5.java PropertyTax6.java Submit

More information

GUI, Events and Applets from Applications, Part III

GUI, Events and Applets from Applications, Part III GUI, Events and Applets from Applications, Part III Quick Start Compile step once always javac PropertyTax6.java mkdir labs cd labs Execute step mkdir 6 appletviewer PropertyTax6.htm cd 6 emacs PropertyTax6.htm

More information

Sequential Program Execution

Sequential Program Execution Sequential Program Execution Quick Start Compile step once always g++ -o Realtor1 Realtor1.cpp mkdir labs cd labs Execute step mkdir 1 Realtor1 cd 1 cp../0/realtor.cpp Realtor1.cpp Submit step cp /samples/csc/155/labs/1/*.

More information

Editing, Compiling, Executing and Submitting Programs

Editing, Compiling, Executing and Submitting Programs Editing, Compiling, Executing and Submitting Programs Quick Start Compile step once always mkdir labs javac Realtor.java cd labs mkdir 0 Execute step java Realtor cd 0 Submit step emacs Realtor.java &

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points. Java for Non Majors Final Study Guide April 26, 2017 The test consists of 1. Multiple choice questions 2. Given code, find the output 3. Code writing questions 4. Code debugging question 5. Short answer

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Gaddis_516907_Java 4/10/07 2:10 PM Page 51 Chapter 6 Lab Classes and Objects Objectives Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Lab Objectives Chapter 6 Lab Classes and Objects Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value Be able to write instance methods that

More information

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

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods

More information

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18 Assignment Lecture 9 Logical Operations Formatted Print Printf Increment and decrement Read through 3.9, 3.10 Read 4.1. 4.2, 4.3 Go through checkpoint exercise 4.1 Logical Operations - Motivation Logical

More information

Anatomy of a Class Encapsulation Anatomy of a Method

Anatomy of a Class Encapsulation Anatomy of a Method Writing Classes Writing Classes We've been using predefined classes. Now we will learn to write our own classes to define objects Chapter 4 focuses on: class definitions instance data encapsulation and

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Principles of Computer Science I

Principles of Computer Science I Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120A - Fall 2004 Lecture Unit 7 Review Chapter 4 Boolean data type and operators (&&,,) Selection control flow structure if, if-else, nested

More information

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently. Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently. User Request: Create a simple magazine data system. Milestones:

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 30 April 4, 2018 I/O & Histogram Demo Chapters 28 HW7: Chat Server Announcements No penalty for late submission by tomorrow (which is a HARD deadline!)

More information

COMP 110 Programming Exercise: Simulation of the Game of Craps

COMP 110 Programming Exercise: Simulation of the Game of Craps COMP 110 Programming Exercise: Simulation of the Game of Craps Craps is a game of chance played by rolling two dice for a series of rolls and placing bets on the outcomes. The background on probability,

More information

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

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects Administrative Stuff September 12, 2007 HW3 is due on Friday No new HW will be out this week Next Tuesday we will have Midterm 1: Sep 18 @ 6:30 7:45pm. Location: Curtiss Hall 127 (classroom) On Monday

More information

Table of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited

Table of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited Table of Contents Date(s) Title/Topic Page #s 11/6 Chapter 3 Reflection/Corrections 56 Chapter 4: Writing Classes 4.1 Objects Revisited 57 58-59 look over your Ch 3 Tests and write down comments/ reflections/corrections

More information

Programming Exercise 14: Inheritance and Polymorphism

Programming Exercise 14: Inheritance and Polymorphism Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.

More information

Project #1 Computer Science 2334 Fall 2008

Project #1 Computer Science 2334 Fall 2008 Project #1 Computer Science 2334 Fall 2008 User Request: Create a Word Verification System. Milestones: 1. Use program arguments to specify a file name. 10 points 2. Use simple File I/O to read a file.

More information

Chapter 4: Writing Classes

Chapter 4: Writing Classes Chapter 4: Writing Classes Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Writing Classes We've been using predefined classes. Now we will learn to write our own

More information

Arrays OBJECTIVES. In this chapter you will learn:

Arrays OBJECTIVES. In this chapter you will learn: 7 Arrays Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then

More information

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently. Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently. User Request: Create a simple movie data system. Milestones: 1. Use

More information

C# Programming for Developers Course Labs Contents

C# Programming for Developers Course Labs Contents C# Programming for Developers Course Labs Contents C# Programming for Developers...1 Course Labs Contents...1 Introduction to C#...3 Aims...3 Your First C# Program...3 C# The Basics...5 The Aims...5 Declaring

More information

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous Assignment 3 Methods Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required. Notes:

More information

CS 116. Lab Assignment # 1 1

CS 116. Lab Assignment # 1 1 Points: 2 Submission CS 116 Lab Assignment # 1 1 o Deadline: Friday 02/05 11:59 PM o Submit on Blackboard under assignment Lab1. Please make sure that you click the Submit button and not just Save. Late

More information

ISBN. Title. Author(s). Publisher. Year published. Pages... Baseball batting statistics for one player: Hits. Walks. Batting average. Strike outs...

ISBN. Title. Author(s). Publisher. Year published. Pages... Baseball batting statistics for one player: Hits. Walks. Batting average. Strike outs... Why User-Defined Classes? Primitive data types (int, long, double, etc.) provide only a limited ability to represent data from complex objects such as: Books: ISBN. Title. Author(s). Publisher. Year published.

More information

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2017-18 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Answer FOUR questions. All questions carry equal weight. Notes are

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

COMP-202: Foundations of Programming. Lecture 22: File I/O Jackie Cheung, Winter 2015

COMP-202: Foundations of Programming. Lecture 22: File I/O Jackie Cheung, Winter 2015 COMP-202: Foundations of Programming Lecture 22: File I/O Jackie Cheung, Winter 2015 Announcements Assignment 5 due Tue Mar 31 at 11:59pm Quiz 6 due Tue Apr 7 at 11:59pm 2 Review 1. What is a graph? How

More information

CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams

CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams In this lab you will write a set of simple Java interfaces and classes that use inheritance and polymorphism. You will also write code that uses

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

CS 6353 Compiler Construction Project Assignments

CS 6353 Compiler Construction Project Assignments CS 6353 Compiler Construction Project Assignments In this project, you need to implement a compiler for a language defined in this handout. The programming language you need to use is C or C++ (and the

More information

Java for Non Majors Spring 2018

Java for Non Majors Spring 2018 Java for Non Majors Spring 2018 Final Study Guide The test consists of 1. Multiple choice questions - 15 x 2 = 30 points 2. Given code, find the output - 3 x 5 = 15 points 3. Short answer questions - 3

More information

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors

More information

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 ); Sample Final Exam 1. Evaluate each of the following expressions and show the result and data type of each: Expression Value Data Type 14 % 5 1 / 2 + 1 / 3 + 1 / 4 4.0 / 2.0 Math.pow(2.0, 3.0) (double)(2

More information

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group. CMPS 12L Introduction to Programming Lab Assignment 2 We have three goals in this assignment: to learn about file permissions in Unix, to get a basic introduction to the Andrew File System and it s directory

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name CSC 1051 Algorithms and Data Structures I Final Examination May 12, 2017 Name Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces provided.

More information

An Introduction To Writing Your Own Classes CSC 123 Fall 2018 Howard Rosenthal

An Introduction To Writing Your Own Classes CSC 123 Fall 2018 Howard Rosenthal An Introduction To Writing Your Own Classes CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Understand Object Oriented Programming The Syntax of Class Definitions Constructors this Object Oriented "Hello

More information

Active Learning: Streams

Active Learning: Streams Lecture 29 Active Learning: Streams The Logger Application 2 1 Goals Using the framework of the Logger application, we are going to explore three ways to read and write data using Java streams: 1. as text

More information

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

CSCI 355 Lab #2 Spring 2007

CSCI 355 Lab #2 Spring 2007 CSCI 355 Lab #2 Spring 2007 More Java Objectives: 1. To explore several Unix commands for displaying information about processes. 2. To explore some differences between Java and C++. 3. To write Java applications

More information

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1 Designing Classes Where do objects come from? CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

More information

CS1004: Intro to CS in Java, Spring 2005

CS1004: Intro to CS in Java, Spring 2005 CS1004: Intro to CS in Java, Spring 2005 Lecture #13: Java OO cont d. Janak J Parekh janak@cs.columbia.edu Administrivia Homework due next week Problem #2 revisited Constructors, revisited Remember: a

More information

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section:

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section: 7 Arrays Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then

More information

3 Getting Started with Objects

3 Getting Started with Objects 3 Getting Started with Objects If you are an experienced IDE user, you may be able to do this tutorial without having done the previous tutorial, Getting Started. However, at some point you should read

More information

Introduction to Java Applications

Introduction to Java Applications 2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use

More information

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes 1 CS257 Computer Science II Kevin Sahr, PhD Lecture 5: Writing Object Classes Object Class 2 objects are the basic building blocks of programs in Object Oriented Programming (OOP) languages objects consist

More information

Exceptions and I/O: sections Introductory Programming. Errors in programs. Exceptions

Exceptions and I/O: sections Introductory Programming. Errors in programs. Exceptions Introductory Programming Exceptions and I/O: sections 80 83 Anne Haxthausen a IMM, DTU 1 Exceptions (section 80) 2 Input and output (I/O) (sections 81-83) a Parts of this material are inspired by/originate

More information

Introductory Programming Exceptions and I/O: sections

Introductory Programming Exceptions and I/O: sections Introductory Programming Exceptions and I/O: sections 80 83 Anne Haxthausen a IMM, DTU 1 Exceptions (section 80) 2 Input and output (I/O) (sections 81-83) a Parts of this material are inspired by/originate

More information

APCS:: Basketball Statistics Program Activity

APCS:: Basketball Statistics Program Activity APCS:: Basketball Statistics Program Activity This assignment is LARGE. It will involve some very serious programming, but in the end you will have a real piece of software that you have created. Abstract:

More information

Chapter 10. File I/O. Copyright 2016 Pearson Inc. All rights reserved.

Chapter 10. File I/O. Copyright 2016 Pearson Inc. All rights reserved. Chapter 10 File I/O Copyright 2016 Pearson Inc. All rights reserved. Streams A stream is an object that enables the flow of data between a program and some I/O device or file If the data flows into a program,

More information

EE 422C HW 6 Multithreaded Programming

EE 422C HW 6 Multithreaded Programming EE 422C HW 6 Multithreaded Programming 100 Points Due: Monday 4/16/18 at 11:59pm Problem A certain theater plays one show each night. The theater has multiple box office outlets to sell tickets, and the

More information

Lab 5: Java IO 12:00 PM, Feb 21, 2018

Lab 5: Java IO 12:00 PM, Feb 21, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 5: Java IO 12:00 PM, Feb 21, 2018 1 The Java IO Library 1 2 Program Arguments 2 3 Readers, Writers, and Buffers 2 3.1 Buffering

More information

Full file at

Full file at Chapter 1 Primitive Java Weiss 4 th Edition Solutions to Exercises (US Version) 1.1 Key Concepts and How To Teach Them This chapter introduces primitive features of Java found in all languages such as

More information

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 2 EXAMINATIONS 2013/2014 CI101/CI101H. Programming

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 2 EXAMINATIONS 2013/2014 CI101/CI101H. Programming s SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 2 EXAMINATIONS 2013/2014 CI101/CI101H Programming Time allowed: THREE hours Answer: ALL questions Items permitted: Items supplied: There is no

More information

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

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists COMP-202B, Winter 2009, All Sections Due: Tuesday, April 14, 2009 (23:55) You MUST do this assignment individually and, unless otherwise

More information

You must define a class that represents songs. Your class will implement the Song interface in $master/proj2/cs61b/song.java.

You must define a class that represents songs. Your class will implement the Song interface in $master/proj2/cs61b/song.java. CS 61B Summer 2005 Project 2 (spec version 2.0) CD Database Due: July 22, 2005 5pm Overview This project will give you practice with Linked List data structures and sorting algorithms. You will be building

More information

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation. Java: Classes Introduction A class defines the abstract characteristics of a thing (object), including its attributes and what it can do. Every Java program is composed of at least one class. From a programming

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name: CSC 1051 Algorithms and Data Structures I Final Examination May 2, 2015 Name: Question Value 1 10 Score 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 20 TOTAL 100 Please answer questions in the spaces provided.

More information

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() { Scoping, Static Variables, Overloading, Packages In this lecture, we will examine in more detail the notion of scope for variables. We ve already indicated that variables only exist within the block they

More information

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class? Administration Objects and Arrays CS 99 Summer 2000 Michael Clarkson Lecture 6 Read clarified grading policies Lab 6 due tomorrow Submit.java files in a folder named Lab6 Lab 7 Posted today Upson Lab closed

More information

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x );

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x ); Chapter 5 Methods Sections Pages Review Questions Programming Exercises 5.1 5.11 142 166 1 18 2 22 (evens), 30 Method Example 1. This is of a main() method using a another method, f. public class FirstMethod

More information

COMP 401: THE DUAL ROLE OF A CLASS. Instructor: Prasun Dewan (FB 150,

COMP 401: THE DUAL ROLE OF A CLASS. Instructor: Prasun Dewan (FB 150, COMP 401: THE DUAL ROLE OF A CLASS Instructor: Prasun Dewan (FB 150, dewan@unc.edu) SCRIPTS ANALOGY Script Program Follows Follows Theater Performer 2 STRUCTURING IN SCRIPTS Script (Folder) Act (File)

More information

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 101 Fall 2006 Midterm 3 Name:  ID: You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure

More information

Project #1 Exceptions and Simple System Calls

Project #1 Exceptions and Simple System Calls Project #1 Exceptions and Simple System Calls Introduction to Operating Systems Assigned: January 21, 2004 CSE421 Due: February 17, 2004 11:59:59 PM The first project is designed to further your understanding

More information

CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, :30pm)

CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, :30pm) CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, 2015 11:30pm) This program focuses on binary trees and recursion. Turn in the following files using the link on the

More information

Simple Java Input/Output

Simple Java Input/Output Simple Java Input/Output Prologue They say you can hold seven plus or minus two pieces of information in your mind. I can t remember how to open files in Java. I ve written chapters on it. I ve done it

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 31 November 17, 2017 I/O & Histogram Demo Chapters 28 Announcements HW8: SpellChecker Available on the website and Codio Due next Tuesday, November

More information

1.00 Lecture 30. Sending information to a Java program

1.00 Lecture 30. Sending information to a Java program 1.00 Lecture 30 Input/Output Introduction to Streams Reading for next time: Big Java 15.5-15.7 Sending information to a Java program So far: use a GUI limited to specific interaction with user sometimes

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

CSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, :30pm)

CSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, :30pm) CSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, 2015 11:30pm) This assignment focuses on binary trees and recursion. Turn in the following files using the link

More information

Summary. Recursion. Overall Assignment Description. Part 1: Recursively Searching Files and Directories

Summary. Recursion. Overall Assignment Description. Part 1: Recursively Searching Files and Directories Recursion Overall Assignment Description This assignment consists of two parts, both dealing with recursion. In the first, you will write a program that recursively searches a directory tree. In the second,

More information

Logic & program control part 2: Simple selection structures

Logic & program control part 2: Simple selection structures Logic & program control part 2: Simple selection structures Summary of logical expressions in Java boolean expression means an expression whose value is true or false An expression is any valid combination

More information

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

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology Computer Science II OO Programming Classes Scott C Johnson Rochester Institute of Technology Outline Object-Oriented (OO) Programming Review Initial Implementation Constructors Other Standard Behaviors

More information

11/19/2014. Objects. Chapter 4: Writing Classes. Classes. Writing Classes. Java Software Solutions for AP* Computer Science A 2nd Edition

11/19/2014. Objects. Chapter 4: Writing Classes. Classes. Writing Classes. Java Software Solutions for AP* Computer Science A 2nd Edition Chapter 4: Writing Classes Objects An object has: Presentation slides for state - descriptive characteristics Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis, William Loftus,

More information

System.out.print(); Scanner.nextLine(); String.compareTo();

System.out.print(); Scanner.nextLine(); String.compareTo(); System.out.print(); Scanner.nextLine(); String.compareTo(); Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 6 A First Look at Classes Chapter Topics 6.1 Objects and

More information

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

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING INPUT AND OUTPUT Input devices Keyboard Mouse Hard drive Network Digital camera Microphone Output devices.

More information

Classes Classes 2 / 36

Classes Classes 2 / 36 Classes 1 / 36 Classes Classes 2 / 36 Anatomy of a Class By the end of next lecture, you ll understand everything in this class definition. package edu. gatech. cs1331. card ; import java. util. Arrays

More information

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Repe$$on CSC 121 Spring 2017 Howard Rosenthal Repe$$on CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Learn the following three repetition structures in Java, their syntax, their similarities and differences, and how to avoid common errors when

More information

BM214E Object Oriented Programming Lecture 8

BM214E Object Oriented Programming Lecture 8 BM214E Object Oriented Programming Lecture 8 Instance vs. Class Declarations Instance vs. Class Declarations Don t be fooled. Just because a variable might be declared as a field within a class that does

More information

Classes, interfaces, & documentation. Review of basic building blocks

Classes, interfaces, & documentation. Review of basic building blocks Classes, interfaces, & documentation Review of basic building blocks Objects Data structures literally, storage containers for data constitute object knowledge or state Operations an object can perform

More information

Agenda & Reading. Python Vs Java. COMPSCI 230 S Software Construction

Agenda & Reading. Python Vs Java. COMPSCI 230 S Software Construction COMPSCI 230 S2 2016 Software Construction File Input/Output 2 Agenda & Reading Agenda: Introduction Byte Streams FileInputStream & FileOutputStream BufferedInputStream & BufferedOutputStream Character

More information

Chapter 7 Classes & Objects, Part B

Chapter 7 Classes & Objects, Part B Chapter 7 Classes & Objects, Part B These note present Dog simulation example that shows how we go about OO modeling. A number of new things are introduced. They also present the Person > BirthDate example.

More information

Java and OOP. Part 2 Classes and objects

Java and OOP. Part 2 Classes and objects Java and OOP Part 2 Classes and objects 1 Objects OOP programs make and use objects An object has data members (fields) An object has methods The program can tell an object to execute some of its methods

More information

Java Input/Output. 11 April 2013 OSU CSE 1

Java Input/Output. 11 April 2013 OSU CSE 1 Java Input/Output 11 April 2013 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter

More information

CIS 162 Project 4 Farkle (a dice game)

CIS 162 Project 4 Farkle (a dice game) CIS 162 Project 4 Farkle (a dice game) Due Date at the start of class on Monday, 3 December (be prepared for quick demo and zybook test) Before Starting the Project Read chapter 10 (ArrayList) and 13 (arrays)

More information

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

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects CmSc 150 Fundamentals of Computing I Lesson 28: Introduction to Classes and Objects in Java 1. Classes and Objects True object-oriented programming is based on defining classes that represent objects with

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

Static Methods. Why use methods?

Static Methods. Why use methods? Static Methods A method is just a collection of code. They are also called functions or procedures. It provides a way to break a larger program up into smaller, reusable chunks. This also has the benefit

More information

Defining Classes and Methods

Defining Classes and Methods Defining Classes and Methods Chapter 5 Modified by James O Reilly Class and Method Definitions OOP- Object Oriented Programming Big Ideas: Group data and related functions (methods) into Objects (Encapsulation)

More information