Lab7_5.java:79: error: incompatible types: possible lossy conversion from double to int
                extra = minutesOver + .20;
                                    ^
Lab7_5.java:83: error: incompatible types: possible lossy conversion from double to int
                return totalDue;
                       ^
2 errors

Saya melihat-lihat di situs web dan ternyata orang lain juga memiliki masalah ini tetapi saya melihat komentar dan saya masih tidak mengerti masalahnya, tidak ada ganda dalam kode saya mengapa mengatakan ini. Dan saya juga tidak mengerti kesalahan yang mengatakan tidak dapat menemukan simbol. Tolong bantu saya benar-benar terjebak dalam hal ini untuk sementara waktu.

Kode:

import java.util.Scanner;

public class Lab7_5 {
    static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args) {
        // Declare local variables
        int minutesAllowed, minutesUsed, minutesOver;
        double totalDue; 
        String endProgram = "no";

        // Loop to run program again
        while (endProgram.equals("no")) {
            minutesAllowed = 0;
            minutesUsed = 0;
            totalDue = 0;
            minutesOver = 0;

            // Call functions
            minutesAllowed = getAllowed(minutesAllowed);
            minutesUsed = getUsed(minutesUsed);
            minutesOver = minutesUsed - minutesAllowed;

        if (minutesOver < 0){
            minutesOver = 0;
    }
            totalDue = calcTotal(totalDue, minutesOver, minutesUsed, minutesAllowed);

            // Call functions cont.
            printData(minutesAllowed, minutesUsed, totalDue, minutesOver);

            System.out.println("Do you want to end the program (enter no to process another set of test scores): ");
            endProgram = keyboard.next();

        while (!(endProgram.equals("yes")) && !(endProgram.equals("no"))){
            System.out.println("Please enter a value of yes or no");
            endProgram = keyboard.nextLine();


        }
    }
    }
    public static int getAllowed(int minutesAllowed) {
        System.out.println("How many minutes are allowed: ");

        minutesAllowed = keyboard.nextInt();
    while (minutesAllowed <200 || minutesAllowed >800) {
        System.out.println("Please enter minutes between 200 and 800 ");
        minutesAllowed = keyboard.nextInt();
    }

        return minutesAllowed;
    }

    public static int getUsed(int minutesUsed) {
        System.out.println ("How many minutes were used: ");
        minutesUsed = keyboard.nextInt();

        while (minutesUsed <0) {
            System.out.println("Please enter minutes of at least 0");
            System.out.println("How many minutes were used: ");
            minutesUsed = keyboard.nextInt();

        }
        return minutesUsed;
    }

    public static int calcTotal(double totalDue, int minutesOver, int minutesUsed, int minutesAllowed) {
        int extra;
    if (minutesUsed <= minutesAllowed){
        totalDue = 74.99;
    } else { 
        minutesOver = minutesUsed - minutesAllowed;
        extra = minutesOver * .20;
        totalDue = 74.99 + extra;
        System.out.println ("You were over your minutes by" + minutesOver);
    }
        return totalDue;
    }

    public static void printData(int minutesAllowed, int minutesUsed, double totalDue, int minutesOver) {
        System.out.println("----------------MONTHLY USE REPORT----------------------");
        System.out.println("Minutes allowed were " + minutesAllowed);
        System.out.println("Minutes used were " + minutesUsed);
        System.out.println("Minutes over were " + minutesOver );
        System.out.println("Total due is $ " + totalDue);

    }
}
-1
Sutdent_Sequej 15 November 2017, 21:08

1 menjawab

Jawaban Terbaik

Anda mendeklarasikan extra sebagai int dan kemudian menjadikannya double.

int extra;

extra = minutesOver * .20 // error here
// example 6 * .20 != an int
0
DoesData 15 November 2017, 18:16