Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Daniel Lawson
- 9/18/2016
- 1.
- Procedural programming involves executing tasks in a given order. Object oriented programming uses the objects to interact with each other.
- 2.
- A class is used to create a object. A object has various behaviors and information that can be used and changed.
- 3.
- The state is the data of the string class wich are the various characters that make up the string. The behaviors are the methods like charAt,indexOf,substring,etc.
- 4.
- 14 14
- 7 9 14 2
- 18 18
- 7 9 14 18
- 5.
- The calculator's behaviors would be its ability to calculate operations like addition, multiplication, subtraction, division. Another behavior would be to print out the results of a operation.
- The state would be the calculator's storing of inputed values and those previously stored in its memory.
- 6.
- Fields are in a class while parameters are values that are passed through methods. The field of a class is normally made private for encapsulation.
- 7.
- public class Name{
- private String firstName;
- private String lastName;
- private char middleInitial;
- }
- 8.
- An accessor gets a value from the object and returns it, a mutator changes a value of the object. "get" is used for accessors while "set" is used for mutators.
- 9.
- d
- 10.
- public double distance(Point other){
- int dx = this.x -other.x;
- int dy = this.y -other.y;
- return Math.sqrt((dx*dx)*(dy*dy));
- }
- 11.
- public class Name{
- private String firstName;
- private String lastName;
- private char middleInitial;
- public String getNormalOrder(){
- return (firstName + " " +middleInitial +". " + lastName);
- }
- public String getReverseOrder(){
- return (lastName + ", " + firstName + " " +middleInitial +"." );
- }
- }
- 12.
- Create a toString method
- 13.
- c
- 14.
- public String toString(){
- return ("(" +this.x +"," +this.y + ")");
- }
- 15.
- public String toString(){
- return (firstName + " " +middleInitial +". " + lastName);
- }
- 16.
- Point p1 = new Point(8,2);
- Point p2 = new Point(4,3);
- System.out.println("p1 is " +p1);
- System.out.println("p2 is " +p2);
- System.out.println("p1's distance from origin is " + p1.distance(new Point(0,0)));
- p1.translate(1,2);
- p2.translate(-1,10);
- System.out.println("p1 is now " + p1);
- System.out.println("p2 is now " + p2);
Advertisement
Add Comment
Please, Sign In to add comment