Notes on Standalone Entity - Introduction-Computer Science | CS 110, Study notes of Computer Science

Material Type: Notes; Professor: Tanner; Class: Introduction-Computer Science; Subject: Computer Science; University: West Virginia University; Term: Spring 2009;

Typology: Study notes

Pre 2010

Uploaded on 07/31/2009

koofers-user-7l8-1
koofers-user-7l8-1 🇺🇸

7 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 110 Notes Classes III 1
Copyright C. Tanner 2009
Class
o Standalone entity
o Object
o Application class
Driver of program
Contains main method
o Worker or support classes
Reusable elements
Model real world entities
o Decompose problem into series of classes
Class is made up of
o Data
Data members
o Operations
Act upon the data
Member functions
o Encapsulate them into one object – class
Provide a mechanism to “hide” data members from other classes
Isolates data member from unauthorized change
Private
Provide operations to modify and return data members
o Class definition
Modifer(s) class ClassName modifer(s)
{
Data members/fields
Member methods
}
Data members/fields
o Constant declarations
o Variable declarations
Member methods
o Automatically have access to the data members and constants
o Direct access, scope
o Can use other class member methods
Modifiers
o Determine the accessibility of class members
o Private
Can only be accessed by other class members
o Public
Anyone/code can access it
Data member declares
o Visibility dataType identiferName [=value]
Member method declare
o Visibility method header
pf3
pf4

Partial preview of the text

Download Notes on Standalone Entity - Introduction-Computer Science | CS 110 and more Study notes Computer Science in PDF only on Docsity!

  • Class o Standalone entity o Object o Application class ƒ Driver of program ƒ Contains main method o Worker or support classes ƒ Reusable elements ƒ Model real world entities o Decompose problem into series of classes
  • Class is made up of o Data ƒ Data members o Operations ƒ Act upon the data ƒ Member functions o Encapsulate them into one object – class ƒ Provide a mechanism to “hide” data members from other classes - Isolates data member from unauthorized change - Private ƒ Provide operations to modify and return data members o Class definition

Modifer(s) class ClassName modifer(s) { Data members/fields Member methods }

  • Data members/fields o Constant declarations o Variable declarations
  • Member methods o Automatically have access to the data members and constants o Direct access, scope o Can use other class member methods
  • Modifiers o Determine the accessibility of class members o Private ƒ Can only be accessed by other class members o Public ƒ Anyone/code can access it
  • Data member declares o Visibility dataType identiferName [=value]
  • Member method declare o Visibility method header
  • Visibility o Public ƒ Can be used by anyone/code o Private ƒ Can only be used by class members
  • Data --- private
  • Constants – public
  • Methods – public
  • Static o Indicates class method ƒ Only create one copy ƒ Requires parameters to do its work ƒ Math.pow(x,y)
  • Instance Methods o Create a set for each object declared of that type o Manipulate the instance of the message ƒ sc.next() ƒ s.indexOf(‘a’)
  • Create a Class – Card o Data members ƒ Suit - Set of predetermined values - Spades, hearts, clubs, diamonds ƒ face value - integer value 1- - certain values have “names” o ace, king, queen, jack, o Operations ƒ Constructors - Create a random card - Create a specific card ƒ Accessors - Determine the suit - Determine faceValue ƒ Manipulators - Display card - Determine if two cards are equal - Determine if two cards have same faceValue - Determine if two cards have same suit ƒ Mutators - Set faceValue - Set suit o Cards are used for many different things these are the basic things generic to all cards o Classes that build upon card

ƒ Operations

  • Constructor – generate a problem (random)
  • Accessors o Return left, right, operator
  • correctAnswer o return the correct answer to the problem
  • display problem o could create toString()
  • Sample Programs: Problem,.java, Flash.java
  • Extra Credit Assignment: Due Friday May 1, 2009 at the start of class, turn in gnulisting ONLY!!!!! o Create a class to model a fraction o Data members – numerator and denominator o Operations ƒ Create a particular fraction ƒ Create a fraction whose value is 1/1 (null constructor) ƒ Display a fraction as n/d ƒ Add two fractions ƒ Subtract two fractions ƒ Multiple two fractions ƒ Divide two fractions ƒ Reduce to lowest terms ƒ Input a fraction as n/d ƒ Set an existing fraction to a particular value ƒ