1,105,384 Community Members

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

Member Avatar
shantuli
Newbie Poster
16 posts since Jul 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-2
 

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

Member Avatar
Dani
The Queen of DaniWeb
20,565 posts since Feb 2002
Reputation Points: 1,356 [?]
Q&As Helped to Solve: 931 [?]
Skill Endorsements: 204 [?]
Administrator
Featured
Sponsor
 
0
 

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.

input student's grade
if grade < 100 AND grade > 75 { student got an A }
else if grade < 75 AND grade > 60 { student got a B }
else if grade < 60 AND grade > 50 { student got a C }
else if grade < 50 AND grade > 40 { student got a D }
else { student got an F } // didn't fit into any of the above scenerios, so must be an F
print to screen what the student got
Member Avatar
bobinson
Newbie Poster
9 posts since Jul 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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");
}

}
}

Member Avatar
Iron_Cross
Junior Poster
117 posts since Jul 2003
Reputation Points: 32 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 5 [?]
 
0
 

Dude, 2 things.
1. Put your code into the code tags
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)

Member Avatar
saadismail85
Newbie Poster
19 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
import java.util.Scanner;

public class CaseGrade {

	public static void main(String[] args) {
		Scanner input =  new Scanner (System.in);
		String name ;
		int grade;
		String exellent = "Exellent :";
		String veryGgood ="Very Good :";
		String good="Good :";
		String pass ="Pass :";
		String fail = "Fail :";
	
		int max = 0;
		int min = 100;
		int sum = 0;
		int avg ;
		int counter =0;
		
		boolean repeat ;
		while (repeat =true)
		{
			System.out.println("Enter Name : ");
			name =  input.next();
			System.out.println("Enter Grade : ");
			grade = input.nextInt();
			
			if (grade == -1 )
			{
				avg = sum / counter;
				System.out.println(" result = :");
				System.out.println(exellent +"\n"+ veryGgood +"\n"+ good +"\n"+ pass +"\n"+fail);
				System.out.println("maximum = "+ max +"\t");
				System.out.println("minimum = "+ min +"\t");
				System.out.println("\tAverage = " +avg);
				System.exit(0);
			}
			
			
			
			switch (grade/10)
			{
			case 100:
			case 9 :
				exellent += "\n"+ name + "\t" +grade+"\n";
			
				break;
			case 8 :
				veryGgood += "\n" + name + "\t" +grade +"\n";
			
				break ;
			
			case 7 :
				good += "\n" + name + "\t" +grade +"\n";
				
				break;
			case 6:
			case 5:
				pass += "\n" + name + "\t" +grade +"\n";
				break;

				default:
				fail +="\n" + name + "\t" +grade +"\n";
				break;

			}
			
			sum = sum + grade;
			counter = counter + 1;
		
			if (grade > max) 
			{
				max = grade;
			}
			if (grade < min)
			{
				min = grade;
			}
	
		}
	}

}
Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 

saadismail85 please use code tags and/or start a new thread.
For code tags click the button: (code) when you write your post

Member Avatar
saadismail85
Newbie Poster
19 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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 :-)

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 

Here:

For code tags click the button: (code) when you write your post

Member Avatar
peter_budo
Code tags enforcer
7,935 posts since Dec 2004
Reputation Points: 2,502 [?]
Q&As Helped to Solve: 1,028 [?]
Skill Endorsements: 66 [?]
Moderator
Featured
 
1
 

mmmmm tell me how cuz am new user here :-)

[code=java]your code here [/code]

ithelp
Posting Virtuoso
1,910 posts since May 2006
Reputation Points: 757 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 19 [?]
Banned
 
0
 
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.

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 
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.

I believe it would be better to let him start a new thread, before responding to any questions.

Thanks

Member Avatar
kempka15
Newbie Poster
1 post since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi if i need help can someone help me here?i am a student of computer science but im not good in programming T_T

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 

hi if i need help can someone help me here?i am a student of computer science but im not good in programming T_T

Start a new thread with your question

Member Avatar
Transcendent
Junior Poster
104 posts since Oct 2010
Reputation Points: -5 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
-1
 

Java How to Program cover this. you should check the book out.

Member Avatar
afwer
Newbie Poster
1 post since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

