Docsity

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

Toggle sidebar
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 ยƒ