Il cruccio sta che sto muovendo i primi passi in java come autodidatta http://www.hwupgrade...tyle_emoticons/default/patpat.gif
grazie.
...posta la tua idea...poi eventualmente traduciamo in Java...
Inviato 15 luglio 2011 - 14:05
Il cruccio sta che sto muovendo i primi passi in java come autodidatta http://www.hwupgrade...tyle_emoticons/default/patpat.gif
grazie.
Inviato 21 luglio 2011 - 22:51
Inviato 22 luglio 2011 - 00:49
Inviato 22 luglio 2011 - 08:38
Inviato 22 luglio 2011 - 08:56
Inviato 22 luglio 2011 - 09:02
vi ho detto che ho seguito solo un corsaccio on line e basta di java che insegna i comandi, ma non a programmare...
cmq l'array è di misura fissa, quello che mi importa è riuscire a ritornarlo da una funzione INTERO, non un solo elemento.
L'idea è sempre la solita...:
vi faccio i primi passi:
- main creo un array di 3 elementi
- nel main a seconda della data in cui mi trovo creo la classe stagione in cui mi trovo e lo scrivo in array in posizione 1
- nella classe stagione in cui mi trovo creo 3 classi tempo (piovoso, nuvoloso, soleggiato) tutte derivate dalla classe tempo inizializzate con un costruttore
- nella classe stagione, sfruttando le probabilità che trovo nelle classi tempo, mi calcolo che tempo c'è in quel giorno e lo scrivo nell'array in posizione 2
- nella classe tempo in cui mi trovo creo delle classi di qualcos'altro e calcolerò dove mi trovo, scrivendolo nell'array in posizione 3...e così via.
- Finito tutto ritorno nel main, aggiungo +1 al giorno e rifaccio da capo per la nuova data.
Inviato 22 luglio 2011 - 09:06
Inviato 22 luglio 2011 - 09:08
allora, ora sto iniziando a capirci qualcosa di piu'.
Weather dovrebbe essere una enum con i tre possibili valori se non ha altra responsabilita' che indicare il tipo di tempo.
Io creerei una classe Day che contenga una Listo un Weather[] e che calcola lui stesso il valore dei 4 tempi, o meglio se i 4 valori indicano il tempo in uno specifico momento creerei una Map in modo da memorizzare il valore del tempo in ogni momento e lo puoi calcolare in un ciclo direttamente nel costruttore di Day.
La classe Season invece conterra' solamente una Liste puoi semplicemente creare 4 istanze della stessa classe (una per stagione) se l'unica differenza e' la probabilita' di un certo tempo.
vi ho detto che ho seguito solo un corsaccio on line e basta di java che insegna i comandi, ma non a programmare...
cmq l'array è di misura fissa, quello che mi importa è riuscire a ritornarlo da una funzione INTERO, non un solo elemento.
L'idea è sempre la solita...:
vi faccio i primi passi:
- main creo un array di 3 elementi
...stai parlando di un array o di una matrice?...
- nel main a seconda della data in cui mi trovo creo la classe stagione in cui mi trovo e lo scrivo in array in posizione 1
- nella classe stagione in cui mi trovo creo 3 classi tempo (piovoso, nuvoloso, soleggiato) tutte derivate dalla classe tempo inizializzate con un costruttore
- nella classe stagione, sfruttando le probabilità che trovo nelle classi tempo, mi calcolo che tempo c'è in quel giorno e lo scrivo nell'array in posizione 2
- nella classe tempo in cui mi trovo creo delle classi di qualcos'altro e calcolerò dove mi trovo, scrivendolo nell'array in posizione 3...e così via.
- Finito tutto ritorno nel main, aggiungo +1 al giorno e rifaccio da capo per la nuova data.
...cosa vuoi fare esattamente?...un calendario in cui per ogni giorno ci siano 4 orari in cui specifichi il tempo atmosferico o vuoi che per ogni giorno ci siano x posti in cui specifichi 4 orari in cui hai rilevato il tempo?...
Inviato 22 luglio 2011 - 09:17
Inviato 22 luglio 2011 - 09:18
Inviato 22 luglio 2011 - 09:57
appunto, se devi fare un calcolo per ogni giorno allora deve essere responsabilita' della classe giorno fare quel calcolo, non della classe stagione.
La classe stagione avra' semplicemente la responsabilita' di inizializzare correttamente i vari giorni che calcoleranno il tempo nel loro costruttore ricevendo in ingresso i necessari parametri di input.
Inviato 22 luglio 2011 - 10:04
?[/url]":1oveax2r] appunto, se devi fare un calcolo per ogni giorno allora deve essere responsabilita' della classe giorno fare quel calcolo, non della classe stagione.
La classe stagione avra' semplicemente la responsabilita' di inizializzare correttamente i vari giorni che calcoleranno il tempo nel loro costruttore ricevendo in ingresso i necessari parametri di input.
e ma io non ho la classe giorno.
ho una data, e dalla data parte direttamente il calcolo della stagione.
praticamente la classe giorno non mi serve. Ho la data e bona.
Inviato 23 luglio 2011 - 18:12
Inviato 23 luglio 2011 - 18:18
Inviato 04 ottobre 2011 - 12:12
Inviato 09 novembre 2011 - 19:37
public class HttpGet { private Socket s=null; private InetAddress ip; private int port=80; public void go(String str) throws IOException{ ip=InetAddress.getByName(str); s=new Socket(ip,port); try{ System.out.println("inizio, ip ="+ip.getHostAddress()); Scanner input = new Scanner(s.getInputStream()); OutputStream o =s.getOutputStream(); PrintWriter output= new PrintWriter(o,true); output.print("GET /~conti/teaching/PCD1112/project_config.txt HTTP/1.0\r\n\r\n"); System.out.println("aspetto l'input..."); String line=input.next(); //faila anche con nextline System.out.println(line); System.out.println("finito"); }finally { s.close(); } } public static void main (String[] a) throws IOException{ HttpGet hg = new HttpGet(); hg.go("www.math.unipd.it"); } }
inizio, ip =147.162.114.104 aspetto l'input... Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:855) at java.util.Scanner.next(Scanner.java:1364) at HttpGet.go(HttpGet.java:26) at HttpGet.main(HttpGet.java:34)
GET /~conti/teaching/PCD1112/project_config.txt HTTP/1.0\r\n\r\n
The \r\n\r\n string is required by the HTTP protocol. More
specifically, the HTTP 1.0 protocol requires that every line of the
request ends with a Carriage Return (CR) followed by a Line Feed (LF).
In JAVA CR is represented by "\r" and LF is represented by "\n".
However, in the above GET request we see two of them. This second one
is required by the fact that in the HTTP 1.0 protocol the end of the
input is marked with CRLF.
FIRMA FOTTUTAMENTE EDITATA. IL FOTTUTO STAFF.
Mai più giorni felici
Inviato 09 novembre 2011 - 20:50
FIRMA FOTTUTAMENTE EDITATA. IL FOTTUTO STAFF.
Mai più giorni felici
Inviato 09 novembre 2011 - 21:24
Inviato 09 novembre 2011 - 21:31
tiger, è un esercizio didattico da fare così....
ma che cazzo vuoi fare?
se vuoi aspettare la richiesta non devi usare il socket direttamente, ma devi usare il socket che ti viene restituito da un serversocket che e' in ascolto su una determinata porta.
Magari in un altro thread se vuoi fare le cose per bene.
E con questo puoi fare le cose piu' avanzate se vuoi farti il figo e serializzare deserializzare:
http://java.sun.com/... ... T/sockets/
Ma cazzo.. la documentazione e' la cosa migliore di java e voi nemmeno la leggete???
Dear All,
The exercises that we could not do in class are helpful in solving
some part of your project. The exercises that I had planned was to
write a program (HttpGet) to send a HTTP GET request to the web server
to receive a specific file from it. To write this code you need to
know some basic information about the HTTP protocol, and in particular
the GET request and the response to this request.
Fortunately, HTTP is a text based protocol. In other words, a server
and a client communicate with each other by exchanging text messages
that have a specific format. For the homework and the project you only
need to know the format of a GET request, and the format of the
response to it. The format of the GET request is as follows:
GETHTTP/1.0\r\n\r\n
For example to receive the project_config.txt file from the
www.math.unipd.it web server under the /~conti/teaching/PCD1112
directory, we have to send the following GET request over the socket
connection to this web server.
GET /~conti/teaching/PCD1112/project_config.txt HTTP/1.0\r\n\r\n
The \r\n\r\n string is required by the HTTP protocol. More
specifically, the HTTP 1.0 protocol requires that every line of the
request ends with a Carriage Return (CR) followed by a Line Feed (LF).
In JAVA CR is represented by "\r" and LF is represented by "\n".
However, in the above GET request we see two of them. This second one
is required by the fact that in the HTTP 1.0 protocol the end of the
input is marked with CRLF.
if you do not believe me on my words, you can always test the above by
making a "telnet" connection to www.math.unipd.it on port 80 and send
the above GET message, without the 2 CRLFs. In stead of that you have
to press the "Enter" button after the HTTP/1.0 part of the request.
Unfortunately, the response is more complicated then the GET request.
This is caused by the fact that the response consists out of a
variable length header and a variable length payload. These two fields
within the response message are separated by a line that only contains
CRLF on it.
I think the brief explanation above about the GET request and response
are sufficient enough to be able to write the required program. For
the first exercise you have to write a HttpGet program that does the
following: i) create to the specified web server making use of JAVA
Sockets, ii) form a correct GET request message, iii) send this GET
request over the Socket connection to the web server, iv) receive the
reply line-by-line from the web server, v) and print each line of the
response on the standard output.
So, the first exercise does not require any parsing of the response.
FIRMA FOTTUTAMENTE EDITATA. IL FOTTUTO STAFF.
Mai più giorni felici
Inviato 10 novembre 2011 - 09:40