/* * 動作結果 * 日本:■■■■■■■■■■ 米国:■■■■■■■■■■■■■■■■ 韓国:■■■■■■■■ */ public class BarGraph { //データ部分 char sign;//グラフを描画する単位となる記号 int number;//数値 String title;//グラフの対象・タイトル //データ部分に値を代入する処理を担当するコンストラクタ public BarGraph(char sign, int number, String title) { super(); this.sign = sign; this.number = number; this.title = title; }//BarGraph() //グラフを描く void draw(){ System.out.print(title + ":");//見出し語を表示 //記号を指定回数表示する for(int i=1;i<=number;i++){ System.out.print(sign); } System.out.println();//改行 }//draw //テスト動作用main()メソッド public static void main(String[] args) { new BarGraph('■',10,"日本").draw(); new BarGraph('■',16,"米国").draw(); new BarGraph('■',8,"韓国").draw(); }//main }//class