943,917 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 24570
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 25th, 2004
-1

calculate the grades for a student using if..else statements.

Expand Post »
hi everyone,
i am very new in java. can anyone help me to solve the following problem:

A school conducts a 100 mark exam for its student and grades them as follows:
Grade:
Grade A: Marks>75
Grade B: 75>Marks>60
Grade C: 60>Marks>50
Grade D: 50>Marks>40

Write ajava program to calculate the grades for a student, using if..else statement. use some given value to test the code.

thank you,
regards,
shantuli
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shantuli is offline Offline
16 posts
since Jul 2004
Jul 25th, 2004
0

Re: calculate the grades for a student using if..else statements.

I'm in a very giving mood today Usually I don't just give the answer to homework problems outright like I am now. I'd rather see some effort put in on your end. So consider yourself very lucky. The following is the pseudocode for the program. Think about what each line means, and then translate it into Java syntax line by line.

Java Syntax (Toggle Plain Text)
  1. input student's grade
  2. if grade < 100 AND grade > 75 { student got an A }
  3. else if grade < 75 AND grade > 60 { student got a B }
  4. else if grade < 60 AND grade > 50 { student got a C }
  5. else if grade < 50 AND grade > 40 { student got a D }
  6. else { student got an F } // didn't fit into any of the above scenerios, so must be an F
  7. print to screen what the student got
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Aug 4th, 2004
0

Re: calculate the grades for a student using if..else statements.

Hi shantuli,why not try this code as well.Have a lovely day.
Bobinson.



class Testy
{
byte score;


Testy()
{
score=78;
}


public static void main(String arg[])

{
Testy tst=new Testy();
tst.processGrades();
}

public void processGrades()
{


if
(score >=75)
{
System.out.println("Your grade is A");
}
else
if
((score >= 60)&&( score <75 ))
{
System.out.println("Your grade is B");
}
if
((score >=50 )&&(score<60))
{
System.out.println("Your grade is C");
}
else
if
((score >=40 )&&(score <50))
{
System.out.println(" Your grade is D");
}
else
if
(score <40 )
{
System.out.println(" Sorry you have no part here,FAILED");
}

}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bobinson is offline Offline
9 posts
since Jul 2004
Aug 4th, 2004
0

Re: calculate the grades for a student using if..else statements.

Dude, 2 things.
1. Put your code into the [*code] and [/code] tags (remove the * though)
2. Don't just give him the answer to his homework, what good will that do him. You can help him and give him clues, but don't just do it for him. Also, your code seems overly complicated and there is no room for adjustment (i.e. the grade is always 78)
Reputation Points: 46
Solved Threads: 2
Junior Poster
Iron_Cross is offline Offline
117 posts
since Jul 2003
Nov 12th, 2009
0
Re: calculate the grades for a student using if..else statements.
java Syntax (Toggle Plain Text)
  1. import java.util.Scanner;
  2.  
  3. public class CaseGrade {
  4.  
  5. public static void main(String[] args) {
  6. Scanner input = new Scanner (System.in);
  7. String name ;
  8. int grade;
  9. String exellent = "Exellent :";
  10. String veryGgood ="Very Good :";
  11. String good="Good :";
  12. String pass ="Pass :";
  13. String fail = "Fail :";
  14.  
  15. int max = 0;
  16. int min = 100;
  17. int sum = 0;
  18. int avg ;
  19. int counter =0;
  20.  
  21. boolean repeat ;
  22. while (repeat =true)
  23. {
  24. System.out.println("Enter Name : ");
  25. name = input.next();
  26. System.out.println("Enter Grade : ");
  27. grade = input.nextInt();
  28.  
  29. if (grade == -1 )
  30. {
  31. avg = sum / counter;
  32. System.out.println(" result = :");
  33. System.out.println(exellent +"\n"+ veryGgood +"\n"+ good +"\n"+ pass +"\n"+fail);
  34. System.out.println("maximum = "+ max +"\t");
  35. System.out.println("minimum = "+ min +"\t");
  36. System.out.println("\tAverage = " +avg);
  37. System.exit(0);
  38. }
  39.  
  40.  
  41.  
  42. switch (grade/10)
  43. {
  44. case 100:
  45. case 9 :
  46. exellent += "\n"+ name + "\t" +grade+"\n";
  47.  
  48. break;
  49. case 8 :
  50. veryGgood += "\n" + name + "\t" +grade +"\n";
  51.  
  52. break ;
  53.  
  54. case 7 :
  55. good += "\n" + name + "\t" +grade +"\n";
  56.  
  57. break;
  58. case 6:
  59. case 5:
  60. pass += "\n" + name + "\t" +grade +"\n";
  61. break;
  62.  
  63. default:
  64. fail +="\n" + name + "\t" +grade +"\n";
  65. break;
  66.  
  67. }
  68.  
  69. sum = sum + grade;
  70. counter = counter + 1;
  71.  
  72. if (grade > max)
  73. {
  74. max = grade;
  75. }
  76. if (grade < min)
  77. {
  78. min = grade;
  79. }
  80.  
  81. }
  82. }
  83.  
  84. }
Last edited by peter_budo; Nov 12th, 2009 at 8:48 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saadismail85 is offline Offline
19 posts
since Nov 2009
Nov 12th, 2009
0
Re: calculate the grades for a student using if..else statements.
saadismail85 please use code tags and/or start a new thread.
For code tags click the button: [code] when you write your post
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,259 posts
since Dec 2007
Nov 15th, 2009
0
Re: calculate the grades for a student using if..else statements.
Click to Expand / Collapse  Quote originally posted by javaAddict ...
saadismail85 please use code tags and/or start a new thread.
For code tags click the button: [code] when you write your post
mmmmm tell me how cuz am new user here :-)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saadismail85 is offline Offline
19 posts
since Nov 2009
Nov 15th, 2009
0
Re: calculate the grades for a student using if..else statements.
Here:

Click to Expand / Collapse  Quote originally posted by javaAddict ...
For code tags click the button: [code] when you write your post
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,259 posts
since Dec 2007
Nov 15th, 2009
1
Re: calculate the grades for a student using if..else statements.
mmmmm tell me how cuz am new user here :-)
[code=java]your code here[/code]
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Nov 15th, 2009
0
Re: calculate the grades for a student using if..else statements.
Java Syntax (Toggle Plain Text)
  1. while (repeat =true)
Do you really want an infinite loop ? if yes you can use while(true) , not a good coding practice I would say.
Last edited by ithelp; Nov 15th, 2009 at 7:50 am.
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Unknown problem sorting an ArrayList.
Next Thread in Java Forum Timeline: Array of objects





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC