Results 1 to 7 of 7
- 09-29-2012, 02:33 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 3
- Rep Power
- 0
Need quite a bit of help with a program for Storing and Working with data
Anyway I've got this little "assignment" from a buddy of mine helping me start Java but I am having problems how thing actually work.
I need to realise a system in which we can input a N number of students each of which has an M number of grades (in different subjects)
(1<=N<=10) , (1<=M<=10)
Each student has:
a name
a grade (from 1 to 12)
array of marks (scores)
Each mark has:
a subject
a score from 1 to 6
I'm using the eclipse console for input/output so there is no need for some sort of user interface or anything
The system should be structured like so:
2 classes (java beans) Student and Score which have the setters, getters and variables.
Third class for solving the problem and creating the input
Using 2 embedded cycles I need to calculate the average grade of each student
Anyway there are a few other things but right now I'm stuck because I'm not sure how to store the information.
I tried this:
First class for entering names etc.
Java Code:public class Student { private String names; private int grade; private String[] scores; public String getNames() { return names; } public void setNames(String names) { this.names = names; } public int getGrade() { return grade; } public void setGrade(int grade) { this.grade = grade; } public String[] getScores() { return scores; } public void setScores(String[] scores) { this.scores = scores; } }
2nd class for grade information
Java Code:public class Grades extends Student { private String subject; private int grade; public String getSubject() { return subject; } public void setSubject(String subject) { this.subject = subject; } public int getGrade() { return grade; } public void setGrade(int grade) { this.grade = grade; } }
Main body of the program
Java Code:import java.io.*; public class UserInput { public static int readInt() throws IOException { while(true) { try { return Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine()); } catch (NumberFormatException e) { System.out.println("Input a Number!"); } } } public static String readLine() throws IOException { return new BufferedReader(new InputStreamReader(System.in)).readLine(); } public static void main(String[] args) throws IOException{ System.out.println("Plese input how many students you wish to enter into the system:"); int studentNumber = readInt(); for (int i = 0; i < studentNumber; i++){ System.out.println("Please input student name"); Student student = new Student(); student.setNames(readLine()); System.out.println("You have just entered the name " + student.getNames() + " "); System.out.println("Please input in which grade the student " +student.getNames() + " is"); student.setGrade(readInt()); } } }
My first issue is that I only have 1 String for a name. So that every time the user inputs a student name it is replaced by the old one.
I tried using an arrayList but I can't get the getters and setters to work.
Maybe someone could help me with that initial issue?
And when I stumble across another issue you guys can help me with it so I can work piece by piece.
- 09-29-2012, 02:55 PM #2
- 09-29-2012, 03:14 PM #3
Re: Need quite a bit of help with a program for Storing and Working with data
Please post the code that shows the problem.I tried using an arrayList but I can't get the getters and setters to work.If you don't understand my response, don't ignore it, ask a question.
- 09-29-2012, 11:50 PM #4
Member
- Join Date
- Sep 2012
- Posts
- 3
- Rep Power
- 0
Re: Need quite a bit of help with a program for Storing and Working with data
It isn't really homework per-say.
My company has open junior java dev positions and I'm trying to get some basics (I mean the pay is quite better than my current position).
So I've been reading up a bit and one of the senior developers gave me this assignment to show me some java basics so I'm trying to figure it out.
Anyway I'm trying the following setter which I think is rather wrong?
And in the main:Java Code:public void addName(String names) { this.names.add(names); }
The second one is Line 33 in my MainJava Code:student.addName(readLine());
This is really basic stuff but I'd really appreciate it if you bear with me. I have had some shell script experience but it was very limited due to the nature of my work and I have very little other experience in coding.
- 09-30-2012, 12:35 AM #5
Re: Need quite a bit of help with a program for Storing and Working with data
What happens when you compile and execute the code?
The compiler is much better than I am at finding syntax errors.
The few lines of code you posted do not show all that needs to be shown to find errors.
Copy and paste here the full text of the error messages.If you don't understand my response, don't ignore it, ask a question.
- 09-30-2012, 01:31 PM #6
Member
- Join Date
- Sep 2012
- Location
- Australia
- Posts
- 12
- Rep Power
- 0
Re: Need quite a bit of help with a program for Storing and Working with data
you dont create ArrayList of names, you will need to create arrayList of Student
This is just a template. create Student object inside a loop and store into ArrayList.Java Code:class Student { private String name; private int grade; private String[] scores; } //then something to store collection of studnets class StudentCollection { private ArrayList<Student> studentList = new ArrayList<Studnet>(); //create object of student Student student = new Student(); student.setName("Tom"); student.setGrade(10); //once student object is created then save in Arraylist studentList.add(student); }
Hope this will help.
- 10-01-2012, 10:30 AM #7
Member
- Join Date
- Sep 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Need Help with storing and displaying data
By Mitho in forum New To JavaReplies: 5Last Post: 04-10-2012, 11:20 PM -
storing data in queues
By javanut123 in forum New To JavaReplies: 1Last Post: 12-04-2011, 08:10 PM -
Storing local data?
By DennisMadsen in forum Advanced JavaReplies: 1Last Post: 11-01-2010, 08:27 PM -
Storing data?
By Syntax in forum New To JavaReplies: 4Last Post: 01-23-2010, 01:17 AM -
Storing Data
By Khorod in forum New To JavaReplies: 1Last Post: 08-03-2007, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks