CodeLab 10.02.06

CodeLab 10.02.06 - CodeLab: 10.02.06 Write the definition...

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

View Full Document Right Arrow Icon
CodeLab : 10.02.06 Write the definition of a class Simple. The class has no constructors or instance variables. public class Simple { } Write the definitions of two classes Day and Night. Both classes have no constructors or instance variables. Note: For this exercise, please do not use declare your classes using the public visibility modifier. class Day { } class Night { } Write the definition of a class Clock. The class has no constructors and one instance variable of type int called hours. public class Clock { private int hours; } Write the definition of a class Clock. The class has no constructors and two instance variables. One is of type int called hours and the other is of type boolean called isTicking. public class Clock { private int hours; private boolean isTicking; } 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. Instructor's notes: The Integer class is just like other data types we've used. To declare an instance of the Integer class. Example to declare an instance of the Bottle class: private Bottle bottle; public class Clock { private int hours; private boolean isTicking; private Integer diff; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
You are given a class named Clock that has one int instance variable called hours. Write a constructor with no parameters for the class Clock. The constructor should set hours to 12. public Clock() { hours = 12; } You are given a class named Clock that has one int instance variable called hours. Write a constructor for the class Clock that takes one parameter, an int, and gives its value to hours. public Clock(int hours) { this.hours = hours; } You are given a class named Clock that has three instance variables: One of type int called hours, another of type boolean called isTicking, and the last one of type Integer called diff. Write a constructor for the class Clock that takes three parameters -- an int, a boolean, and another int. The constructor should set the instance variables to the values provided. Instructor's notes: Reminder: To create an instance of a reference type (like Integer), you must use the new operator. In this question, the incoming value for diff is of type int and it is the constructor's responsibility to create and store an Integer object with that value. public Clock(int hours, boolean isTicking, int diff)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

CodeLab 10.02.06 - CodeLab: 10.02.06 Write the definition...

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

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