Antenka 274 Posting Whiz

I saw. But this try didn't helped me to read normally his code. ;)

Antenka 274 Posting Whiz

Hello, Sandawg.
Here is your mistake: you trying to take element of array, that not exists.
you should use this

public static void printArray(int count)
{
for (int i = 0; i<count; i++ )
{
System.out.print(pName[i]);
...
}

Also there is a couple recommendations to you (including about using static keyword). Ask if you interested.

P.S. If you post your code in more readable state next time, you get the answer much faster :)

Antenka 274 Posting Whiz

You should realize interface Comparable in your class Person. After that you'll can compare your objects, like that:

Person a, b;
a = ...;
b=...;
a.CompareTo(b);

This will allow you to sort your array of Person. And also it became Comparable.

Alex Edwards commented: Comparable is the way to go! =) +5
Antenka 274 Posting Whiz

Here is link to understand Comparable Interface:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Comparable.html

And here is a little help on binary search:
http://leepoint.net/notes-java/algorithms/searching/binarysearch.html

Antenka 274 Posting Whiz

Here some links, that can solve your problem:
http://www.hostitwise.com/java/japplet.html
http://www.roseindia.net/java/example/java/applet/

and here is alternative decision (if you interested):
http://www.jython.org/applets/coordinates.html
:)

Antenka 274 Posting Whiz

Here's little example for better understanding:

Operation op = new Minus();  // you can dynamicly set the operation         
XObject x = new XNumber(5.0); //creating numbers
XObject x1 = new XNumber(4.0); //creating numbers
XObject r = op.operate(x, x1); //doing operation
Antenka 274 Posting Whiz

Hello, KPS
You can try to look in class Operation...

Antenka 274 Posting Whiz

I've tried to run your code ... it's working. Try to rebuild your project.

Antenka 274 Posting Whiz

stultuske: I'm optimist, so I prefer to think, that he wants to get some knowleges :)

Antenka 274 Posting Whiz

Hello, beforehand, sorry for my english...
You can read your data into String, the split it by " ". And you'll have an array of symbols. To print it, you can use 2 cycles: (1st - from 0 to arrayLength; 2nd- from 0 to (columCount and arrayLength if you can have strings with not equal length))

Antenka 274 Posting Whiz

As I can see, you didn't read this post "We only give homework help to those who show effort". All I can do is give you advices:
1. About String s: String - is a class, when you create an object of class, the class "do not know about it". So you can't cll the object from the class (String.s = null). Also as in your program.
2. The phrase "data=null" in the begginig of the method is wrong (consider, you use it later...).
3.Befor using variables? you have to declare. That way compiler understands, what you will store in it. In your case the type is "E". this mean, that it unknown now, but will be known later. Also you have to know is the base type for all refference types is Object.
4. If you are writing "public void remove(E data)" it means, that function doesn't return value. The return keyword is not out of place.

Also you can answer a questions and I'll try to answer. Good luck.

Antenka 274 Posting Whiz

You can use scanner.next() it returns string, but you can convert it to char.

Antenka 274 Posting Whiz

Scanner has no definition of method getChar.

Antenka 274 Posting Whiz

Hello, deven1974
Lets start:
1. Illegal use of data and datatypes:

public void remove(E data) {
E.data = null;
if (head != null)
temp = head.data;
head = head.next;
return temp;
}

It is equal, if you write this

String s;
String.s = null;

2. You didn't declare variable temp, but use it.
3. Why are you setting your just entered parameter no null and the working with it?

Antenka 274 Posting Whiz

First: startSky != "snowy" and startSky != "sunny". Use method equals to campare stings.
Maybe it will be better for you to use enum instead strings "sunny", "snowy" etc.
In setSky method, when you get an error, you don't set the skyCondition.

Antenka 274 Posting Whiz

It doesn't work because you compare strings using "==". Try this:

if(sval.equals(arr[pos]))
Antenka 274 Posting Whiz

Hello, lone_emu:
At first, to use your static methods, you don't have to create an object of class Palindrome. So this:

Palindrome pal = new Palindrome();

is not wanted here.

To replace chars in the string (not using replace function) you can convert your string to char array, replace the elements at specified indexes and the convert it back to string

Antenka 274 Posting Whiz
Ezzaral commented: Plenty of info there. +15
Antenka 274 Posting Whiz

Here is part of description of this function, given by java help:
public boolean renameTo(File dest)

It asks a File as parameter, but you give String to it.

Alex Edwards commented: Helpful information =) +5
shubhang commented: Thanks a million for the help. +1
Antenka 274 Posting Whiz

You can output them:

System.out.println(application2.setHours(input.nextInt()));

or check, if the setting passed correctly

