Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
/**
 * Write a description of class Methods here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
import java.util.Random;
public class Methods
{

    public Methods()
    {
       int a, b, c, avg=0;
       String grade="";
       Random random = new Random();
       a = random.nextInt(101);
       b = random.nextInt(101);
       c = random.nextInt(101);

       System.out.println("Your grade is " + avg + " you receive a " + grade);

    }


       public static int avg(int a, int b, int c) {
           int avg = (a + b + c) / 3;

           return avg;


    }


    public static String grade(int avg) {
        String grade;
        if (avg >= 90.0)
        grade = "A";
        else if (avg >= 80.0)
        grade = "B";
        else if (avg >= 70.0)
        grade = "C";
        else if (avg >= 60.0)
        grade = "D";
        else
        grade = "F";

        return grade;


    }
}
Posted

1 solution

You do not fix it - you will use another technic:
Java
public class MyClass{

  private String test = "it works";

  // construtor NEVER executes code. only values are handed over if given as arguments.
  // Further fun is happening in another method that might be called (often init() ).
  public MyClass(){
    this.startTheFun();
  }

  private void startTheFun(){
  // have fun
    System.out.println(test);
  }

  // Main is entry point - not more. so let's create an object!
  // the main method is the only static thingy in your class.
  public void main(String[] args){
    new MyClass(); //
  }

}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900