0

Java の学習を始めたばかりで、割り当てシートに基づいてプログラムを作成しようとしています (このシートは投稿の下部にありました)。しかし、メソッドの使い方がよくわかりません。「Customer.java」クラスでメソッドを作成しましたが、「TestCustomer.java」クラスでそれらを使用しようとしています。しかし、私はこれを行う方法を本当に知らないので、恐ろしくなってしまいました。私はこれに関する情報を検索しましたが、私は自分自身をより混乱させ続けているようです. これらのメソッドを使用する正しい方法を教えてくれる可能性はありますか、または少なくとも正しい方向に向けてくれますか? あなたが提供できるどんな助けにも感謝します。

顧客クラス

import java.util.Scanner;

import javax.swing.JOptionPane;


public class Customer {
public static double taxRate = 0.00;
public static double saleRate = 0.00;
String customerName;
double listSaleAmount;
double saleDiscount = 0;
double netSaleAmount;
double taxAmount;
double saleTotal;
boolean taxable;

public Customer (String CustomerName, boolean taxable) {

}

public double calculateTax (double listSaleAmount) {
    saleDiscount = listSaleAmount*saleRate;
    netSaleAmount = listSaleAmount-saleDiscount;
    if (taxable == true) {
    taxAmount = netSaleAmount*taxRate;
    }
    else {
    taxAmount = 0.00;
    }
    saleTotal = listSaleAmount + taxAmount;


    return saleTotal;

}

public String printRecord; {
    System.out.println("Customer is " + customerName);
    System.out.println("Sale amount is $" + listSaleAmount);
    System.out.println("Discount amount is $" + saleDiscount);
    System.out.println("Net Sale Amount is $" + netSaleAmount);
    System.out.println("Tax amount is $" + taxAmount);
    System.out.println("Total Sale Amount is $" + saleTotal);
}

public static double changeTaxAmount (double taxRate) {
    Scanner input = new Scanner(System.in);
    double userTaxAmount = Double.parseDouble(JOptionPane.showInputDialog("What is the Tax Rate? (8.25 & 8.50 for testing)"));
    taxRate = userTaxAmount;
    return taxRate;

}

public static double changeSaleRate (double saleRate) {
    Scanner input = new Scanner(System.in);
    double userSaleAmount = Double.parseDouble(JOptionPane.showInputDialog("What is the Sale Discount Rate? (0.00 & 7.50 for testing)"));
    saleRate= userSaleAmount;
    return saleRate;
}

public static String printTaxRate; {
    System.out.println("Tax Rate is" + taxRate + "%.");
}

public static String printSaleRate; {
    System.out.println("The Sale Rate is" + saleRate + ".");
}
}

TestCustomer クラス

import java.math.BigDecimal;
public class TestCustomer {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

Customer customer1 = new Customer("Annie Smith", true);
Customer customer2 = new Customer("Bob Wilson", false);
Double totalOfAllSales = 0.00;


//I have no clue how to actually use the methods I created in the Customer class!
//These are my best guesses, which are obviously wrong
//Any help here would be greatly appreciated!
Customer.changeTaxAmount(taxRate);

Customer.printTaxRate;

Customer.changeSaleRate(saleRate);

Customer.printSaleRate;

customer1.listSaleAmount = 65.00;
customer2.listSaleAmount = 52.00;

totalOfAllSales += customer1.calculateTax;
totalOfAllSales += customer2.calculateTax;

customer1.printRecord;
customer2.printRecord;

Customer.changeTaxAmount(taxRate);
Customer.printTaxRate;
Customer.changeSaleRate(saleRate);
Customer.printSaleRate;

customer1.listSaleAmount = 84.00;
customer2.listSaleAmount = 105.00;
totalOfAllSales += customer1.calculateTax;
totalOfAllSales += customer2.calculateTax;
customer1.printRecord;
customer2.printRecord;

System.out.println("The total of all sales is $" + totalOfAllSales);
    }

}

割り当てシート (今はファイルへの出力について心配する必要はありません。主要な仕組みを機能させたいだけです) ここに画像の説明を入力 ここに画像の説明を入力

4

1 に答える 1