CodeLab 11.20.06

CodeLab 11.20.06 - CodeLab 11.20.06 Write the definition of a class Telephone The class has no constructors one instance variable of type String

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: CodeLab : 11.20.06 Write the definition of a class Telephone. The class has no constructors, one instance variable of type String called number, and one static variable of type int called quantity. public class Telephone { private String number; private static int quantity; } Write the definition of a class Telephone. The class has no constructors, one instance variable of type String called number, and two static variables. One is of type int called quantity, initialized to 250; the other is of type double called total, initialized to 15658.92. public class Telephone { private String number; private static int quantity = 250; private static double total = 15658.92; } Write the definition of a class Telephone. The class has no constructors and one static method printNumber. The method accepts a String argument and prints it on the screen. The method returns nothing. public class Telephone { public static void printNumber(String string) { System.out.println(string); } } Write the definition of a class Telephone. The class has no constructors and one static method getFullNumber. The method accepts a String argument and returns it, adding 718- to the beginning of the argument. public class Telephone { public static String getFullNumber(String s) { return ("718-" + s); } } Write the definition of a class Telephone. The class has no constructors, one instance variable of type String called number, and two static variables. One is of type int called quantity; the other is of type double called total. Besides that, the class has one static method makeFullNumber. The method accepts two arguments, a String containing a telephone number and an int containing an area code. The method concatenates the two arguments in the following manner: First comes the area code, then a dash, then the telephone number. The method returns the resultant string. public class Telephone { private String number; private static int quantity; private static double total; public static String makeFullNumber(String s, int i) { return (i + "-" + s); } } Write the definition of a class Counter containing: An instance variable named counter of type int. An instance variable named limit of type int. A static int variable named nCounters which is initialized to 0. A constructor taking two int parameters that assigns the first one to counter and the second one to limit. It also adds one to the static variable nCounters. A method named increment. It does not take parameters or return a value; if the instance variable counter is less than limit, increment just adds one to the instance variable counter....
View Full Document

This note was uploaded on 03/29/2008 for the course CS 302 taught by Professor Willbenton during the Fall '07 term at Wisconsin.

Page1 / 7

CodeLab 11.20.06 - CodeLab 11.20.06 Write the definition of a class Telephone The class has no constructors one instance variable of type String

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