Java

OOP GUIDE / WORK

 

PEN CLASS

 

Topics

  • Class Design

 

 

TASK – PART 1 – SETUP

 

Copy and paste the following Tester classes to your IDE.

 

public class PenTester1

{

     public static void main(String[] args)

     {

           Pen q = new Pen(3);

           q.write("Patrick");

           //This program will output "Pat"

     }

}

public class PenTester2

{

     public static void main(String[] args)

     {

           Pen p = new Pen(8);

           p.write("hello");

           p.write("hello");

           p.write("hello");

           //This program will output "hellohel"

     }

}

public class PenTester3

{

     public static void main(String[] args)

     {

           Pen a = new Pen(7);

           System.out.print(a.getRemainingInk());

           a.write("yo!");                                 

           System.out.print(a.getRemainingInk());

           //This program will output 7yo!4

     }

}

public class PenTester4

{

     public static void main(String[] args)

     {

           Pen z = new Pen(4);

           z.write("Lockerby");

           System.out.print(z.getRemainingInk());

           System.out.print(z.isEmpty());

           //This program will output: Lock0true

     }

}

public class PenTester5

{

     public static void main(String[] args)

     {

           Pen t = new Pen(3);

           t.write("A B C D E");

           //This program will output: A B C

     }

}

 

 

TASK – PART 2 – PEN CLASS

 

Start by analyzing each Tester class above.

 

Then create the Pen class that will work with every Tester program above.  You must determine the required instance variable(s), constructor(s) and instance method(s).

 

Run each Tester to make sure you get the proper output.