Übergeben von Variablen zwischen den Methoden?

So, ich bin versucht, zu schreiben, ein einfaches java-Programm, das college, und ich bin ein absoluter Neuling in diesem java-Kram. Ich bekomme immer einen Fehler wenn ich compile, "Fehler - konnte nicht finden symbol" innerhalb der Methode printreciept. Ich weiß, dass es so etwas wie nicht in der Lage, Zugriff auf die Variablen in der main. Könnte mir jemand helfen? Ich weiß, ich werde prob haben eine Menge Fehler, wenn ich es beheben, aber ich würde lieber hier starten! P. S. sorry für alle der code :/

import java.util.Scanner;

public class Order {

public static void main (String[] args) {

    String clubcard;
    double clubcard_discount;
    double special_discount;
    double balance; 
    double final_balance; 
    int apples;
    int oranges;
    int apples_cost;
    int oranges_cost;

    final Scanner scanner = new Scanner( System.in);
    System.out.println("How Many Bags of Apples?");
    apples = scanner.nextInt( );
    System.out.println("How many bags of Oranges?");
    oranges = scanner.nextInt( );
    System.out.println("Do you have a clubcard? Yes/No");
    clubcard = scanner.nextLine();

    if(clubcard == "Yes") {
        clubcard_discount = clubcard_discount - 1.0;
        final_balance = final_balance - (balance / 100 * 10);
    }

    else if(clubcard == "No") {
        special_discount = 0.0;
    }   

    if(apples == 3) {
        special_discount = -1.0;
        balance = balance - 1.0;
    }

}

//Calculating the cost of apples and oranges
public void calculate_apples (final double apples_cost ) {
    apples_cost = apples * 1.0;
}

public void calculate_oranges (final double oranges_cost ) {
    oranges_cost = oranges * 1.25;
}

//Printing the receipt
public static void printReceipt() {
    System.out.println("Bags of apples: " + apples);
    System.out.println("Bags of oranges: " + oranges);
    System.out.println("Clubcard: " + clubcard);
    System.out.println( );
    System.out.println("Price for apples: " + apples_cost);
    System.out.println("Special discount: " + special_discount);
    System.out.println("Price of oranges: " + oranges_cost);
    System.out.println("Total: " + balance);
    System.out.println("Clubcard discount: " + clubcard_discount);
    System.out.println( );
    System.out.println("Final price: " + final_balance);
    System.out.println( );
    System.out.println("Thanks for doing business with CS2500.");

  }

 }
  • bitte fügen Sie die stack-Fehler
  • Sie müssen entweder deklarieren Sie alle Variablen als Class Variablen innerhalb der Klasse, aber außerhalb der main Funktion, oder ändern printReceipt zu akzeptieren alle, die Variablen als Argumente.
  • Bitte Bearbeiten Sie die Frage, um die komplette Fehlermeldung mit Angabe der Zeile bewirkt, dass der compiler-Fehler.
Schreibe einen Kommentar