Wątek zablokowany 2015-01-31 00:30 przez furious programming.

Wirtualny dziekanat - jak to zrobić?

0

Witam. Potrzebuje pomocy w napisaniu czegoś takiego:

Napisz program wczytujący dane dziesięciu studentów (nazwisko, imię, numer indeksu, rok urodzenia, tabela pięciu ocen z egzaminu). Następnie program powinien umożliwiać:

wyświetlanie informacji o studencie z podanym numerem indeksu
wyświetlanie informacji o wszystkich studentach
obliczenie wieku studentów
obliczenie średniej poszczególnych studentów z podanych ocen
wyświetlenie studentów, których średnia nie przekracza 3.5
sortowanie studentów względem wieku (od najmłodszego do najstarszego)

Do tego celu wykorzystaj stworzoną przez siebie klasę Student z odpowiednimi składowymi i metodami.

Nie chce zeby ktos napsal to za mnie tylko zeby mi wytlumaczyl jak to zrobic i jak do tego podejsc

0

To ma być baza danych tzn ma się zapisywać na dysku ? bo z zadania to nie wynika.
Klasę Student z tymi polami już masz, możesz stworzyć klase StudentManager która w metodach będzie przyjmować tablicę/listę studentów(ew. zapisze ją sobie na stałe w odpowiednim polu za pomocą konstruktora), w mainie switch i wybierz odpowiednią opcję, nie rozumiem, gdzie widzisz problem i nie rozumiem jak można pomóc w takim zadaniu (nie mówię tego na złość :P)

0

Aplikacja konsolowa czy okienkowa? Jaki język programowania? Skąd masz wczytac tych 10 studentów, z bazy czy pliku tekstowego?

0

Musi byc napisane w javie. Studenci maja byc zapisani w programie. Musze stworzyc klase studenci i wpisac tam 10 studentow (imie,nazwisko, date ur, itd.) Zupelnie nie wiem jak to zrobic. Wyswietlanie tych podpunktow jakos zrobie ale nie potrafie po prostu tego zaczac

0
Student[] studenci = new Student[10];
StudentManager sm = new StudentManager();
Scanner sc = new Scanner(System.in);
for(Student a: studenci)
{
a.setImie(sc.nextLine());
...
}
System.out.println("Menu : \n0.Zakoncz \n1. Opcja 1\n2. Opcja 2\n3. Opcja 3");
int i;
while((i=sc.nextInt())!=0)
switch(i)
{
case1:
sm.funkcja1(studenci);
break;
....
}

można taki main ? Piszę funkcję z pamięci nie wiem czy dobrze xd

0

jeżeli masz już klasę Student reprezentującą studenta, to teraz napisz prawidłowo
tą klasę StudentManager, która zajmuje się tylko przechowywaniem tych studentów i serwuje Ci potrzebne metody typu:

void dodajStudenta(Student student);
Student findByNumerIndeksu(int numerIndeksu);
List<Student> findBySredniaMniejszaNiz(double srednia);

itd...

potem wyniki użycia StudentMangera w main będziesz sobie wypisywać sysoutem.

dodanie znacznika <code class="java"> - @furious programming

0

A oprócz StudentManagera, potrzebujesz też oczywiście StudentHelpera, StudentFactory, StudentManagerFactory, StudentHelperFactory i StudentFactoryFactory nie licząc StudentFactoryManager i StudentFactoryHelperManagera.

A tak na serio - jeśli jakaś klasa ma w nazwie Manager, to znaczy, że nie wiadomo do czego tak naprawdę ona ma służyć, więc jest niepotrzebna.

0

Juz sie troche pogubilem :D ale dziekuje wszystkim za pomoc jutro dzisiaj wieczorem jak wroce z pracy to siade do tego i postaram sie cos napisac i wynikami "pochwale" sie na forum :D

0

Najlepiej napisz w konsoli,tak bedzie najprosciej.
Stwórz na początku menu które będzie wykonywac konkretną funkcje przy wpisaniu jakiejs liczby.

1
package com.java.model;


public class Student {
	private String lastname;
	private String name;
	private int numberOfIndex;
	private int dateOfBirth;
	private double[] evaluations;
	
	public Student(String lastname, String name, int numberOfIndex,
			int dateOfBirth) {
		super();
		this.lastname = lastname;
		this.name = name;
		this.numberOfIndex = numberOfIndex;
		this.dateOfBirth = dateOfBirth;
	}

	public Student(String lastname, String name, int numberOfIndex,
			int dateOfBirth, double[] evaluations) {
		super();
		this.lastname = lastname;
		this.name = name;
		this.numberOfIndex = numberOfIndex;
		this.dateOfBirth = dateOfBirth;
		this.evaluations = evaluations;
	}
	
	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getNumberOfIndex() {
		return numberOfIndex;
	}

	public void setNumberOfIndex(int numberOfIndex) {
		this.numberOfIndex = numberOfIndex;
	}

