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.










share|improve this question









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 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















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.










share|improve this question









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 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













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.










share|improve this question









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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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 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


















  • 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
















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















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






dealvidit is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















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






























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.










draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno