-3

i have trouble with my java project homework. in this program when i use case 1 it activates student recording system. i need i must write all of this recording system with method. i tried but i failed. can you show me how can i write method which records informations to array ? Thanks a lot .

//===========================================values
String[] name = new String [100];
String[] gender = new String [100];
String[] studentNo = new String [100];
Double[] gpa = new Double [100];
int menu = 0;
int accountNumber = 0;

//===========================================
menu = in.nextInt();
switch (menu) 
case 1:  {
System.out.println("** Recording a new student");
System.out.println("*** Please use lower case");
in.nextLine(); // for solve skipping 

System.out.print("Enter Student Name and Surname: ");
name[accountNumber] = in.nextLine();

System.out.print("Enter Student Gender(m/f): ");
gender[accountNumber] = in.nextLine();

System.out.print("Enter Student Number: ");
studentNo[accountNumber] = in.nextLine();

System.out.print("Enter Student GPA: ");
gpa[accountNumber] = in.nextDouble();

accountNumber++;


System.out.println("New Student Recorded. There are ["+accountNumber+"] students in system.");
System.out.println("");
}break;
Beau Grantham
  • 3,435
  • 5
  • 33
  • 43
Gökhan Nas
  • 45
  • 2
  • 8
  • 1
    Folks here will bristle if you ask them to have them do your homework for you, `" can you show me how can i write method which records informations to array ?"` Much better would be to show your attempt to solve this, to let us know what is wrong with the attempt, and to ask *specific* questions over just what confuses you. Voting to close. – Hovercraft Full Of Eels May 08 '13 at 19:02
  • I Already did my homework that show on code. It's my extra request :) – Gökhan Nas May 08 '13 at 19:04
  • You're not getting the point, I'm afraid. You will want to improve this question soon lest it gets closed. – Hovercraft Full Of Eels May 08 '13 at 19:05
  • Don't give me any point i just wanna learn. – Gökhan Nas May 08 '13 at 19:06
  • Guys, I said I already submitted my project to my teacher. I tried the convert this case but i failed. – Gökhan Nas May 08 '13 at 19:11
  • I support Hovercraft Full of Eels vote to close, but just put everything between the opening { and closing } in a simple method. – Frecklefoot May 08 '13 at 19:12
  • also this is just 1 case , i have already 7 cases too. – Gökhan Nas May 08 '13 at 19:14
  • when i put everything in a simple void method, i will have just a method . what can i do with it for run program clearly? i need this answer basically... – Gökhan Nas May 08 '13 at 19:17
  • when you run your application you have a much better code, for reading and mainteinance as well as you make it reusable for other components in the future. – Marcelo Tataje May 08 '13 at 20:06

1 Answers1

-1

Well, I agree with people to do your homework, to use methods you just have to know, you must separate code, "divide and conquer", now that you submitted your project, the solution could be this way (using arrays of course), I would have used a bean or dto to store the info, but maybe is a requirement for you to use arrays:

public class DoYourHomework {

    String[] name = new String[100];
    String[] gender = new String[100];
    String[] studentNo = new String[100];
    Double[] gpa = new Double[100];
    int menu = 0;
    int accountNumber = 0;

    public DoYourHomework() {
        Scanner in = new Scanner(System.in);
        menu = in.nextInt();
        switch (menu) {
        case 1:  {
        System.out.println("** Recording a new student");
        System.out.println("*** Please use lower case");
        in.nextLine(); // for solve skipping 

        String name = null;
        String number = null;
        String gender = null;
        double gpa = -1;

        System.out.print("Enter Student Name and Surname: ");
        name = in.nextLine();

        System.out.print("Enter Student Gender(m/f): ");
        gender = in.nextLine();

        System.out.print("Enter Student Number: ");
        number = in.nextLine();

        System.out.print("Enter Student GPA: ");
        gpa = in.nextDouble();

        registerNewStudent(name, gender, number, gpa);
        accountNumber++;


        System.out.println("New Student Recorded. There are ["+accountNumber+"] students in system.");
        System.out.println("");
        }
        }

    }

    private void registerNewStudent(String name2, String gender2,
            String number, double gpa2) {
        name[accountNumber] = name2;
        gender[accountNumber] = gender2;
        studentNo[accountNumber] = number;
        gpa[accountNumber] = gpa2;
    }

    public static void main(String[] args) {
        new DoYourHomework();
    }

}

Hope it helps you to understand for your next exercises. Maybe, as a plus, you can add validation to avoid the same student number or try to do the next operations such "modify and delete" by yourself. Best regards.

Marcelo Tataje
  • 3,849
  • 1
  • 26
  • 51