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

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2004
Posts: 16
Reputation: shantuli is an unknown quantity at this point 
Solved Threads: 0
shantuli shantuli is offline Offline
Newbie Poster

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

 
0
  #1
Jul 25th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,056
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 129
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

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

 
0
  #2
Jul 25th, 2004
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.

  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
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 9
Reputation: bobinson is an unknown quantity at this point 
Solved Threads: 0
bobinson bobinson is offline Offline
Newbie Poster

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

 
0
  #3
Aug 4th, 2004
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");
}

}
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 117
Reputation: Iron_Cross is an unknown quantity at this point 
Solved Threads: 2
Iron_Cross's Avatar
Iron_Cross Iron_Cross is offline Offline
Junior Poster

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

 
0
  #4
Aug 4th, 2004
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)
elitehackers.info
Today's Penny-Arcade!
Pain is weakness leaving the body!
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 19
Reputation: saadismail85 is an unknown quantity at this point 
Solved Threads: 0
saadismail85 saadismail85 is offline Offline
Newbie Poster
 
0
  #5
Nov 12th, 2009
  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)
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,713
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 229
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #6
Nov 12th, 2009
saadismail85 please use code tags and/or start a new thread.
For code tags click the button: [code] when you write your post
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 19
Reputation: saadismail85 is an unknown quantity at this point 
Solved Threads: 0
saadismail85 saadismail85 is offline Offline
Newbie Poster
 
0
  #7
34 Days Ago
Originally Posted by javaAddict View Post
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 :-)
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,713
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 229
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #8
34 Days Ago
Here:

Originally Posted by javaAddict View Post
For code tags click the button: [code] when you write your post
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,249
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 492
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer
 
-1
  #9
34 Days Ago
Originally Posted by saadismail85 View Post
mmmmm tell me how cuz am new user here :-)
[code=java]your code here[/code]
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,857
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso
 
0
  #10
34 Days Ago
  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; 34 Days Ago at 7:50 am.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC