Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Need help with a java project

Options
  • 22-04-2015 2:41pm
    #1
    Closed Accounts Posts: 431 ✭✭


    So i'm writing a program that takes student grades and does calculations on them then print the results to the screen. My problem is i'm using an array to store the values and i'm having trouble taking array values and storing them as int's so i can do the calculations. If you could help me with that i would be very grateful. Here's the code.
    package gradesaverage;//Package name
    import java.util.Scanner;//imports scanner
    import java.util.Arrays;
    /**
     *
     * 
     */
    public class GradesAverage {
        
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {//Main method
            // TODO code application logic here
            NoOfStudents();//Runs method code
            
            Scanner in = new Scanner(System.in);//Declares scanner
            int students = in.nextInt();//Take user input
            int[] arrayGrades = new int[students];//Creates array
            int i = 0;//Value for loop
            int s = 0;//Student number grade
            
            
            for(i=0; i < arrayGrades.length; i++)//For loop
            {
            s++;//Increments student number
            System.out.print("Enter number " + s + " student grade : ");//Prints to the console
            int grade = in.nextInt();//Takes user input and saves in grade
            arrayGrades[i] = grade;//Takes input from grades into the array
            //System.out.println(Arrays.toString(arrayGrades));
            }
            int l;
            for(l=0; l < arrayGrades.length; l++){
            System.out.println(arrayGrades[l]);
                int a = in.nextInt();
      
            System.out.println(arrayGrades[l]);
                int b = in.nextInt();
            System.out.println(b);
            
            
            }
           
            
            
            Average();
            Max();
            Min();
            PassFail();
                
        }
        public static void NoOfStudents(){//NoOfStudents method
            System.out.print("Enter the total number of students: ");
            //This is a method
        }
        
        public static void Average(){
            int average;
            //This is a method
        }
        public static void Max(){
            System.out.println("");
            //This is a method
        }
        public static void Min(){
            System.out.println("");
            //This is a method
        }
        public static void PassFail(){
            System.out.println("");
            //This is a method
        }
    }    
    
    
    


Comments

  • Closed Accounts Posts: 431 ✭✭whats newxt


    I'm not asking for you to do the project for me just need help with the syntax.
    Come on internet i believe in you.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    The Internet does not reciprocate the feeling.


  • Closed Accounts Posts: 431 ✭✭whats newxt


    How do i call a last int with scanner?


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Why are you using a scanner? Is it a requirement for your assignment?


  • Closed Accounts Posts: 431 ✭✭whats newxt


    Why are you using a scanner? Is it a requirement for your assignment?

    Yes and arrays and methods. Do you have any idea? the problem is i have to enter a number and hit enter for it to move to the next int. Anyway to bypass this?

    This is the problem:
    int l;
            for(l=0; l < arrayGrades.length; l++)
            {
                
            System.out.print(arrayGrades[0]);
                int a = in.nextInt();
      
                int b = arrayGrades[1];
            System.out.println(b);
            
            
            
            }
    


  • Advertisement
  • Registered Users Posts: 200 ✭✭druidhill


    You should define the initial problem/requirement(s) more clearly so people understand what you want to do and also any outputs (errors, debug outputs you have done). You might get more responses.


  • Closed Accounts Posts: 431 ✭✭whats newxt


    It's ok i got it to work, thanks for giving me faith. Here's the code:
    for(i=0; i < arrayGrades.length; i++)//For loop
            {
                
            s++;//Increments student number
            System.out.print("Enter number " + s + " student grade : ");//Prints to the console
            int grade = in.nextInt();//Takes user input and saves in grade
            arrayGrades[i] = grade;//Takes input from grades into the array
            //System.out.println(Arrays.toString(arrayGrades));
            
            }
            
            int l;
            for(l=0; l < arrayGrades.length; l++)
            {
              
            int a = arrayGrades[0];    
            System.out.println(arrayGrades[0]);
            l++ ;
                
            System.out.println(arrayGrades[1]);
            l++ ;   
            System.out.println(a);
          
            }
    


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    It's ok i got it to work, thanks for giving me faith.
    No one did anything other than yourself. Chances are you just needed to walk away from the problem for a bit then return to it and the answer would present itself - often works that way.

    And druidhill was correct; your initial query was not clear - you asked about getting values from an array, when it turned out what you needed to know is how to use the Scanner object.

    More experienced developers will scan over these threads and one that clearly states the problem will always get answered more quickly (or at all). If all you supply is a fuzzy description and a code dump, that same developer will likely take one look, go "can't be arsed to decipher, or play 20 questions with him/her to find out, what the actual problem is" and move on.


Advertisement