[14]マイアプリ-3を作成


方法


方法は整理整頓の箱…!

public class AccountingMethodApp {

	public static void main(String[] args) {
		double valueOfSupply = Double.parseDouble(args[0]);
		double expenseRate = 0.3;
		double vatRate = 0.1;
		double vat = getVAT(valueOfSupply, vatRate);
		double total = valueOfSupply+vat;
		double expense = valueOfSupply*expenseRate;
		double income = valueOfSupply-expense;
		double dividend1 = income*0.5;
		double dividend2 = income*0.3;
		double dividend3 = income*0.2;
		
		System.out.println("Value of supply : "+valueOfSupply);
		System.out.println("VAT : "+vat);
		System.out.println("Total : "+total);
		System.out.println("Expense : "+expense);
		System.out.println("Income : "+income);
		
		System.out.println("Dividend 1 : "+dividend1);
		
		System.out.println("Dividend 2 : "+dividend2);
		
		System.out.println("Dividend 3 : "+dividend3);
		
		

	}

	private static double getVAT(double valueOfSupply, double vatRate) {
		return valueOfSupply*vatRate;
	}

}
これで、クラスに方法があります.

public class AccountingMethodApp {
	public static double valueOfSupply = 10000.0;
	public static double vatRate = 0.1;
	public static void main(String[] args) {
		
		double expenseRate = 0.3;
		double vat = getVAT();
		double total = valueOfSupply+vat;
		double expense = valueOfSupply*expenseRate;
		double income = valueOfSupply-expense;
		double dividend1 = income*0.5;
		double dividend2 = income*0.3;
		double dividend3 = income*0.2;
		
		System.out.println("Value of supply : "+valueOfSupply);
		System.out.println("VAT : "+vat);
		System.out.println("Total : "+total);
		System.out.println("Expense : "+expense);
		System.out.println("Income : "+income);
		
		System.out.println("Dividend 1 : "+dividend1);
		
		System.out.println("Dividend 2 : "+dividend2);
		
		System.out.println("Dividend 3 : "+dividend3);
		
		

	}

	private static double getVAT() {
		return valueOfSupply*vatRate;
	}

}
このようにしてグローバル変数を与えることができます.

public class AccountingMethodApp {
	public static double valueOfSupply;
	public static double vatRate;
	public static double expenseRate;
	public static double expense;
	
	public static void main(String[] args) {
		
		valueOfSupply = 10000.0;
		vatRate = 0.1;
		expenseRate = 0.3;
		expense = getExpense();
		double vat = getVAT();
		double total = getTotal();
		double income = getIncome();
		double dividend1 = income*0.5;
		double dividend2 = income*0.3;
		double dividend3 = income*0.2;
		
		print( dividend1, dividend2, dividend3);
		
		

	}

	private static void print(double dividend1, double dividend2,
			double dividend3) {
		System.out.println("Value of supply : "+valueOfSupply);
		System.out.println("VAT : "+getVAT());
		System.out.println("Total : "+getTotal());
		System.out.println("Expense : "+getExpense());
		System.out.println("Income : "+getIncome());
		System.out.println("Dividend 1 : "+dividend1);
		System.out.println("Dividend 2 : "+dividend2);
		System.out.println("Dividend 3 : "+dividend3);
	}

	private static double getIncome() {
		double income = valueOfSupply-expense;
		return income;
	}

	private static double getExpense() {
		double expense = valueOfSupply*expenseRate;
		return expense;
	}

	private static double getTotal() {
		return valueOfSupply + getVAT();
	}

	public static double getVAT() {
		return valueOfSupply*vatRate;
	}

}
この方法で作ることができます.

カテゴリ


クラスが相互に関連付けられる変数をメソッドに関連付けます
method <- class
class Accounting{
	public static double valueOfSupply;
	public static double vatRate;
	public static double expenseRate;
	public static double expense;
	
	public static void print(double dividend1, double dividend2,
			double dividend3) {
		System.out.println("Value of supply : "+valueOfSupply);
		System.out.println("VAT : "+getVAT());
		System.out.println("Total : "+getTotal());
		System.out.println("Expense : "+getExpense());
		System.out.println("Income : "+getIncome());
		System.out.println("Dividend 1 : "+dividend1);
		System.out.println("Dividend 2 : "+dividend2);
		System.out.println("Dividend 3 : "+dividend3);
	}

