--------------------------------------------------------------------------------
im creating a code for a printer. the question i am trying to answer is :
MyPrinter needs some printing methods. The first, signature:
public boolean printOne(String text) {}
should take a String as a parameter, and output it on a single line to the terminal window.
It should also increment (add 1 to) the total number of copies made, and decrement (subtract 1 from) the number of sheets of paper available.
It should return the boolean value true(this is actually to avoid confusion in the next assignment)
the second, signature:
public void print5(String text) {}
should take a String as a parameter and outputs it on five successive single lines to the terminal window.
It should also increase the total number of copies made by 5, and reduce the number of sheets available by 5.
It should not return anything.
this is my coding. i keep getting unreachable statement and im a newbie so i dont really understand what ive done wrong.
Expand|Select|Wrap|Line Numbers
- public class MyPrinter
- {
- // instance variables - replace the example below with your own
- private int prints;
- private int sheets;
- private String printerName;
- private boolean printOne;
- private boolean print5;
- private String name;
- private int startPaper;
- private int end;
- /**
- * Constructor for objects of class MyPrinter
- */
- public MyPrinter()
- {
- // initialise instance variables
- prints = 0;
- sheets = 500;
- printerName = "Epson";
- }
- public MyPrinter(String name, int startPaper, int end)
- {
- // initialise instance variables
- prints = 0;
- sheets = startPaper;
- printerName = name;
- }
- /**
- * An example of a method - replace this comment with your own
- *
- * @param y a sample parameter for a method
- * @return the sum of x and y
- */
- public void testMyPrinter()
- {
- // put your code here
- System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
- System.out.println("0123456789");
- }
- public void Test()
- {
- MyPrinter p = new MyPrinter();
- p.testMyPrinter();
- System.out.println("Printer Name: " + p.getName() );
- System.out.println("Sheets: " + p.getPaper() );
- System.out.println("copies: " + p.getCopies() );
- p = new MyPrinter("HP", 200, 0); p.testMyPrinter();
- System.out.println("Printer Name: " + p.getName() );
- System.out.println("Sheets: " + p.getPaper() );
- System.out.println("copies: " + p.getCopies() );
- p.printOne("Test printOne"); // ignore return value
- System.out.println("Sheets: " + p.getPaper() );
- System.out.println("copies: " + p.getCopies() );
- System.out.println("Sheets: " + p.getPaper() );
- System.out.println("copies: " + p.getCopies() );
- }
- public int getCopies()
- {
- return prints;
- }
- public int getPaper()
- {
- return sheets;
- }
- public String getName()
- {
- return printerName;
- }
- public boolean printOne(String text)
- {
- System.out.println("printOne");
- return startPaper == sheets - 1;
- return end == prints + 1;
- }
- public void print5(String text)
- {
- System.out.println("print5");
- System.out.println("print5");
- System.out.println("print5");
- System.out.println("print5");
- System.out.println("print5");
- startPaper = sheets - 5;
- end = prints + 5;
- }
- }
the output is supposed to look like this below:
The output when a test object is created should be
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
Printer Name: Epson
Sheets: 500
copies: 0
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
Printer Name: HP
Sheets: 200
copies: 0
Test printOne
Sheets: 199
copies: 1
Test print5
Test print5
Test print5
Test print5
Test print5
Sheets: 194
copies: 6
any help would be much appreciated as ive been at this all day now.
thanks x