if(application2.setHours(input.nextInt())))
{//all good}
else {//something wrong}

Also you can save that value to variable:

Boolean settingStatus = application2.setHours(input.nextInt()));
Antenka 274 Posting Whiz

Correct me, if I'm wrong:
1. You creating new "clock" and setting it to 0.

Time application = new Time();
application.TimeTest(0, 0, 0);

2. Then while setting the hours creating 2 more clocks.

Time application2 = new Time();					application2.setHours(input.nextInt());

and

Time app = new Time();
app.getHours();

Here is your problem: you setting hours to the clock-2 and getting it (hours) from clock-3.

Antenka 274 Posting Whiz

Don't forget the Ukraine ;)

Antenka 274 Posting Whiz

To display image on your form you can use the Picturebox control and the Image class:

Image yourImage = Image.FromFile(pathOfYourImage);
            pictureBox1.Image = yourImage;

Is that what you are looking for?

Antenka 274 Posting Whiz

Here is something:

Introduction to the JavaMail API:
http://archive.devx.com/upload/free/bkchapters/prowap/40441303.asp

and here you can find code, provided by Sun:
http://java.sun.com/products/javamail/downloads/

Antenka 274 Posting Whiz

Thanks a lot!!!!!!!!!!!!!!!!

Antenka 274 Posting Whiz

Maybe. And my "\n\n" was as sample :) I'm newbie in remote interaction, can you tell me, is there any usual way to tell server (client) "That's enough"?

Antenka 274 Posting Whiz

Yeah ... I mean before. I've posted code for case, if someone be interested.

Antenka 274 Posting Whiz

Oh ... it never ends :( Thanks a lot for spending time working with me and my problem. I have tried new variant - same trouble. I found the way to pass through this problem:
I add "\n\n" in the end of request and then when reading from stream I'm checking, if the string ends on "\n\n" i break the cycle.
Here is updated server code (reading part):

while (true)
            {
                int b = is.read();
                if (b == -1)
                    break; 
                request += (char)b;
                if(request.endsWith("\n\n"))
                    break;
            }

It is workibg!
Just interesting, what is wrong? Have any ideas what is that? :)

P.S. about client and server on same machine: this is 3rd home work. Previous 2 also used interacting remote and I tested them on my machine and all works normally.

peter_budo commented: Good luck with your homeworks :) +12
Antenka 274 Posting Whiz

Thanks I'll try...

Antenka 274 Posting Whiz

oops.. sorry for russian messages. It is only messages like "Server started" or "IO error". If it necessary I can translate it... :)

Antenka 274 Posting Whiz

Server:

private Socket socket = null;
private BufferedReader is = null;
private PrintWriter os = null;
private String request = "";
private ServerSocket ss = null;
private int port = 2604;

public void run()
    {
        try
        {

            String line;
            while ((line = is.readLine()) != null) {
                request += "\n" + line;
            }
                        
            System.out.println("Request from ctient: " + request);
            System.out.println("Processing...");
            String msgToReport = AnalyzeEntryRequest(request);
            System.out.println("Sending: " + msgToReport);
            os.println(msgToReport);
            os.flush();
        }
        catch (IOException e)
        {
            System.out.println("Ошибка ввода-вывода. " + e);
        }
        finally
        {
            try
            {
                is.close();
                os.close();
                socket.close();
                System.out.println("Клиент " + socket + " отсоединен.");
            }
            catch (IOException e)
            {
                System.out.println("Ошибка закрытия сокетов. " + e);
            }
        }
    }
private boolean InitServer()
    {
        boolean res = true;
        
        try
        {
            is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            os = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
        }
        catch (IOException e)
        {
            System.out.println("Ошибка создания потоков. " + e);
        }
        new  Thread (this).start();
        System.out.println("Запуск сервера.");

        return res;
    }

Client:

private String sendRequest(String request)
    {
        String result = "";
        this.host = jTextField7.getText();
        InputStream in = null;
        OutputStreamWriter out = null;
        try
        {
            URL url = new URL ("http://" + host + ":" + port);
            URLConnection c = url.openConnection();
            c.setDoOutput(true);
            c.connect();
            
            out = new OutputStreamWriter(c.getOutputStream());

            String data =  URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode(request, "UTF-8") + "\r\n\r\n";
            
            out.write(data);            
            out.flush();

            out.close();
            
            BufferedReader rd = new BufferedReader(new InputStreamReader(c.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) 
	    {
            
                result += "\n" + line;
            }

            in.close();
        }
        catch (Exception e)
        {
            JOptionPane.showMessageDialog(jTextPane1,"Ошибка передачи данных. " + e);
        }
        
        return result;
    }

There was …

Antenka 274 Posting Whiz

I already tried -1 - same. And I took "null" from java help

java.​io.​BufferedReader
public String readLine() throws IOException
Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached

Can you tell what you mean as period?

Antenka 274 Posting Whiz

Yeah ... THANKS... IT WORKS (almost). So I have another problem:
server catches the client connections, but when I'm trying to read from InputStream

BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));

	//....
	
	String line;
        while ((line = is.readLine()) != null)       
	{
            
        	request += "\n" + line;
        }

