84246682-My-Programming-Lab-Chapter-4 - 20630 Write the definition of a class Clock The class has no constructors and three instance variables One is of

84246682-My-Programming-Lab-Chapter-4 - 20630 Write the...

This preview shows page 1 out of 4 pages.

Unformatted text preview: 20630 Write the definition of a class Clock . The class has no constructors and three instance variables. One is of type int called hours , another is of type boolean called isTicking , and the last one is of type Integer called diff . public class Clock { private int hours; private boolean isTicking; private Integer diff; } 20744 public class Player { private String name = ""; private int score = 0; public void setName(String name) {this.name = name;} public void setScore(int score) {this.score = score;} public String getName() {return name;} public int getScore() {return score;} } 20747 public class WeatherForecast { private String skies = ""; private int high = 0; private int low = 0; public void setSkies(String skies) {this.skies = skies;} public void setHigh(int high) {this.high= high;} public void setLow(int low) {this.low= low;} public String getSkies() {return skies;} public int getHigh() {return high;} public int getLow() {return low;} } 20844 String getFirstLine(String lines) {return lines.substring(0, lines.indexOf("\n"));} Ch4: Projects PP 4.1 4.1: Sphere Design and implement a class called Sphere that contains instance data that represents the sphere͛s diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter methods for the diameter. Include methods calcVolume and calcSurfaceArea that calculate and return the volume and surface area of the sphere. Include a toString method that returns a one-line description of the sphere of this form: public class Sphere { private double diameter; public Sphere(double diameter) {setDiameter(diameter);} public String toString() {return "sphere with diameter "+new java.text.DecimalFormat("0.###").format(diameter);} public double getDiameter() {return diameter;} public void setDiameter(double diameter) {this.diameter = diameter;} public double calcVolume() { return (4.0/3.0)*Math.PI*(diameter/2.0)*(diameter/2.0)*(diameter/2.0); } public double calcSurfaceArea() { return 4.0*Math.PI*(diameter/2.0)*(diameter/2.0); } CH4:Projects PP 4.3 4.3: Car Design and implement a class called Car that contains instance data that represents the make, model, and year of the car (as a String, String and int value respectively). Define the Car constructor to initialize these values (in that order). Include getter and setter methods for all instance data, and a toString method that returns a one-line description of the car of the form public class Car { private String make, model; private int year; public Car(String make, String model, int year) { setMake(make); setModel(model); setYear(year); } public String getMake() {return make;} public void setMake(String make) {this.make = make;} public String getModel() {return model;} public void setModel(String model) {this. model = model;} public int getYear() {return year;} CH4: Projects PP 4.4 4.4: Box Design and implement a class called Box that contains instance data that represents the height, width, and depth of the box. Thes dimensions should be of a type that can represent linear measurements, including fractional ones. Also include a boolean variable called full as instance data that represents whether the box is full or not. Define the Box constructor to accept and initialize the height, width, and depth of the box. Each newly created Box is empty (the constructor should initialize full to false). Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the box of the form "HxWxD" where H, W, and D are the current values respectively of the boxes height, width and depth. public class Box { private double height, width, depth; private boolean full; public Box(double height, double width, double depth) { setHeight(height); setWidth(width); setDepth(depth); setFull(false); } public double getHeight() {return height;} public void setHeight(double height) {this.height = height;} public double getWidth() {return width;} public void setWidth(double width) {this.width = width;} public double getDepth() {return depth;} 4.6 Graphic Objects 60234 The applet or JFrame method that returns the Container object that represents the applet's (or JFrame's) space (its visual "real estate") is________________ 4.8 Buttons 60235 A _______________________is a component that provides a button control in a GUI application or applet. 60236 The import statement needed to use button components in applets or GUI applications is___________ 60238 The general term for an object that receives notifications of user actions is______________________ 60239 The general term for methods that are invoked as a result of a user action is______________________ 60240 Clicking a button results in the creation of an _______________ object to represent the button click. 60241 Clicking a button may result in notification being sent to an_______________ object. 60242 The method used to arrange for a button to notify another object when it is clicked later is to an_______ 60243 The class definition for objects that receive notifications of user operations on controls like buttons must contain the following phrase: _______ 60244 An object that receives notifications of user operations on controls like buttons must provide the ________ method. 60248 The ActionListener interface requires that the_______________ method be implemented. 4.9 Text fields 60245 A _____________________ is a component that provides a box for writing one line of text in a GUI application or applet. ...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture