A novice student record system
up vote
1
down vote
favorite
I am an extreme novice in Java and thus trying to practise some online exercises. One of them involved creating a basic student record system.
This is what I've come up with but I think a lot of things are quite redundant in my code so any reviews are greatly appreciated.
Student.java
class Student {
int rollno;
String name;
Student(int r, String n) {
this.rollno = r;
this.name = n;
}
}
StudentDB.java
import java.util.Scanner;
class Main {
public static void getStudents(Student ...students) {
int i = 1;
for (Student x : students) {
System.out.println("Student Number : " + i);
System.out.println("Name -> "+ x.name);
System.out.println("Roll Number -> " + x.rollno + "n");
i++;
}
}
public static void main(String args) {
Scanner sc = new Scanner(System.in);
System.out.print("Number of students? ");
int num = sc.nextInt();
String name = new String[num];
int rollno = new int[num];
System.out.println("Enter those " + num + " students one by one");
for (int i = 0; i < num; i++) {
System.out.println("Enter details for student no. " + (i + 1));
System.out.print("Enter Name: ");
name[i] = sc.next();
System.out.print("Enter Roll Number: ");
rollno[i] = sc.nextInt();
System.out.println("n");
}
Student students = new Student[num];
for (int i = 0; i < num; ++i) {
students[i] = new Student(rollno[i], name[i]);
}
getStudents(students);
}
}
I would really love it if someone could tell me as to how can I pass those name and rollno arrays directly to the vararg function getStudents without creating that Student object array.
java beginner
New contributor
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
1
down vote
favorite
I am an extreme novice in Java and thus trying to practise some online exercises. One of them involved creating a basic student record system.
This is what I've come up with but I think a lot of things are quite redundant in my code so any reviews are greatly appreciated.
Student.java
class Student {
int rollno;
String name;
Student(int r, String n) {
this.rollno = r;
this.name = n;
}
}
StudentDB.java
import java.util.Scanner;
class Main {
public static void getStudents(Student ...students) {
int i = 1;
for (Student x : students) {
System.out.println("Student Number : " + i);
System.out.println("Name -> "+ x.name);
System.out.println("Roll Number -> " + x.rollno + "n");
i++;
}
}
public static void main(String args) {
Scanner sc = new Scanner(System.in);
System.out.print("Number of students? ");
int num = sc.nextInt();
String name = new String[num];
int rollno = new int[num];
System.out.println("Enter those " + num + " students one by one");
for (int i = 0; i < num; i++) {
System.out.println("Enter details for student no. " + (i + 1));
System.out.print("Enter Name: ");
name[i] = sc.next();
System.out.print("Enter Roll Number: ");
rollno[i] = sc.nextInt();
System.out.println("n");
}
Student students = new Student[num];
for (int i = 0; i < num; ++i) {
students[i] = new Student(rollno[i], name[i]);
}
getStudents(students);
}
}
I would really love it if someone could tell me as to how can I pass those name and rollno arrays directly to the vararg function getStudents without creating that Student object array.
java beginner
New contributor
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Why don't you want to create aStudent? If you don't, you just have a seemingly unrelated collection of names and roll numbers. Not to mention no use for theStudentclass
– Katie.Sun
17 mins ago
@Katie.Sun I just thought it seemed a bit redundant making Student[ ] when my function takes varargs as parameter.
– dealvidit
7 mins ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am an extreme novice in Java and thus trying to practise some online exercises. One of them involved creating a basic student record system.
This is what I've come up with but I think a lot of things are quite redundant in my code so any reviews are greatly appreciated.
Student.java
class Student {
int rollno;
String name;
Student(int r, String n) {
this.rollno = r;
this.name = n;
}
}
StudentDB.java
import java.util.Scanner;
class Main {
public static void getStudents(Student ...students) {
int i = 1;
for (Student x : students) {
System.out.println("Student Number : " + i);
System.out.println("Name -> "+ x.name);
System.out.println("Roll Number -> " + x.rollno + "n");
i++;
}
}
public static void main(String args) {
Scanner sc = new Scanner(System.in);
System.out.print("Number of students? ");
int num = sc.nextInt();
String name = new String[num];
int rollno = new int[num];
System.out.println("Enter those " + num + " students one by one");
for (int i = 0; i < num; i++) {
System.out.println("Enter details for student no. " + (i + 1));
System.out.print("Enter Name: ");
name[i] = sc.next();
System.out.print("Enter Roll Number: ");
rollno[i] = sc.nextInt();
System.out.println("n");
}
Student students = new Student[num];
for (int i = 0; i < num; ++i) {
students[i] = new Student(rollno[i], name[i]);
}
getStudents(students);
}
}
I would really love it if someone could tell me as to how can I pass those name and rollno arrays directly to the vararg function getStudents without creating that Student object array.
java beginner
New contributor
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am an extreme novice in Java and thus trying to practise some online exercises. One of them involved creating a basic student record system.
This is what I've come up with but I think a lot of things are quite redundant in my code so any reviews are greatly appreciated.
Student.java
class Student {
int rollno;
String name;
Student(int r, String n) {
this.rollno = r;
this.name = n;
}
}
StudentDB.java
import java.util.Scanner;
class Main {
public static void getStudents(Student ...students) {
int i = 1;
for (Student x : students) {
System.out.println("Student Number : " + i);
System.out.println("Name -> "+ x.name);
System.out.println("Roll Number -> " + x.rollno + "n");
i++;
}
}
public static void main(String args) {
Scanner sc = new Scanner(System.in);
System.out.print("Number of students? ");
int num = sc.nextInt();
String name = new String[num];
int rollno = new int[num];
System.out.println("Enter those " + num + " students one by one");
for (int i = 0; i < num; i++) {
System.out.println("Enter details for student no. " + (i + 1));
System.out.print("Enter Name: ");
name[i] = sc.next();
System.out.print("Enter Roll Number: ");
rollno[i] = sc.nextInt();
System.out.println("n");
}
Student students = new Student[num];
for (int i = 0; i < num; ++i) {
students[i] = new Student(rollno[i], name[i]);
}
getStudents(students);
}
}
I would really love it if someone could tell me as to how can I pass those name and rollno arrays directly to the vararg function getStudents without creating that Student object array.
java beginner
java beginner
New contributor
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 27 mins ago
200_success
127k15148412
127k15148412
New contributor
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 39 mins ago
dealvidit
61
61
New contributor
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
dealvidit is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Why don't you want to create aStudent? If you don't, you just have a seemingly unrelated collection of names and roll numbers. Not to mention no use for theStudentclass
– Katie.Sun
17 mins ago
@Katie.Sun I just thought it seemed a bit redundant making Student[ ] when my function takes varargs as parameter.
– dealvidit
7 mins ago
add a comment |
Why don't you want to create aStudent? If you don't, you just have a seemingly unrelated collection of names and roll numbers. Not to mention no use for theStudentclass
– Katie.Sun
17 mins ago
@Katie.Sun I just thought it seemed a bit redundant making Student[ ] when my function takes varargs as parameter.
– dealvidit
7 mins ago
Why don't you want to create a
Student ? If you don't, you just have a seemingly unrelated collection of names and roll numbers. Not to mention no use for the Student class– Katie.Sun
17 mins ago
Why don't you want to create a
Student ? If you don't, you just have a seemingly unrelated collection of names and roll numbers. Not to mention no use for the Student class– Katie.Sun
17 mins ago
@Katie.Sun I just thought it seemed a bit redundant making Student[ ] when my function takes varargs as parameter.
– dealvidit
7 mins ago
@Katie.Sun I just thought it seemed a bit redundant making Student[ ] when my function takes varargs as parameter.
– dealvidit
7 mins ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
dealvidit is a new contributor. Be nice, and check out our Code of Conduct.
dealvidit is a new contributor. Be nice, and check out our Code of Conduct.
dealvidit is a new contributor. Be nice, and check out our Code of Conduct.
dealvidit is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208712%2fa-novice-student-record-system%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why don't you want to create a
Student? If you don't, you just have a seemingly unrelated collection of names and roll numbers. Not to mention no use for theStudentclass– Katie.Sun
17 mins ago
@Katie.Sun I just thought it seemed a bit redundant making Student[ ] when my function takes varargs as parameter.
– dealvidit
7 mins ago