Results 1 to 7 of 7
  1. #1
    Bastor is offline Member
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Need quite a bit of help with a program for Storing and Working with data

    Quote Originally Posted by Bastor View Post
    Anyway I've got this little "assignment" from a buddy of mine helping me start Java
    Ah, homework.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: Need quite a bit of help with a program for Storing and Working with data

    I tried using an arrayList but I can't get the getters and setters to work.
    Please post the code that shows the problem.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Bastor is offline Member
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

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

    Java Code:
    	public void addName(String names) {
    		this.names.add(names);
    	}
    And in the main:

    Java Code:
    student.addName(readLine());
    The second one is Line 33 in my Main

    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.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

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

  6. #6
    Amok is offline Member
    Join Date
    Sep 2012
    Location
    Australia
    Posts
    12
    Rep Power
    0

    Default 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

    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);
    }
    This is just a template. create Student object inside a loop and store into ArrayList.
    Hope this will help.

  7. #7
    Bastor is offline Member
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Default Re: Need quite a bit of help with a program for Storing and Working with data

    Thank you Amok I'll try this solution during lunch, see how it turns up and follow up.

Similar Threads

  1. Need Help with storing and displaying data
    By Mitho in forum New To Java
    Replies: 5
    Last Post: 04-11-2012, 12:20 AM
  2. storing data in queues
    By javanut123 in forum New To Java
    Replies: 1
    Last Post: 12-04-2011, 09:10 PM
  3. Storing local data?
    By DennisMadsen in forum Advanced Java
    Replies: 1
    Last Post: 11-01-2010, 09:27 PM
  4. Storing data?
    By Syntax in forum New To Java
    Replies: 4
    Last Post: 01-23-2010, 02:17 AM
  5. Storing Data
    By Khorod in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •