1.11M Members

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

 
-3
 

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

 
1
 

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

}
}

 
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)

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

}
 
0
 

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

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

 
0
 

Here:

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

 
1
 

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

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

 
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.

 
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

 
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

 
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

 
-1
 

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

 
-2
 

//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);


    }

}
 
0
 

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

 
0
 

my instructor told us to create a flowchart that will accept prelim,midterm and final grade and will determine the average,identify if it's pass or failed . . . can someine help me with this. . . thanks in advance

 
0
 

Hi Rachelle, welcome to DaniWeb.
Please take a moment to familiarise yourself with the site rules
http://www.daniweb.com/community/rules
in particular, don't hijack old threads - start your own for a new question
and
you must show what you have done so far if you want help with homework.

JC

You
Post:
Start New Discussion
Tags Related to this Article