i need help writing a program using array. ASAP!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 42

Thread: i need help writing a program using array. ASAP!

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    i need help writing a program using array. ASAP!

    Write a Java application that does the following:
     Reads an integer from the user represents the number of the students in a class.
     Reads the scores of the students from the user and store them in an array.
     Calculates and prints the percentage of the excellent students in the class rounded
    to 1 decimal place.

    please i am new at programming and have to submit this assignment by tomorrow.. so can how how to write.. coz the way i am using it keeps messing up at the declaring Array time

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: i need help writing a program using array. ASAP!

    Show what you have done and we can guide you in correcting it but we won't write it for you.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Dec 2012
    Posts
    21

    Re: i need help writing a program using array. ASAP!

    this what i have so far.. i just started java this semester so i bet its full of mistakes.

    import java.util.Scanner;
    public class Q7_A_112532 {
    public static void main(System[] args){
    Scanner input = new Scanner(System.in);
    int num = 0;
    int excellentstudent;
    excellentstudent = 0;
    double percentage = 0;

    System.out.print("enter the total number of students: ");
    num = input.nextInt();

    int[] studentarray;
    studentarray = new.int[num];
    {for (i = 0; i < studentarray.lenght, i++ )
    sum = sum + arr[num]
    }
    if (grade >= 90 )
    gradecount ++;

    percentage = count * 100 / num

    System.out.printf("The percentage f excellent student is : %.1f", + percentage);


    }

    }

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: i need help writing a program using array. ASAP!

    so i bet its full of mistakes.
    So have you tried compiling it to see what compile time mistakes you have?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    Join Date
    Dec 2012
    Posts
    21

    Re: i need help writing a program using array. ASAP!

    should i copy paste em here?

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: i need help writing a program using array. ASAP!

    Only if you can't fix them yourself
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  7. #7
    Join Date
    Dec 2012
    Posts
    21

    Re: i need help writing a program using array. ASAP!

    i used netbeans to compile it.... and this is all the errors it shows.

    ant -f "C:\\Users\\Al Doctor\\Documents\\NetBeansProjects\\HafsaShahab_112532" clean jar
    init:
    deps-clean:
    Updating property file: C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\build\built-clean.properties
    Deleting directory C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\build
    clean:
    init:
    deps-jar:
    Created dir: C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\build
    Updating property file: C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\build\built-jar.properties
    Created dir: C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\build\classes
    Created dir: C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\build\empty
    Created dir: C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\build\generated-sources\ap-source-output
    Compiling 7 source files to C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\build\classes
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:23: error: <identifier> expected
    studentarray = new.int[num];
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:23: error: <identifier> expected
    studentarray = new.int[num];
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:24: error: ';' expected
    {for (i = 0; i < studentarray.lenght, i++ )
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:24: error: ')' expected
    {for (i = 0; i < studentarray.lenght, i++ )
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:24: error: illegal start of expression
    {for (i = 0; i < studentarray.lenght, i++ )
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:25: error: ';' expected
    sum = sum + arr[num]
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:30: error: ';' expected
    percentage = count * 100 / num
    7 errors
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\nbproject\build-impl.xml:915: The following error occurred while executing this line:
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\nbproject\build-impl.xml:268: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)

  8. #8
    Join Date
    Dec 2012
    Posts
    21

    Re: i need help writing a program using array. ASAP!

    yup i can fix em... because there are so many dont know where to start from

  9. #9
    Join Date
    Dec 2012
    Posts
    21

    Re: i need help writing a program using array. ASAP!

    i can't fix them*

  10. #10
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: i need help writing a program using array. ASAP!

    Read the error messages carefully they tell the line number the problem is on (and show you the line) and tell you what is wrong. For instance:

    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:25: error: ';' expected
    sum = sum + arr[num]
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:30: error: ';' expected
    percentage = count * 100 / num
    Look at these two lines and the error message which says ';' is expected. What do statements in Java have to end with?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  11. #11
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: i need help writing a program using array. ASAP!

    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:24: error: ';' expected
    {for (i = 0; i < studentarray.lenght, i++ )
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:24: error: ')' expected
    {for (i = 0; i < studentarray.lenght, i++ )
    These two are a bit more difficult as the compiler is confused. The line has two problems the first being the compiler doesn't know what type 'i' is as you haven't declared it anywhere and secondly it is confused by '.lenght' - check the spelling.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  12. #12
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: i need help writing a program using array. ASAP!

    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:23: error: <identifier> expected
    studentarray = new.int[num];
    C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:23: error: <identifier> expected
    studentarray = new.int[num];
    These messages aren't too obvious but mean you haven't declared the type of a variable. There is also a more difficult error on this line which is here 'new.int' - there shouldn't be a '.' in there
    Last edited by keang; December 18th, 2012 at 01:02 PM.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  13. #13
    Join Date
    Dec 2012
    Posts
    21

    Re: i need help writing a program using array. ASAP!

    okay i get that part... but now its not even running.... it says that it doesn't have a main method. Could you do me the biggest favor and go through the code once... and tell me if u think what i am trying to do is right or not.... you see the thing is i srudy in an arab country where majority of my class speaks Arabic... so our professor is compelled to speak Arabic most of the time... and that is how i miss those small points that make these programs work.

  14. #14
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: i need help writing a program using array. ASAP!

    okay i get that part... but now its not even running
    It can't have been running before, it wouldn't compile.
    Post your latest code with all these fixes in place - please use code tags when posting code.

    Your code is on the right lines - you are missing the bit where you ask the user of each of the scores but the rest looks basically correct.
    What are grade and gradeCount for - they are not part of the question you posted.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  15. #15
    Join Date
    Dec 2012
    Posts
    21

    Re: i need help writing a program using array. ASAP!

    um i thought u would need to calculate the percentage of excellent students... thats why... u think i should remove that part?

Page 1 of 3 123 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center