roy
Administrator
Dołączył: 02 Gru 2007
Posty: 70
Przeczytał: 0 tematów
Skąd: Głuchołazy
|
Wysłany: Czw 9:06, 07 Maj 2009 Temat postu: LISTA 2 ZADANIE Z INDEXEM |
|
|
Nie ma tu polimorfizmu ale jest dziedziczenie
Kod: |
import javax.swing.JOptionPane;
class Student
{
//static InputStreamReader StrumienWejsciowy = new InputStreamReader(System.in);
//static BufferedReader BuforWejsciowy = new BufferedReader(StrumienWejsciowy);
public String Imie;
public String Nazwisko;
public Przedmiot [] Przedmioty = new Przedmiot[99];
public int iloscPrzedmiotow;
public void Wstaw_Studenta()
{
//String Str_nazwisko;
Dodaj_Imie_Nazwisko();
Dodaj_Przedmioty();
}
public void Dodaj_Przedmioty()
{
String s_ilosc=JOptionPane.showInputDialog(null, "Podaj liczbę przedmiotów");
int ilosc =Integer.parseInt(s_ilosc);
for(int x = 0; x<ilosc; x++)
{
Przedmioty[x] = new Przedmiot();
String s_nazwa=JOptionPane.showInputDialog(null, "Podaj nazwe przedmiotu nr:"+x);
Przedmioty[x].Nazwa = s_nazwa;
String s_prowadzacy=JOptionPane.showInputDialog(null, "Podaj prowadzącego dla przedmiotu nr:"+x);
Przedmioty[x].Prowadzacy = s_prowadzacy;
Przedmioty[x].zaliczenie = new ZaliczeniePoprawkowe();
iloscPrzedmiotow++;
}
}
public void Dodaj_Imie_Nazwisko()
{
String l1 =JOptionPane.showInputDialog(Nazwisko, "Podaj nazwisko Studenta");
Nazwisko = l1;
String l2 = JOptionPane.showInputDialog(Imie, "Podaj imie Studenta");
Imie =l2;
}
public void WyswietlDane()
{
JOptionPane.showMessageDialog(null, "Imie i Nazwisko: " + Imie + " " + Nazwisko + "\n");
if (iloscPrzedmiotow >0 )
{
Wyswietl_Przedmioty();
}
}
public void Wyswietl_Przedmioty()
{
for (int j=0; j<iloscPrzedmiotow; j++)
{
JOptionPane.showMessageDialog(null, "Nr. " + j + " Nazwa: " + Przedmioty[j].Nazwa + " Prowadzacy: "+ Przedmioty[j].Prowadzacy + "\n");
}
}
}
class Przedmiot
{
public String Nazwa;
public String Prowadzacy;
public ZaliczeniePoprawkowe zaliczenie;
}
class Zaliczenie
{
public float Ocena;
public String DataZaliczenia;
public String Wpis;
}
class ZaliczeniePoprawkowe extends Zaliczenie
{
public float Ocena2termin;
public String DataZaliczenia2termin;
public String Wpis2termin;
public float Ocena3termin;
public String DataZaliczenia3termin;
public String Wpis3termin;
}
public class IndexProgram {
//static InputStreamReader StrumienWejsciowy = new InputStreamReader(System.in);
//static BufferedReader BuforWejsciowy = new BufferedReader(StrumienWejsciowy);
static int ile_studentow = 0;
static public void main(String args[]){
int wybor;
Student[] Dane = new Student[100];
for (int i=0; i<100; i++)
{
Dane[i]= new Student();
}
do
{
String s_wybor=JOptionPane.showInputDialog(null, "Podaj wybor"
+"\n1 - Dodaj Studenta,"
+ "\n2 - Wyswietl dane studenta"
+ "\n3 - Dodaj oceny"
+ "\n9 - Koniec programu");
wybor = Integer.parseInt(s_wybor);
switch (wybor)
{
case 1:
{
Dane[ile_studentow].Wstaw_Studenta();
ile_studentow++;
}break;
case 2:
{
if (ile_studentow == 0)
{
JOptionPane.showMessageDialog(null, "Baza jest pusta Dodaj najpierw studenta !");
}
else
{
String s_nr=JOptionPane.showInputDialog(null, "Wybierz studenta podaj numer z zakresu 0 -" +ile_studentow);
int nr = Integer.parseInt(s_nr);
Dane[nr].WyswietlDane();
}
break;
}
case 3 :
{
{
if (ile_studentow == 0)
{
JOptionPane.showMessageDialog(null, "Baza jest pusta Dodaj najpierw studenta !");
}
else
{
String s_nrStudenta=JOptionPane.showInputDialog(null, "Wybierz studenta podaj numer z zakresu 0 -" +ile_studentow);
int nrStudenta = Integer.parseInt(s_nrStudenta);
Dane[nrStudenta].Wyswietl_Przedmioty();
String s_nrPrzedmiotu=JOptionPane.showInputDialog(null, "Podaj nr przedmiotu:");
int nrPrzedmiotu;
nrPrzedmiotu = Integer.parseInt(s_nrPrzedmiotu);
if(Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.Ocena == 2)
{
if(Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.Ocena2termin == 2)
{
if(Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.Ocena3termin == 2)
{
System.out.print("Witamy w wojsku");
}
else
{
String data=JOptionPane.showInputDialog(null, "Podaj date:");
Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.DataZaliczenia3termin = data;
String ocena=JOptionPane.showInputDialog(null, "Podaj ocene:");
Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.Ocena3termin = Float.parseFloat(ocena);
}
}
else
{
String data=JOptionPane.showInputDialog(null, "Podaj date:");
Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.DataZaliczenia2termin = data;
String ocena=JOptionPane.showInputDialog(null, "Podaj ocene:");
Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.Ocena2termin = Float.parseFloat(ocena);
}
}
else
{
String data=JOptionPane.showInputDialog(null, "Podaj date:");
Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.DataZaliczenia = data;
String ocena=JOptionPane.showInputDialog(null, "Podaj ocene:");
Dane[nrStudenta].Przedmioty[nrPrzedmiotu].zaliczenie.Ocena = Float.parseFloat(ocena);
}
}
}
break;
}
case 9 :
{
JOptionPane.showMessageDialog(null, "Koniec");
break;
}
default:
JOptionPane.showMessageDialog(null,"Zła opcja!");
}
} while (wybor != 9) ;
}
}
|
|
|