Created
May 13, 2014 10:44
-
-
Save anonymous/7fe910d7d1837a4e8a58 to your computer and use it in GitHub Desktop.
原価(Cost)と消費税率(TaxRate)から、消費税込み価格を出力するJavaクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*プログラム実行用のクラス*/ | |
public class execute{ | |
public static void main(String args[]){ | |
TaxCalc taxcalc = new TaxCalc(100,0.08); | |
System.out.println(taxcalc.CalcTaxinCost()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
/********************************************************************************/ | |
/*Mac OSのvimで作成 */ | |
/*命名規則:各単語の頭文字を大文字として指定 */ | |
/*多人数開発の経験に乏しいため、public,private,protected */ | |
/*(各オブジェクトやクラスの適用範囲)を意識した */ | |
/*開発が苦手です(後々の改修に備えるという仮定のもと、修飾子はpublicで設定します)*/ | |
/*この他、ご指摘があったらコメント願います */ | |
/********************************************************************************/ | |
//原価(Cost)と消費税率(TaxRate)から、消費税込み価格を出力するクラス | |
//小数点は四捨五入で計算します | |
public class TaxCalc{ | |
public int Cost;//原価 | |
public double TaxRate;//消費税率 | |
//コンストラクタ | |
public TaxCalc(int Cost,double TaxRate){ | |
//入力値に負数が入った場合などのvalidateは致しません | |
this.Cost = Cost; | |
this.TaxRate = TaxRate; | |
} | |
//消費税込み価格を出力 | |
int CalcTaxinCost(){ | |
return (int)Math.round(Cost*(1+TaxRate)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment