Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Fondamenti di architettura e programmazione > Aiuto Esercizio!
  Last Thread   Next Thread
Author
Thread    Post New Thread    Post A Reply
Strong
.consigliere.

User info:
Registered: Dec 2007
Posts: 138 (0.02 al dì)
Location: Bergamo
Corso: Comunicazione Digitale
Anno:
Time Online: 1 Day, 9:25:25 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Aiuto Esercizio!

Vi chiedo un'info su una tipologia che mette sempre delle prove scritte. Faccio riferimento a un esercizio, esattamente al 7 e all'8 della prova del 26 febbraio 2010.

Allora, ecco le classi che ho sviluppato (simili se non identiche alla correzione)

PHP:

public class Corso implements Comparable{

    private String nome, docente;
    private int crediti;

    public Corso(String nm, String cgm, int cfu){
        nome = nm;
        docente = cgm;
        crediti = cfu;
    }

    public Corso(String nm, String cgm){
        this(nm, cgm, 6);
    }

    public String getNome(){
        return nome;
    }

    public String getTitolare(){
        return docente;
    }

    public int getCrediti(){
        return crediti;
    }

    public String toString(){
        return nome + " " + docente + " " + crediti;
    }

    public boolean haCreditiMaggiori(Corso c){
        return docente.equals(c.docente) && crediti > c.crediti;
    }

    public int compareTo(Object o){
        Corso c = (Corso) o;
        if(getCrediti() > c.getCrediti())
            return 1;
        else
            if(getCrediti() < c.getCrediti())
                return -1;
            else
                return 0;
    }

}



PHP:

class CorsoLab extends Corso{

    private String laboratorio;

    public CorsoLab(String nm, String cgm, int cfu, String lab){
        super(nm, cgm, cfu);
        laboratorio = lab;
    }

    public String getLab(){
        return laboratorio;
    }

    public String toString(){
        return super.toString() + " " + laboratorio;
    }


}



ed ecco il programma:

PHP:

import prog.io.*;
import prog.utili.*;

class CorsoProg{
    public static void main(String[] args){

    ConsoleInputManager in = new ConsoleInputManager();
    ConsoleOutputManager out = new ConsoleOutputManager();

    int n = in.readInt("Quanti corsi?");
    Corso[] corsi = new Corso[n];

    for(int i=0; i<n; i++){
        String nome = in.readLine("Nome del corso " + (i+1) + ": ");
        String docente = in.readLine("Nome del titolare del corso " + (i+1) + ": ");
        int crediti = in.readInt("Numero di crediti del corso " + (i+1) + ": ");
        boolean s = in.readSiNo("E' un corso di laboratorio? (s/n) ");
        if (!s)
             corsi[i] = new Corso(nome, docente, crediti);
        else{
            String lab = in.readLine("Nome del laboratorio in cui si tiene il corso " + (i+1) + ": ");
            corsi[i] = new CorsoLab(nome, docente, crediti, lab);
        }
    }

    for(int i=0; i<n; i++){
        if(corsi[i].getTitolare().equals("Rossi"))
            out.println(corsi[i].toString());
    }

    GestioneArray.ordina(corsi);
    for(int i=0; i<n; i++){
        if(corsi[i] instanceof CorsoLab)
            out.println(corsi[i].toString());
    }

    }
}



Se compilo il programma mi da questo errore:
PHP:

Note: CorsoProg.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.



Lo ricompilo con javac CorsoProg.java -Xlint ed esce questo avviso:
PHP:

CorsoProg.java:31: warning: [unchecked] unchecked method invocation: <T>ordina(T[]) in prog.utili.GestioneArray is applied to (Corso[])
    GestioneArray.ordina(corsi);
                        ^
1 warning



Scusate l'eccessiva lunghezza del post. Forse lo ha detto a lezione, non riesco a risolvere. Il programma è esatto, solo che non lo compila.

26-01-2012 15:12
Click Here to See the Profile for Strong Click here to Send Strong a Private Message Find more posts by Strong Add Strong to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Strong
.consigliere.

User info:
Registered: Dec 2007
Posts: 138 (0.02 al dì)
Location: Bergamo
Corso: Comunicazione Digitale
Anno:
Time Online: 1 Day, 9:25:25 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Volendo posso risolvere in questo modo:

PHP:

for(int i=0; i<30; i++){
        for(int j=0; j<n; j++){
            if(corsi[j] instanceof CorsoLab){
                if(corsi[j].getCrediti() == i)
                    out.println(corsi[j].toString());
            }
        }
    }



senza utilizzare le interfacce. La mia domanda cmq rimane :)

26-01-2012 15:42
Click Here to See the Profile for Strong Click here to Send Strong a Private Message Find more posts by Strong Add Strong to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 19:39.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.038 seconds (79.12% PHP - 20.88% MySQL) con 23 query.