Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Hi can any have a look at my code and see how I am going wrong with my array list out put,the mark is not outputing

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hi can any have a look at my code and see how I am going wrong with my array list out put,the mark is not outputing

     
    import java.util.ArrayList;
    import java.util.*;
     
    public class LabArray {
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
     
    		ArrayList<String> firstname = new ArrayList<String>();
    		ArrayList<String> surname = new ArrayList<String>();
    		ArrayList<Integer> Grade = new ArrayList<Integer>();
    		String fname;
    		String sname;
    		int grade;
     
     
     
    		Scanner kb  = new Scanner(System.in);
     
    		for (int i=0; i < 20; i++){
     
    		fname = kb.nextLine();
    		firstname.add(fname);
     
    		sname = kb.nextLine();
    		surname.add(sname);
     
    		grade = kb.nextInt();
    		Grade.add(grade);
     
    		System.out.println(firstname.get(i) + " " + surname.get(i) + " " + Grade.get(i));
     
    		}
     
     
    		for (int j = 0;  j < 20;  j++){
     
    			grade = kb.nextInt();
    			Grade.add(grade);
     
    			if( grade >= 85 && grade <= 100 )
    					{
     
    					    System.out.println( "Distinction" );
    					}
    					else
    					    if( grade >= 65 && grade < 84 )
    					    {
     
    					         System.out.println( "Merit" );
    					    }
    					else
    					    if( grade >= 39 && grade < 65 )
    					    {
     
    					         System.out.println( "Pass" );
    					    }
    					else
    					     if( grade >= 39 && grade < 0 )
    					     {
     
    					          System.out.println( "fail" );
    					     }
     
    			System.out.println(firstname.get(j) + " " + surname.get(j) + " " +Grade.get(j));
     
    		}
    		}
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Hi can any have a look at my code and see how I am going wrong with my array list out put,the mark is not outputing

    Can you post the console for when you execute the code that shows what the problem is?
    Add some comments saying what is wrong.
      if( grade >= 39 && grade < 0 )
    for what value of grade will that be true?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hi can any have a look at my code and see how I am going wrong with my array list out put,the mark is not outputing

    Hi The code wont give firstname surname grade all on 1 line,example Joe Blogs recieved a grade of 40 Pass.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Hi can any have a look at my code and see how I am going wrong with my array list out put,the mark is not outputing

    code wont give firstname surname grade all on 1 line
    If the String you are printing has a newline character in it, the characters in the String following the newline character will go on the next line.
    If you want all the printed Strings to go on the same line, make sure there is not a newline character in any of the Strings being printed.

    The println() method adds a newline character at the end of the String that it prints.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hi can any have a look at my code and see how I am going wrong with my array list out put,the mark is not outputing

    Ya will take the input from the keyboard but the second for loop wont return the fname surname and the grade.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Hi can any have a look at my code and see how I am going wrong with my array list out put,the mark is not outputing

    the second for loop wont
    Please copy the full contents of the console that shows what you are talking about. I see lots of calls to:
    System.out.println() in the second for loop. Which ones are printing and which ones are not printing?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. where to put list of objects method OOP
    By stanlj in forum Object Oriented Programming
    Replies: 3
    Last Post: January 14th, 2013, 02:08 PM
  2. How to put my code onto the window.
    By Shzylo in forum Java Theory & Questions
    Replies: 1
    Last Post: December 18th, 2012, 09:34 PM
  3. where to put the nodes into the array?
    By blaster in forum Algorithms & Recursion
    Replies: 9
    Last Post: March 11th, 2012, 07:03 PM
  4. How Can i put mysql query results into Linked List.
    By Muhanguzi in forum JDBC & Databases
    Replies: 1
    Last Post: June 18th, 2011, 11:03 AM
  5. Beginner question on where to put an array
    By Diplo in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 3rd, 2011, 03:56 PM