Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 5

Java assignment...please find the error and correct it for me,it is not working.Thanks in advance?

/**

* Write a description of class Grading here.

*

* @author (your name)

* @version (a version number or a date)

*/

public class Grading

{

// instance variables - replace the example below with your own

private int x;

/**

* Constructor for objects of class Grading

*/

public Grading()

{

// initialise instance variables

x = 0;

}

/**

* An example of a method - replace this comment with your own

*

* @param y a sample parameter for a method

* @return the sum of x and y

*/

public String Meangrade(String name,int a)

{String t;

t=("Grade");

switch(t)

{ case "one":if (a>=90)

t=("Grade A");

case "Two":if (a>=80)

t=("Grade B");

case "Three":if (a>=70)

t=("Grade C");

case "Four":if(a>=60)

t=("Grade D");

case "Five":if (a<60)

t=("Grade E");

default:

return t;

}

}

}

2 Answers

Relevance
  • Anonymous
    10 years ago
    Favorite Answer

    Errors :

    1. Remove public written before the constructor.

    2. t=("Grade"); make it t="Grade", i.e remove the opening n closing brackets.

  • 10 years ago

    There are lots of types of errors. It's better if you tell us what's wrong. That is, is it a compile or run time error? Maybe a logic error in that it runs but produces incorrect results.

    Copy & paste the error message.

    +add

    That switch is really unnecessary because you're doing if..else logic. Replace that switch with:

    if( a<60 ) return "Grade E";

    if( a < 70 ) return "Grade D";

    if( a <80 ) return "Grade C":

    if( a < 90 ) return "Grade B";

    return "Grade A";

Still have questions? Get your answers by asking now.