it reads information:
"
POST / HTTP/1.1
Connection: close
Keep-Alive: 300
User-Agent: Java/1.6.0_07
Host: localhost:2604
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-type: application/x-www-form-urlencoded
Content-Length: 38

key1=search%09StudentRecBook%09123"
and after that stops at

while ((line = is.readLine()) != null)

like waiting for reading something else from stream.
What he is waiting for? Help :)

Antenka 274 Posting Whiz

Please, at least somebody!
Any help at all would be greatly appreciated!

Antenka 274 Posting Whiz

You are compering 2 different types String accountNum and int accountNumber[0]. This is interesting, that you run it without troubles :)
As I understand, it must be like that:
f(accountNum2==bank.accountNumber[0])

Antenka 274 Posting Whiz

As I understood, you have combined information in your file "books.txt" (name -
string and price - double). To split information, that was read from your file you should use patterns (in example there is pattern to delimit using comma and different number of whitespaces " *" ). You also can use control symbols, such as "\n".

//we have cycle until we'll reach the symbol,
//what hasn't next element
while(src.hasNext()) { 
      //if next value is double
      //(it is just checking next value, not goes to it)
      if(src.hasNextDouble()) { 
	//we take this value and add to sum
        sum += src.nextDouble(); 
      }
      //if the next value is not  double
      //in your case you should pass through this block
      else { 
        //we take this element as string
        String str = src.next();  
        //if this string equals("done"), we are
	//coercive breaking the cycle
        if(str.equals("done")) break; 
        else { 
          //if this is not "done" we have troubles :)
          System.out.println("File format error."); 
          return; 
        } 
      } 
    }

Did I answered on your question?

Alex Edwards commented: Quite the helpful individual =) +5
Antenka 274 Posting Whiz
Antenka 274 Posting Whiz

Hello everyone, beforehand, sorry for my english...
I have to do client - server application. They must interact, using classes URL, URLConnection. I understand, how to send data to server. But I can not realize server work.
The common algorithm of server is:
1. Start.
2. Wait for connection.
3. After receiving connection it must process request.
4. Or back for "2" or exit.

as I understand, client code to send request is:

URL url = new URL ("http://" + host + ":" + port);
            URLConnection c = url.openConnection();
            c.setDoOutput(true);
            c.connect();
            
            OutputStreamWriter out = new OutputStreamWriter(c.getOutputStream());
            out.write(URLEncoder.encode(request,"UTF-8") );
            out.flush();
            out.close();

please help with server code to catch this connection?

Antenka 274 Posting Whiz
Antenka 274 Posting Whiz

Beforehand, sorry for my english...
The || - is short version of |.
I.e. if you have simple condition like this:
(a||b) then, there is no difference, what operator to use. In case with complex condition:
((a==b)||(c==d)||(e==f)) will be difference. The || operator will be checking the conditions, untill it find TRUE. If it happened on (a==b), the other conditions will not be checked. If you are choose the | operator, then all conditions will be checked necessarily.

Antenka 274 Posting Whiz

Don't know, how fix it, but I found something to turn off function, that calls the exception (and a little info about that) ...
http://msdn.microsoft.com/en-us/library/d21c150d.aspx

Antenka 274 Posting Whiz

No, there is no necessity. I just forgot, that I can create my own :)

Antenka 274 Posting Whiz

beforehand, sorry for my english... :)
I'magree with dickersonka and just want to add, that the object oriented programming is more understandable, than procedural. With your expirience it means not a lot of work for learn it.
Thanks for your attention :)

Antenka 274 Posting Whiz

Can you attach whole file m3u, that you are working with?

Antenka 274 Posting Whiz

ReadLine() is not the only one, there are a few not less interesting functions in StreamReader class ... pay attention to it.
And there's a few functions in Stream class (for example to move the cursor).

Antenka 274 Posting Whiz

If the files that youll working with will be not to large, I think, you can use It. But in case bigger files, I prefer to use, for example, ReadLine() function to reach the end of file.

Antenka 274 Posting Whiz

:) good luck

Antenka 274 Posting Whiz

I can offer you this:
String.Concat(s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));

where s - is title. Not the best, but it is variant.

Antenka 274 Posting Whiz

How about splitting like this:
string[] s1 = s.Split(new string[]{".mp3"} ,StringSplitOptions.RemoveEmptyEntries);
and then Split('-') ?

Antenka 274 Posting Whiz

beforehand, sorry for my english... :)
I have some advices for you:
1. You have a lot of repeating code in your program. You should take out it to a method(s) and then call it...
(also in doneBtn_Click method you have switch operator, that no matter what do this: amountTxtBx.Text = ""; you could place this before of after switch)
2. And you can make you switch operator shorter (it has equals cases)
3. Instead of creating variables chckFee, interestRate I would create an accessors in classes to get them.
I think, that's all for a first sight.
4. Instead caseNumber you could use an enum, with work, you want to lock in. I think it would be more understandable.

schmidty169 commented: Took advice and took out repeative code and placed into methods. +3