ex5 - Example 5: All About Classes - Polynomial /* class...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Example 5: All About Classes - Polynomial /* class Polynomial * * Purpose: Show how a class is defined, declared, allocated, used * */ public class Polynomial { int toTheZeroth; // These are instance variables int toTheFirst; int toTheSecond; // The following are all methods of class Polynomial // set different instance variables – Mutators // each mutator has a single argument or input parameter public void setZeroth(int zero) { toTheZeroth = zero; } public void setFurst(int one) { toTheFirst = one; } public void setSecond(int two) { toTheSecond = two; } // read different instance variables – Accessors // each accessors returns an int public int getZeroth() { return (toTheZeroth); } public int getFirst() { return (toTheFirst); } public int getSecond() { return (toTheSecond); } // print out in polynomial form public void print() { System.out.printfdx^2+%dx+%d“, toTheSecond,toTheFirst,toTheZeroth); } } // end of class Polynomial Notice there is no main in Polynomial. That is because this is not where the program starts – it is a class that is intended
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 2

ex5 - Example 5: All About Classes - Polynomial /* class...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online