	public static double getIncome() {
		double income = valueOfSupply-expense;
		return income;
	}

	public static double getExpense() {
		double expense = valueOfSupply*expenseRate;
		return expense;
	}

	public static double getTotal() {
		return valueOfSupply + getVAT();
	}

	public static double getVAT() {
		return valueOfSupply*vatRate;
	}

}




public class AccountingClassApp {
	
	
	public static void main(String[] args) {
		Accounting.valueOfSupply = 10000.0;
		Accounting.vatRate = 0.1;
		Accounting.expenseRate = 0.3;
		
		Accounting.expense = Accounting.getExpense();
		double vat = Accounting.getVAT();
		double total = Accounting.getTotal();
		double income = Accounting.getIncome();
		
		double dividend1 = income*0.5;
		double dividend2 = income*0.3;
		double dividend3 = income*0.2;
		// anotherVariable = .. ; 
		// anotherMethod = ... ;
		
		Accounting.print(dividend1, dividend2, dividend3);
	}
}
イルケイ...それを等級に縛ることができます!

≪インスタンス|Instance|emdw≫


クラスをコピーすることで、異なるデータ値と異なるメソッド値を持つコピーを作成できます.
class Accounting1{
	public static double valueOfSupply;
	public static double vatRate;
	public static double expenseRate;
	public static double expense;
	
	public static void print(double dividend1, double dividend2,
			double dividend3) {
		System.out.println("Value of supply : "+valueOfSupply);
		System.out.println("VAT : "+getVAT());
		System.out.println("Total : "+getTotal());
		System.out.println("Expense : "+getExpense());
		System.out.println("Income : "+getIncome());
		System.out.println("Dividend 1 : "+dividend1);
		System.out.println("Dividend 2 : "+dividend2);
		System.out.println("Dividend 3 : "+dividend3);
	}

	public static double getIncome() {
		double income = valueOfSupply-expense;
		return income;
	}

	public static double getExpense() {
		double expense = valueOfSupply*expenseRate;
		return expense;
	}

	public static double getTotal() {
		return valueOfSupply + getVAT();
	}

	public static double getVAT() {
		return valueOfSupply*vatRate;
	}

}


class Accounting2{
	public static double valueOfSupply;
	public static double vatRate;
	public static double expenseRate;
	public static double expense;
	
	public static void print(double dividend1, double dividend2,
			double dividend3) {
		System.out.println("Value of supply : "+valueOfSupply);
		System.out.println("VAT : "+getVAT());
		System.out.println("Total : "+getTotal());
		System.out.println("Expense : "+getExpense());
		System.out.println("Income : "+getIncome());
		System.out.println("Dividend 1 : "+dividend1);
		System.out.println("Dividend 2 : "+dividend2);
		System.out.println("Dividend 3 : "+dividend3);
	}

	public static double getIncome() {
		double income = valueOfSupply-expense;
		return income;
	}

	public static double getExpense() {
		double expense = valueOfSupply*expenseRate;
		return expense;
	}

	public static double getTotal() {
		return valueOfSupply + getVAT();
	}

	public static double getVAT() {
		return valueOfSupply*vatRate;
	}

}


public class AccountingClassApp {
	
	
	public static void main(String[] args) {
		Accounting1.valueOfSupply = 10000.0;
		Accounting1.vatRate = 0.1;
		Accounting1.expenseRate = 0.3;
		
		Accounting1.expense = Accounting1.getExpense();
		double vat = Accounting1.getVAT();
		double total = Accounting1.getTotal();
		double income = Accounting1.getIncome();
		
		double dividend1 = income*0.5;
		double dividend2 = income*0.3;
		double dividend3 = income*0.2;
		// anotherVariable = .. ; 
		// anotherMethod = ... ;
		
		Accounting1.print(dividend1, dividend2, dividend3);
		
		//	..
		Accounting2.valueOfSupply = 20000.0;
		Accounting2.vatRate = 0.1;
		Accounting2.expenseRate = 0.3;
		Accounting2.print(dividend1, dividend2, dividend3);
		
		
		
		
	}
}
なんだ.仕事させろ!
Accounting a1 = new Accounting();
		a1.valueOfSupply = 10000.0;
		a1.vatRate = 0.1;		
このようにしてインスタンスを作成します.
classのstaticはすべて出してから使用できます.