JamesBong Posted July 12, 2018 Report Posted July 12, 2018 (edited) Salut Am de facut pentru facultate un program in Java si anume sistem pentru inregistrarea studentilor unei facultati. Nu vreau sa scrie cineva programul pentru mine, am nevoie de ghidare, daca sunteti amabili. Si iata ce am facut eu pana acum : public class Student { private static String[] firstname; private static String[] surname; private static String[] course; private static String[] adress; private static String[] tel; private static String[] email; private static String[] dob; private static String[] country; private static int[] fees, id; private static int n = 0; private static int idn = 10000; private static int studentCount = 0; public static void addStudent(String fn, String sn, String crse, String adr, String tel_, String mail, String db, String ctry) { firstname[n] = fn; surname[n] = sn; course[n] = crse; adress[n] = adr; tel[n] = tel_; email[n] = mail; dob[n] = db; country[n] = ctry; id[n] = idn + 1; fees[n] = 9000; studentCount++; idn++; n++; } public static void listStudent() { for(n = 0; n < studentCount; n++) { System.out.printf("%s %s %s %s %s %s %s %s %d %d%n ", firstname[n], surname[n], course[n], adress[n], tel[n], email[n], dob[n], country[n], id[n], fees[n] ); } } } import java.util.Scanner; public class StudentTest { static Scanner input = new Scanner(System.in); public static void main(String[] args) { menu(); } public static void menu() { byte choice; System.out.println("*************************"); System.out.println("* Bright Future College *"); System.out.println("*************************"); System.out.println("1. Enroll student"); System.out.println("2. Pay fees"); System.out.println("3. List students on a course"); System.out.println("4. Change course"); System.out.println("5. View student profile"); System.out.println("6. Remove student from course"); System.out.println("7. ****Management reporting****"); System.out.println("8. Exit"); choice = input.nextByte(); input.nextLine(); switch(choice) { case 1: enroll(); menu(); break; case 3: Student.listStudent(); default: System.out.println("Please enter a valid option!"); menu(); } } public static void enroll() { System.out.println("Please enter the first name: "); String fn = input.nextLine(); System.out.println("Please enter the surname: "); String sn = input.nextLine(); System.out.println("Please enter the course: "); String crse = input.nextLine(); System.out.println("Please enter the full adress: "); String adr = input.nextLine(); System.out.println("Please enter the telephone number: "); String tel_ = input.nextLine(); System.out.println("Please enter the email: "); String mail = input.nextLine(); System.out.println("Please enter the date of birth: "); String db = input.nextLine(); System.out.println("Please enter the type of student(home or foreign "); String ctry = input.nextLine(); Student.addStudent( fn, sn, crse, adr, tel_, mail, db, ctry); } } Asta am facut pentru inceput. Nu stiu exact cum sa inregistrez studenti noi, sau cum sa chem metoda din alta clasa sa inregistrez studenti. Orice sfat ar fi foarte apreciat. Edited July 12, 2018 by JamesBong Quote
Raul Posted July 12, 2018 Report Posted July 12, 2018 Mai taie din staticele alea, da-le dreacu... 1 Quote
FoxBlood Posted July 12, 2018 Report Posted July 12, 2018 Hai ca te luam usor.. deci, nu cred te ajuta nimeni pt facultate pe forumul asta, e datoria ta sa inveti. Acel "static" inseamna ca pentru fiecare obiect in java i se atribuie aceeasi valoare, google poate explica mai bine la ce ma refer. Quote
QuoVadis Posted July 12, 2018 Report Posted July 12, 2018 https://hackhands.com/ Primele 5 minute gratuit Quote
yoyois Posted July 12, 2018 Report Posted July 12, 2018 Vai de java ta. Esti anul 1? Daca esti anul 2 nu prea e bine de tine. Mai bine te duci la arte sau finante. Da un google despre OOP (Programarea Orientata pe Obiecte) Vezi ca un Student poate fi o clasa. Un campus poate fi o clasa. Poti face o colectie de studenti intr-un campus. Un curs poate fi o clasa. Poti face o relatie reflexiva intre curs-student. Quote
black_death_c4t Posted July 13, 2018 Report Posted July 13, 2018 trolls, everywhere. @JamesBong cauta un crash course pe OOP in Java. Vezi dupa how it goes. Quote
Guest Posted July 13, 2018 Report Posted July 13, 2018 Nu prea e bine. Puteai sa faci campurile sa nu fie statice si atribuiai cu constructorul tot ce trebuie, practic faceai un student nou cand faceai un obiect nou. Ce ai facut tu nu e bine. Quote
gigiRoman Posted July 13, 2018 Report Posted July 13, 2018 Atributul static al unei clase este valabil pentru toate instantele clasei. Deci numele studentului nu are cum. Quote
JamesBong Posted July 13, 2018 Author Report Posted July 13, 2018 Sunt la inceput in saptamana 4 si trebuie sa fac asta in 3 saptamani si prea nu stiu cum....profesorul ne citeste materialul de curs si nu ne da exemple sa intelegem principiile. Quote
QuoVadis Posted July 13, 2018 Report Posted July 13, 2018 20 minutes ago, JamesBong said: .profesorul ne citeste materialul de curs si nu ne da exemple sa intelegem principiile. Banuiesc ca nu ai vreo dizabilitate/handicap si ai gura sa poti intreba si cere? Ca de aia e platit. Quote
Guest Posted July 13, 2018 Report Posted July 13, 2018 https://www.youtube.com/results?search_query=java+for+beginners Succes. Cand nu ai inteles ceva poti intreba aici. Quote
JamesBong Posted July 13, 2018 Author Report Posted July 13, 2018 Va multumesc tuturor pentru raspunsuri....O sa citesc din nou despre metode si clase si un crash course despre java. Quote
Active Members SynTAX Posted July 13, 2018 Active Members Report Posted July 13, 2018 3 hours ago, JamesBong said: Va multumesc tuturor pentru raspunsuri....O sa citesc din nou despre metode si clase si un crash course despre java. Doar de curiozitate intreb. Cum esti in saptamana 4 pe 15 Iulie? 1 Quote
JamesBong Posted July 13, 2018 Author Report Posted July 13, 2018 Sunt la facultate in UK si la facultatea la care sunt eu se incepe pe 15 iunie, chiar daca majoritatea facultatilor de aici incep in septembrie.....nu stiu de ce Quote
JamesBong Posted July 13, 2018 Author Report Posted July 13, 2018 Am facut cateva modificari la cod si acum primesc urmatoarea eroare dupa ce bag datele la enroll student si nu imi dau seama cum o pot rezolva. public class Student { private String[] firstname; private String[] surname; private String[] course; private String[] adress; private String[] tel; private String[] email; private String[] dob; private String[] country; private int[] fees; private int[] id; private int n = 0; private int idn = 10000; int studentCount = 0; public Student(String fn, String sn, String crse, String adr, String tel_, String mail, String db, String ctry) { firstname[n] = fn; surname[n] = sn; course[n] = crse; adress[n] = adr; tel[n] = tel_; email[n] = mail; dob[n] = db; country[n] = ctry; id[n] = idn + 1; fees[n] = 9000; studentCount++; idn++; n++; } public void listStudent() { for(int x = 0; x < studentCount; x++) { System.out.printf("%s %s %s %s %s %s %s %s %d %d%n ", firstname[n], surname[n], course[n], adress[n], tel[n], email[n], dob[n], country[n], id[n], fees[n] ); } } } import java.util.Scanner; public class StudentTest { static Scanner input = new Scanner(System.in); public static void main(String[] args) { menu(); } public static void menu() { byte choice; System.out.println("*************************"); System.out.println("* Bright Future College *"); System.out.println("*************************"); System.out.println("1. Enroll student"); System.out.println("2. Pay fees"); System.out.println("3. List students on a course"); System.out.println("4. Change course"); System.out.println("5. View student profile"); System.out.println("6. Remove student from course"); System.out.println("7. ****Management reporting****"); System.out.println("8. Exit"); choice = input.nextByte(); input.nextLine(); switch(choice) { case 1: enroll(); menu(); break; case 3: //Student.listStudent(); default: System.out.println("Please enter a valid option!"); menu(); } } public static void enroll() { System.out.println("Please enter the first name: "); String fn = input.nextLine(); System.out.println("Please enter the surname: "); String sn = input.nextLine(); System.out.println("Please enter the course: "); String crse = input.nextLine(); System.out.println("Please enter the full adress: "); String adr = input.nextLine(); System.out.println("Please enter the telephone number: "); String tel_ = input.nextLine(); System.out.println("Please enter the email: "); String mail = input.nextLine(); System.out.println("Please enter the date of birth: "); String db = input.nextLine(); System.out.println("Please enter the type of student(home or foreign "); String ctry = input.nextLine(); Student student = new Student(fn, sn, crse, adr, tel_, mail, db, ctry); } } Un sfat va rog. Quote
Nytro Posted July 13, 2018 Report Posted July 13, 2018 Trebuie alocat spatiu pentru acei vectori. Foloseste liste mai bine: https://www.javatpoint.com/java-list Quote
yoyois Posted July 13, 2018 Report Posted July 13, 2018 (edited) DE CE DUMNEZEII MASII TOT VAD String[] nume; Ma omoara! Vai de pula voastra daca intelege careva ce cacat e String[] r(e o declaratie neinitializata de un array de stringuri) Uite fa asa in pula mea: public class Student{ public String nume; Student(String name){ nume=name; } public class StudentTest{ pula mea main() { Student student1 = new Student("Vasili"); Student student2= new Student("Amariei"); //Baga student 1 si 2 intr-un array //fa un array de studenti Student[] listaStudenti = new Student[10]; //baga-l in array listaStudenti[0]=student1; //CITESTE IN PLM CE E ALA OOP!!! } Sfat: Petrece 4-5 zile fara sa lucrezi la cacatul tau de proiect. Petrece timpul ala invatand ce e OOP. Joaca-te cu niste exemple simple de pe google si incearca sa intelegi cum merge treaba. Nu poti sa sari de la 0 si sa faci proiectul din prima. Daca investesti timp pentru tine, ca sa inveti inainte sa te apuci sa faci un cacat, ai sanse sa construiesti un proiect acceptabil. Edited July 13, 2018 by yoyois 1 Quote
Raul Posted July 14, 2018 Report Posted July 14, 2018 11 hours ago, yoyois said: Vai de pula voastra daca intelege careva ce cacat e String[] Man, daca nu petrece timp studiind putin si sare si face totul dupa ureche... Quote
JamesBong Posted July 15, 2018 Author Report Posted July 15, 2018 Salut. Va multumesc pentru sfaturi....foarte constructive ..... Am facut un alt program prin care sa invat despre arrayList si cand dau enroll student cumva sare peste firstName si inregistreaza doar surname. Am tot incercat sa ii dau de cap si nu reusesc. import java.util.Scanner; import java.util.ArrayList; public class arrayList { static Scanner input = new Scanner(System.in); static ArrayList<String> firstName = new ArrayList<String>(); static ArrayList<String> surname = new ArrayList<String>(); public static void main(String[] args) { menu(); } public static void menu() { byte choice; System.out.println("Main menu"); System.out.println("*********"); System.out.println("1. Enroll student"); System.out.println("2. List students"); System.out.println("Make a choice: "); choice = input.nextByte(); switch(choice) { case 1: enroll(); System.out.println("You have successfully added a student."); System.out.println(); menu(); break; case 2: list(); menu(); break; default: System.out.println("Please make a valid choice."); System.out.println(); menu(); break; } } public static void list() { int n = 1; for(int x = 0; x < firstName.size();x++) { System.out.println(n + ". " + firstName.get(x) + " " + surname.get(x)); n++; } } public static void enroll() { String fn, sn; System.out.println("Please enter the first name:"); fn = input.nextLine(); System.out.println("Please enter the surname:"); sn = input.nextLine(); firstName.add(fn); surname.add(sn); } } Quote
Nytro Posted July 15, 2018 Report Posted July 15, 2018 Vezi asta: https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo 1 Quote
JamesBong Posted July 15, 2018 Author Report Posted July 15, 2018 Problema rezolvata. Iti multumesc. Quote