Ok, I now realise i need a LinkedList and I think this should be declared in the OrderList class, how do I get the information from the Cashier Thread into the LinkedList?
Thanks.
User Profile
Collapse
-
jonjon0688 started a topic Multiple threads, require a synchronized list, which can hold multiple variablesin JavaMultiple threads, require a synchronized list, which can hold multiple variables
I have the task of creating 3 classes, Cashier, OrderList and cook.
The cashier adds an order to the OrderList. The order info is the cashiers name, the order number (unique) and the current time.
I have written code to get the relevant information for the order (see below), however I do not know how to put it in the OrderList, I thought an arrayList could only hold one variable. Also should the list be declared in... -
it says:
The output should have been:
countChars
This is what was actually produced:
public int fileSize(String name) throws IOException
{
try {
InputStreamRead er isr = new InputStreamRead er(new FileInputStream (name));
BufferedReader in = new BufferedReader( isr);
int charLength = 0;
...Leave a comment:
-
no i am still using the reader in the fileSize method, the above method countChars is the one it says to use to create the fileSize method, i was just wondering how i use it?...Leave a comment:
-
yes it says use this method:
public int countChars(Inpu tStream input) throws IOException
{
int count = 0;
BufferedInputSt ream input2 = new BufferedInputSt ream(input);
while(input2.re ad() != -1)
{
count++;
}
return count;
}
but how? what does it mean by 'use' it?Leave a comment:
-
like this ..
public int fileSize(String name) throws IOException
{
try {
InputStreamRead er isr = new InputStreamRead er(new FileInputStream (name));
int charLength = 0;
while (isr.read() != -1)
charLength++;
return charLength;
}
catch...Leave a comment:
-
-
sorry i know im being really stupid, but i don't quite understand what you mean?Leave a comment:
-
this is what i have:
public int fileSize(String name) throws Exception
{
try {
InputStreamRead er isr = new InputStreamRead er(new FileInputStream ("name.txt") );
int charLength = 0;
while (isr.read() != -1)
charLength++;
return charLength;
...Leave a comment:
-
is this what you mean ?
public int fileSize(String name) throws IOException
{
try {
InputStreamRead er isr = new InputStreamRead er(new FileInputStream (System.getProp erty("user.dir" )));
int charLength = 0;
while (isr.read() != -1)
charLength++;
return...Leave a comment:
-
But does the question not state that the file is called "name"? it would not matter whether i have the file or not when i submit my work.
Is it something to do with where i have placed try {
thanks for the helpLeave a comment:
-
fileSize help
Using the countChars() method from the previous answer, write a method called fileSize() declared as follows:
public int fileSize (String name) {
...
}
which counts the number of characters in the file whose name is supplied as the "name" parameter. This method should return the number of characters in the file, or -1 if an IOException occurs.
public... -
same question ..
public int fileSize(String name) throws IOException
{ try {
InputStreamRead er isr = new InputStreamRead er(new FileInputStream ("name"));
int charLength = 0;
int c;
while ((c = isr.read()) != -1)
charLength++;
return(charLeng th);
}
...Leave a comment:
-
Using the countChars() method from the previous answer, write a method called fileSize() declared as follows:
public int fileSize (String name) {
...
}
which counts the number of characters in the file whose name is supplied as the "name" parameter. This method should return the number of characters in the file, or -1 if an IOException occurs.
This is what i have done :
public...Leave a comment:
No activity results to display
Show More
Leave a comment: