473,509 Members | 3,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can anyone help me? code errors!

9 New Member
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.


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
Oct 30 '07 #1
1 1098
epots9
1,351 Recognized Expert Top Contributor
Moved to the JAVA Forums where the resident experts can better assist you.

**Moved from Programming Challenges
Oct 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2003
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be...
4
4026
by: Ersin Gençtürk | last post by:
Server : WEB System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown. ---> System.Web.HttpException: The View State is invalid for this page and might be...
0
1206
by: Mike | last post by:
Hi All, I am using a COM object and so I have to use a form for it to work. The problem is I need to run it as a service as well. When I run it in a test scenario everything works fine and...
31
2739
by: Jim Hubbard | last post by:
I am downloading the REALbasic 5.5 demo and was just wondering if anyone else had tried it. I am tired of Microsoft constantly changing things and breaking backward compatibility ON PURPOSE. ...
40
2912
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
5
1207
by: Andrew | last post by:
Hello, friends, In our development machine, the .net web app worked fine. Then we deployed it to our server. However, it did not work on the server. After a user entered user name/pswd and...
66
5279
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
20
1730
by: ridergroov | last post by:
I had this message previously in another group and I was told to try here. Hopefully someone can help out. Site was created in Dreamwaver MX 04 and I cna't figure out why there are so many errors...
10
1400
by: spacebebop | last post by:
#include <cstring> #include <iostream> using namespace std; class X { public: X(); X( char * ); ~X();
11
1478
by: itgetsharder | last post by:
can anyone help me? code errors! -------------------------------------------------------------------------------- im creating a code for a printer. the question i am trying to answer is : ...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.