-
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
-
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.
-
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);
}
}
-
Re: i need help writing a program using array. ASAP!
Quote:
so i bet its full of mistakes.
So have you tried compiling it to see what compile time mistakes you have?
-
Re: i need help writing a program using array. ASAP!
should i copy paste em here?
-
Re: i need help writing a program using array. ASAP!
Only if you can't fix them yourself
-
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)
-
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
-
Re: i need help writing a program using array. ASAP!
-
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:
Quote:
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?
-
Re: i need help writing a program using array. ASAP!
Quote:
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.
-
Re: i need help writing a program using array. ASAP!
Quote:
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
-
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.
-
Re: i need help writing a program using array. ASAP!
Quote:
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.
-
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?
-
Re: i need help writing a program using array. ASAP!
okY so i got the errors down to 5.. here the new code so far... i forgot to give a option for the user to enter grade..
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;
int grade;
System.out.print("enter the total number of students: ");
num = input.nextInt();
int i;
int studentarray;
studentarray = new.int[num];
{for (i = 0; i < studentarray.length, i++ )};
sum = sum + arr[num];
System.out.print("Enter the grade of the student: ");
grade = input.nextInt();
if (grade >= 90 )
gradecount ++;
percentage = count * 100 / num;
System.out.printf("The percentage f excellent student is : %.1f", + percentage);
}
}
-
Re: i need help writing a program using array. ASAP!
Quote:
um i thought u would need to calculate the percentage of excellent students... thats why... u think i should remove that part?
But you aren't using it anywhere. But I wouldn't worry about that at the moment, the first thing is to get your code compiling.
-
Re: i need help writing a program using array. ASAP!
Please use code tags when posting code.
Format your code properly so the curly braces and indents are all consistently aligned, this will help highlight at least one problem.
If I have to keep asking you to post error message etc this will take all night and I don't have all night. If there are 5 errors, post the messages.
-
Re: i need help writing a program using array. ASAP!
okay i got all the errors i could fixed... but still have four left!
C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:25: error: <identifier> expected
studentarray = new.int[num];
C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:25: error: <identifier> expected
studentarray = new.int[num];
C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:26: error: illegal start of expression
{for (i = 0; i < studentarray.length; i++ )};
C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:42: error: reached end of file while parsing
}
4 errors
i am so sorry for bothering you.... but at the current moment u are the only help i have!
-
Re: i need help writing a program using array. ASAP!
Quote:
i am so sorry for bothering you..
Don't worry, I'm just concerned we don't have enough time.
The first two errors I have already explained in an earlier post.
The 3rd error is because the for statement shouldn't be wrapped in curly braces
The 4th is because you probably don't have the same number of opening and closing curly braces hence my earlier comment about formatting your code properly.
-
Re: i need help writing a program using array. ASAP!
i think the atempt of fixing the last four errors i have messed it all up all over...i bet u might be thinking i am like a crazy person or something.... but i think its slowly getting over m,y head.... now i think i am screwed it big time... coz in the middle i was working on another program... which was fine... but now donno what to do!
am, trying to get back to where it was..
-
Re: i need help writing a program using array. ASAP!
okay wait i think i got everything back.. lemme work on ur suggestion and i will get back to you
-
Re: i need help writing a program using array. ASAP!
Fixing one error can often make more errors appear, it doesn't necessarily mean you done something wrong.
-
Re: i need help writing a program using array. ASAP!
yeah never thought of that..am gonna keep that in mind... okay so am down to 3 errors..:D
-
Re: i need help writing a program using array. ASAP!
okay so i removed the curly brace from one of em... but there is a new error in it..
C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:26: error: <identifier> expected
studentarray = new.int[num];
C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:26: error: <identifier> expected
studentarray = new.int[num];
C:\Users\Al Doctor\Documents\NetBeansProjects\HafsaShahab_112532\src\Q7_A_112532.java:48: error: class, interface, or enum expected
}
3 errors
-
Re: i need help writing a program using array. ASAP!
okay so got ride of the last error... but the other two are still pending... can re-explain what i have to do to fix it.
-
Re: i need help writing a program using array. ASAP!
Without seeing the current code it's hard to say exactly but you certainly shouldn't have a '.' in 'new.int' and you probably haven't declared studentarray
-
Re: i need help writing a program using array. ASAP!
import java.util.Scanner;
public class Q5_112532 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int integer;
System.out.print("Enter an integer less then 2147483648: ");
integer = input.nextInt();
int sum = 0;
while (integer != 0){
sum += integer % 10;
integer /= 10;
}
System.out.print("the sum of digits of integers is ");
if (sum % 2 == 0){
System.out.println("even!");
}
else
{
System.out.println("odd!");
}
}
}
SO THIS WHAT I HAVE GOTTEN AFTER ALL THAT!!
-
Re: i need help writing a program using array. ASAP!
WOOPS DORRY WRONG PROGRAM!!
import java.util.Scanner;
public class Q7_A_112532 {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int num = 0;
double percentage = 0;
int grade;
System.out.print("Enter the number of students");
num = input.nextInt();
int sum;
int studentarray;
studentarray = new.int[num];
for (num = o; num < studentarray.length; num ++);
sum = sum + arr[num];
System.out.print("enter the grade of the student: ");
grade = input.nextInt();
if ( grade >= 90)
gradecount ++;
percentage = gradecount * 100 / num;
System.out.printf("The percentage of excelent students: %.1f", +percentage);
}
}
-
Re: i need help writing a program using array. ASAP!
What about error messages and you still have a '.' in 'new.int'
-
Re: i need help writing a program using array. ASAP!
yup both the errors are at that place!
-
Re: i need help writing a program using array. ASAP!
i dont mean to be a pain.. but there is very less time left to submit my assignment..
-
Re: i need help writing a program using array. ASAP!
And you're still not using code tags. Please do so, it makes the code much easier to read.
-
Re: i need help writing a program using array. ASAP!
Quote:
i dont mean to be a pain.. but there is very less time left to submit my assignment
Unfortunately that's not my problem.
If you did what I have suggested you do without me having to repeat myself and having to keep asking for error messages and the latest code you would be a lot closer to finishing.
-
Re: i need help writing a program using array. ASAP!
i am sorry but i am unfamiliar with code tags... how do i use them here?
-
Re: i need help writing a program using array. ASAP!
i am so sorry i did in no way mean to offend you.... it just my first time doing this... and my nerves are getting the best of me!! but srsly thank you for being so patient with me! u have been nothing short of great help!
-
Re: i need help writing a program using array. ASAP!
At the bottom of every one of my post in blue writing it shows to use them. You can either type them in or highlight your code and click on the code tags button ('#').
-
Re: i need help writing a program using array. ASAP!
okay thank you so much for sticking with me all through this....i think this will be all now... wish me lcuk for my assignement....and i wish u the best luck!! hope i was'nt to much of a nuisance!
-
Re: i need help writing a program using array. ASAP!
I definitely wish you luck. Do you have it working now?
-
Re: i need help writing a program using array. ASAP!
[code]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class MyHomework {
public static void main(String[] args){
int num = 0;
int excellentstudent;
excellentstudent = 0;
double percentage = 0;
Scanner scanner = new Scanner(System.in);
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
String s = scanner.nextLine(); // bufferRead.readLine();
System.out.println(s);
num = scanner.nextInt();
int[] studentarray;
studentarray = new int[num];
int sum = 0;
for (int i = 0; i < studentarray.length; i++ ){
sum = sum + studentarray[num];
}
int gradecount = 0;
if (sum >= 90 ){
gradecount ++;
//Sorry i dont understand this
percentage = count * 100 / num;
System.out.printf("The percentage f excellent student is : %.1f", + percentage);
}
}
[code]
-
Re: i need help writing a program using array. ASAP!
Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class MyHomework {
public static void main(String[] args){
int num = 0;
int excellentstudent;
excellentstudent = 0;
double percentage = 0;
Scanner scanner = new Scanner(System.in);
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
String s = scanner.nextLine(); // bufferRead.readLine();
System.out.println(s);
num = scanner.nextInt();
int[] studentarray;
studentarray = new int[num];
int sum = 0;
for (int i = 0; i < studentarray.length; i++ ){
sum = sum + studentarray[num];
}
int gradecount = 0;
if (sum >= 90 ){
gradecount ++;
//Sorry i dont understand this
percentage = count * 100 / num;
System.out.printf("The percentage f excellent student is : %.1f", + percentage);
}
}
-
Re: i need help writing a program using array. ASAP!
Sorry for triple post. Anyway that is the program, after i fixed error. Just ask if you dont under stand. I think you need to read more books because you need to know how to make a "function"(or called "method" in java) and "declare variable".