CodeLab 11.20.06 - CodeLab 11.20.06 Write the definition of...

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

View Full Document Right Arrow Icon
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;
Image of page 1

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

View Full Document Right Arrow Icon
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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern