473,666 Members | 2,082 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(Strin g 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.prin tln("ABCDEFGHIJ KLMNOPQRSTUVWXY Z");
System.out.prin tln("0123456789 ");
}


public void Test()
{
MyPrinter p = new MyPrinter();
p.testMyPrinter ();
System.out.prin tln("Printer Name: " + p.getName() );
System.out.prin tln("Sheets: " + p.getPaper() );
System.out.prin tln("copies: " + p.getCopies() );
p = new MyPrinter("HP", 200, 0); p.testMyPrinter ();
System.out.prin tln("Printer Name: " + p.getName() );
System.out.prin tln("Sheets: " + p.getPaper() );
System.out.prin tln("copies: " + p.getCopies() );
p.printOne("Tes t printOne"); // ignore return value
System.out.prin tln("Sheets: " + p.getPaper() );
System.out.prin tln("copies: " + p.getCopies() );
System.out.prin tln("Sheets: " + p.getPaper() );
System.out.prin tln("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.prin tln("printOne") ;
return startPaper == sheets - 1;
return end == prints + 1;


}




public void print5(String text)
{
System.out.prin tln("print5");
System.out.prin tln("print5");
System.out.prin tln("print5");
System.out.prin tln("print5");
System.out.prin tln("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
ABCDEFGHIJKLMNO PQRSTUVWXYZ
0123456789
Printer Name: Epson
Sheets: 500
copies: 0
ABCDEFGHIJKLMNO PQRSTUVWXYZ
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 1107
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
2015
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 returned as DataSet. Now, here's the problem. On .NET Framework 1.1, if any rows in the dataset returned contain errors (marked by calling the SetColumnError() method or
4
4038
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 corrupted. at System.Web.UI.Page.LoadPageStateFromPersistenceMedium() at System.Web.UI.Page.LoadPageViewState() at System.Web.UI.Page.ProcessRequestMain() --- End of inner exception stack trace --- at System.Web.UI.Page.HandleError(Exception e)...
0
1213
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 Invoke works as expected. However, when I run it as a service the Invoke command just bombs out without any errors and everything just stops. I have the service installed using an administrator account and interacting with the desktop for testing.
31
2764
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. I'd like to offer my customers the ability to run my apps on Windows, MAC or Linux - and REALbasic claims the ability to do that from one set of source code.
40
2963
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 front end open at the first form) and even though this links to the back-end files, there are no ldb files created. This is so I know when it is safe to compact the back-end files without going round to make sure everyone is logged off. User...
5
1217
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 tried to log in, we have the error message in Exception : Thread was being aborted in Page_Load(). Page_Load()
66
5338
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 occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of occurences. The second is to let you enter a word, with the program reporting how many times the...
20
1750
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 or how to fix them. Original thread can be found here: http://groups.google.com/group/mozilla.support.firefox/browse_thread/thread/9f479425c897212b/106dbd2754e85252?q=looks+good+in+firefox&rnum=1#106dbd2754e85252 I've been working on our...
10
1411
by: spacebebop | last post by:
#include <cstring> #include <iostream> using namespace std; class X { public: X(); X( char * ); ~X();
11
1494
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 : 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...
0
8449
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8360
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8556
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8642
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5666
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2774
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 we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1777
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.