//There are ten students in class. Each student has taken five tests, and each test is worth 100 points. The grade is assigned as follows: if the average test score is greater than or equal to 90, the grade is A; if the average test score is greater than or equal to 80 and less than 90, the grade is B; if the average test score is greater than or equal to 70 and less than, the grade is C; if the average test score is greater than or equal to 60 and less than 70, the grade is D; otherwise, the grade is F. Note that the data consists of student's names and their test scores.Create a java program that will solve the problem.

package grade;

import javax.swing.*;
public class Grade
{
    private static String outputStr;
    public static void main(String[]args)
    {
        int test1,test2,test3,test4,test5,a,b,c,d,e,t,w,x,y,z;
        double average1,average2,average3;
        char A,B,C,D,F,Grade1,Grade2,Grade3;
        String student1Str,student2Str,student3Str,test1Str,test2Str,test3Str,test4Str,test5Str,aStr,bStr,cStr,dStr,eStr,tStr,wStr,xStr,yStr,zStr;

        {
        student1Str=JOptionPane.showInputDialog("Enter first student's name: ");
        student2Str=JOptionPane.showInputDialog("Enter second student's name: ");
        student3Str=JOptionPane.showInputDialog("Enter third student's name: ");
        test1Str=JOptionPane.showInputDialog("Enter the first score of the first student: ");
        test1=Integer.parseInt(test1Str);
        test2Str=JOptionPane.showInputDialog("Enter the second score of the first student: ");
        test2=Integer.parseInt(test2Str);
        test3Str=JOptionPane.showInputDialog("Enter the third score of the first student: ");
        test3=Integer.parseInt(test3Str);
        test4Str=JOptionPane.showInputDialog("Enter the fourth score of the first student: ");
        test4=Integer.parseInt(test4Str);
        test5Str=JOptionPane.showInputDialog("Enter the fifth score of the first student: ");
        test5=Integer.parseInt(test5Str);
        average1=(test1+test2+test3+test4+test5)/5;
        {
        if(average1>=90)
            Grade1='A';
        else if(average1>=80)
            Grade1='B';
        else if(average1>=70)
            Grade1='C';
        else if(average1>=60)
            Grade1='D';
        else
            Grade1='F';
        }


        }
        {
        aStr=JOptionPane.showInputDialog("Enter the first score of the second student: ");
        a=Integer.parseInt(aStr);
        bStr=JOptionPane.showInputDialog("Enter the second score of the second student: ");
        b=Integer.parseInt(bStr);
        cStr=JOptionPane.showInputDialog("Enter the third score of the second student: ");
        c=Integer.parseInt(cStr);
        dStr=JOptionPane.showInputDialog("Enter the fourth score of the second student: ");
        d=Integer.parseInt(dStr);
        eStr=JOptionPane.showInputDialog("Enter the fifth score of the second student: ");
        e=Integer.parseInt(eStr);
        average2=(a+b+c+d+e)/5;
        {
        if(average2>=90)
            Grade2='A';
        else if(average2>=80)
            Grade2='B';
        else if(average2>=70)
            Grade2='C';
        else if(average2>=60)
            Grade2='D';
        else
            Grade2='F';
        }
        }
        {
        tStr=JOptionPane.showInputDialog("Enter the first score of the second student: ");
        t=Integer.parseInt(tStr);
        wStr=JOptionPane.showInputDialog("Enter the second score of the second student: ");
        w=Integer.parseInt(wStr);
        xStr=JOptionPane.showInputDialog("Enter the third score of the second student: ");
        x=Integer.parseInt(xStr);
        yStr=JOptionPane.showInputDialog("Enter the fourth score of the second student: ");
        y=Integer.parseInt(yStr);
        zStr=JOptionPane.showInputDialog("Enter the fifth score of the second student: ");
        z=Integer.parseInt(zStr);
        average3=(t+w+x+y+z)/5;
        {
        if(average3>=90)
            Grade3='A';
        else if(average3>=80)
            Grade3='B';
        else if(average3>=70)
            Grade3='C';
        else if(average3>=60)
            Grade3='D';
        else
            Grade3='F';
        }
        }

        outputStr="Name: "+student1Str+"    "+"Average: "+average1+"    "+"Grade: "+Grade1+"\nName: "+student2Str+"   "+"Average: "+average2+"    "+"Grade: "+Grade2+"\nName: "+student3Str+"   "+"Average: "+average3+"    "+"Grade: "+Grade3;

        JOptionPane.showMessageDialog(null,outputStr,"Grade",JOptionPane.PLAIN_MESSAGE);


    }

}
Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 

Do you have a question? Or has your post any point other than reviving an old thread?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article