特急java程式解答…

特急這兩題程式會寫出能夠run的大大幫幫忙!謝謝

1.Implement the following integer methods:

a) Method celsius returns the Celsius equivalent

of a Fahrenheit temperature, using the calculation

C =5.0/ 9.0 *()F-32);

b)Method fahrenheit returns the Fahrenheit equivalent of a

Celsius temperature, using the calculation

F= 9.0/5.0*C+32;

C) Use the methods from parts(a)and (b)to write an application that

enables the user either to enter a Fahrenheit temperature and display

the Celsius equivalent or to enter a Celsius temperature and display

the Fahrenheit equivalent.

2.Write a method qualityPoints that inputs a student's average and

returns 4 if the student's average is 90-100, 3 if the average is 80-89,

2 if the average is 70-79, 1 if the average is 60-69 and

0 if the average is lower than 60. Incorporate the method into an application that reads a value from the user and displays the result.

1 個解答

評分
  • 1 0 年前
    最佳解答

    請參考我的做法

    import java.util.*;

    class A {

    static int celsius(int f) {

    return (int)(5.0 / 9.0 * (f - 32));

    }

    static int fahrenheit(int c) {

    return (int)(9.0 / 5.0 * c + 32);

    }

    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    System.out.print("Please choose (1)C->F or (2)F->C: ");

    int x = scan.nextInt();

    switch (x) {

    case 1:

    System.out.print("Please enter what degree(s) of Celsius: ");

    int c = scan.nextInt();

    System.out.println("Equivalent to " + fahrenheit(c) + " degree(s) of Fahrenheit");

    break;

    case 2:

    System.out.print("Please enter what degree(s) of Fahrenheit: ");

    int f = scan.nextInt();

    System.out.println("Equivalent to " + celsius(f) + " degree(s) of Celsius");

    }

    }

    }

    class B {

    static int qualityPoints(int avg) {

    if (avg >= 90) {

    return 4;

    } else if (avg >= 80 && avg < 90) {

    return 3;

    } else if (avg >= 70 && avg < 80) {

    return 2;

    } else if (avg >= 60 && avg < 70) {

    return 1;

    } else if (avg < 60) {

    return 0;

    }

    return 0;

    }

    public static void main(String[] args) {

    System.out.print("Please enter your average (0~100): ");

    Scanner scan = new Scanner(System.in);

    int x = scan.nextInt();

    System.out.println("Your quality point is " + qualityPoints(x));

    }

    }

還有問題?馬上發問,尋求解答。