Monday, June 26, 2017

Simple Java Code - calling another method

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package helloworldapp;

/**
 *
 * @author Kent Lau
 */
public class HelloWorldApp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Hello World!");
       
        int testscore = 76;
        char grade;
       
       
        System.out.println("Grade = " + testMyScore(testscore));
    }
   
    public static char testMyScore(int score) {
    //do the calculation here
   
        if (score >= 90) {
            return 'A';
        } else if (score >= 80) {
            return 'B';
        } else if (score >= 70) {
            return 'C';
        } else if (score >= 60) {
            return 'D';
        } else {
            return 'F';
        }
    }
   
}

No comments:

Post a Comment