	public int getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(int dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	public double[] getEvaluations() {
		return evaluations;
	}

	public void setEvaluations(double[] evaluations) {
		this.evaluations = evaluations;
	}
	
	public String toString(){
		return lastname + " " + name + " " + numberOfIndex + " " + dateOfBirth;
		
	}
	public void printEvalutions(){
		for(double e : evaluations){
			System.out.print(e + " ");
		}
	}
	
	public double myAvg(){
		double sum = 0;
		double avg = 0;
		for(int i=0; i<evaluations.length; i++){
			sum +=  evaluations[i];
		}
		avg = sum/evaluations.length;
		return avg;
	}
	
} 
package com.java.repository;

import java.util.ArrayList;
import java.util.List;

import com.java.model.Student;

public class StudentRepository {

	private List<Student> listOfStudents = new ArrayList<Student>();

	// public StudentRepository(){};

	// imitacja zamiast wczytywania z bazy/pliku
	public StudentRepository() {
		double[] tab1 = { 5, 4, 4, 4, 5 };
		double[] tab2 = { 3, 2, 5, 2, 5 };
		double[] tab3 = { 2, 2, 2, 2, 2 };
		listOfStudents.add(new Student("Nowak", "Jan", 1112, 1992, tab1));
		listOfStudents.add(new Student("Skoczek", "Dawid", 1113, 1993, tab2));
		listOfStudents.add(new Student("Zucek", "Joanna", 1114, 1989, tab3));
	}

	public List<Student> getAllStudents() {
		return listOfStudents;
	}

	public void addStudent(Student student) {
		listOfStudents.add(student);
	}

	public Student getStudentByNumberOfIndex(int numberOfIndex) {
		for (Student s : listOfStudents) {
			if (s.getNumberOfIndex() == numberOfIndex) {
				return s;
			}
		}
		return null;
	}

	public void deleteStudent(int numberOfIndex) {
		for (Student s : listOfStudents) {
			if (s.getNumberOfIndex() == numberOfIndex) {
				listOfStudents.remove(s);
			}
		}
	}
}

 
package com.java.test;

import java.util.List;
import java.util.Scanner;

import com.java.model.Student;
import com.java.repository.StudentRepository;

public class Dziekanat {

	public static void main(String[] args) {
		int yourChoice;
		do {
			System.out.println();
			System.out.println("1.Wyświetl wszystkich studentów.");
			System.out.println("2. Dane konretnego studenta.");
			System.out.println("3. Średnia mniejsza niż 3.5");
			System.out.println("4. Studenci i ich średnia.");
			System.out.print("Twój wybór: ");
			Scanner sc = new Scanner(System.in);
			yourChoice = sc.nextInt();

			switch (yourChoice) {
			case 0:{
				System.out.println("KONIEC");
				break;
			}
			case 1: {
				StudentRepository sr = new StudentRepository();
				List<Student> listOfStudents = sr.getAllStudents();
				for (Student s : listOfStudents) {
					System.out.print("\nStudent: " + s.toString() + " oceny: ");
					s.printEvalutions();
				}
				break;
			}
			case 2: {
				System.out.println("Podaj nr indeksu: ");
				int numberOfIndex = sc.nextInt();
				StudentRepository sr = new StudentRepository();
				Student student = sr.getStudentByNumberOfIndex(numberOfIndex);
				if (student != null) {
					System.out.print(student.toString());
					student.printEvalutions();
				} else {
					System.out.println("Nie ma takiego studenta.");
				}
				break;

			}
			case 3: {
				StudentRepository sr = new StudentRepository();
				List<Student> listOfStudents = sr.getAllStudents();
				System.out.println("Osoby z średnią mniejszą niż 3.5 to: ");
				for (Student s : listOfStudents) {
					if (s.myAvg() < 3.5) {
						System.out.print("\n" + s.toString());
					}
				}
				break;
			}
			case 4: {
				StudentRepository sr = new StudentRepository();
				List<Student> listOfStudents = sr.getAllStudents();

				for (Student s : listOfStudents) {
					System.out.print("\nStudent: " + s.toString()
							+ " średnia: " + s.myAvg());
				}
				break;
			}
			default:{
				System.out.println("Nie ma takiej opcji.");
			}
			}
		} while (yourChoice != 0);
	}
}

Do ideału pewnie daleko, ale bardziej doświadczeni może podpowiedzą co poprawić.

0

@somekind taką nazwę zaproponował już ktoś wcześniej. miałam na myśli jakiś StudentService.

@ariel.wojcik.1991
http://ideone.com/pLnOl4

tutaj masz kawałek kodu w java8, który może Ci lekko pomóc

EDIT nie zauważyłam poprzedniego wpisu -
klasa Student: dateOfBirth czemu nie jest java.util.Date?
w main'ie stwórz raz StudentRepository i tyle

0

okej czyli co tu dokładnie trzeba poprawić w tym kodzie ?:>

1 użytkowników online, w tym zalogowanych: 0, gości: 1