Erstellen Sie ein Programm, mit Buch Klasse und TestBook-Klasse in Java

Ich versuche zu erstellen java-Programm, das ermöglicht dem Benutzer, geben Sie das Buch
Anzahl und zeigt das Programm den Preis des Buches gewählt. Ich habe
erstellt wurde das Buch Klasse und es gibt keine syntax-Fehler, aber die meisten
wahrscheinlich gibt es den Logik-Fehler und die Klasse TestBook hat Fehler
in Berufung auf den Eingang. können Sie mir helfen? im lost 🙁 hier mein code:

class Book{

    String title;
    String author;
    double price;
    int option;

    //constructor
    Book(String title, String author, double newPrice){
        title = title;
        author = author;
        price = newPrice;

    }

    public String getTitle(){
        return title;
    }
    public String getAuthor(){
        return author;
    }
    public double getPrice(){
        return price;
    }
    public int getOption(){
        return option;
    }

    public void setPrice(int option, double price, double newPrice){
        if (option == 1){
            price = 20.00;
            newPrice = price;
        }
        else if (option == 2){
            price = 15.00;
            newPrice = price;
        }
        else if (option == 3){
            price = 23.90;
            newPrice = price;
        }
        else if (option == 4){
            price = 27.30;
            newPrice = price;
        }
        else if (option == 5){
            price = 50.00;
            newPrice = price;
        }
        else if (option == 6){
            price = 13.50;
            newPrice = price;
        }
    }
    public void setOption(int newOption){
        option = newOption;
    }
}

Dem TestBook Klasse

import java.util.Scanner;

public class TestBook{
    public static void main (String[]args){

        Scanner input = new Scanner (System.in);

        //The Book List
        System.out.println("The Book List");
        System.out.println("1)How to do programming 12th Edition by Liang.\n2)Malaysian Food Recipe by Nadia Bt Mahmud.\n3)What is Islam by Ustad Manzoor Malik.\n4)Urban Legend by Christine R.M.\n5)Fundamental of Calculus by Prof. Abu.\n6)How to raise your kids by Salsabila\n");
        System.out.println("Choose your book number to know the price: ");
        int option = input.nextInt();

        Book b1 = new Book(theOption(option);//invoke the option to get the price
        System.out.println("The price is: "+ b1.getPrice);


    }
    //Method option
    public static int theOption(int option){
        return option;
    }
}
  • Können Sie die spezifische Probleme/Fehler, die Sie erhalten?
  • Sie ruft Konstruktor von Buch mit einem argument,nicht sehen, dass in der Klasse geteilt
  • "der Wert der lokalen variable nicht verwenden" dies ist der Fehler in meinem TestBook Klasse
  • Nach weiteren Details wie Bearbeitungen, die Sie auf die Frage und nicht als Kommentare.
Schreibe einen Kommentar