• 締切済み

成績表示プログラム

class Test { String subject; int point; void SetPoint(String s, int p) { subject = s; point = p; } String getPoint() { return subject + ":" + point; } } class Student { int id; String name; int subnum; Test[] test; Student(int i, String n, int s) { id = i; name = n; subnum = s; test = new Test[s]; for(int j = 0; j < s; j++) test[j] = new Test(); } String getName() { return id + " " + name; } int getGrade() { int sum = 0; for(int i = 0; i < subnum; i++) sum += test[i].point; return sum; } // メソッドのオーバーロード int getGrade(int a) { int base = 100 * subnum / a; int rank = getGrade() / base + 1; return rank; } void printScore() { System.out.println(getName()); for(int i = 0; i < subnum; i++) System.out.print(test[i].getPoint() + " "); System.out.println(); System.out.println("合計点:" + getGrade()); int rank = 5; System.out.println("評 価:" + getGrade(rank)); System.out.println(); } } class ClassRoom { public static void main(String[] args) { Student taro = new Student(12, "taro", 3); taro.test[0].SetPoint("国 語", 95); taro.test[1].SetPoint("数 学", 83); taro.test[2].SetPoint("英 語", 76); taro.printScore(); Student jiro = new Student(7, "jiro", 3); jiro.test[0].SetPoint("国 語", 66); jiro.test[1].SetPoint("数 学", 97); jiro.test[2].SetPoint("英 語", 72); jiro.printScore(); } } このJavaのプログラムを画面上に表示させて、下記のようなプログラムを追加したいです。 国語「  」点 数学「  」点 英語「  」点 と言う画面で点を入力して「計算」を押すと 合計点「  」点 評価「  」 が表示されるようにしたいです。

noname#111556
noname#111556
  • Java
  • 回答数1
  • ありがとう数0

みんなの回答

回答No.1

んー、とりあえずSwingかアプレットの基礎を学んできてください。 最低限画面くらいは表示できないと回答の仕様がないです。 Swing http://www.javadrive.jp/tutorial/ アプレット http://www.javadrive.jp/applet/

関連するQ&A

  • identifierについて教えて下さい

    大学の課題をやっていたところ、わからないところが出てきてしまったので教えていただけないでしょうか? エラーが一箇所出てきてしまい、それが <identifier>がありません。 int setDate2(int d,e){ ^ となっています。 初歩的な質問なのですが、調べても分からないので宜しければお願い致します。 以下ソース class Hito{ //フィールド String name; int age; //メソッド String setDate(String a){ name = a; } int setDate(int b){ age = b; } void talk(){ System.out.println(name); System.out.println(age); } } class Gakusei extends Hito{ //フィールド String daigaku; int gakunen; int bangou; //メソッド String setDate2(String c){ daigaku = c; } int setDate2(int d,e){ gakunen = d; gakuseki = e; } void talk(){ System.out.println(daigaku); System.out.println(gakunen); System.out.println(bangou); } } class kadai2{ public static void main(String[] args){ Hito taro = new Hito(); taro.setData("太郎",18); taro.talk(); Gakusei jiro = new Gakusei(); jiro.setData("次郎",20); jiro.setData2("○○○○大学",2,2100000); jiro.talk(); } }

    • ベストアンサー
    • Java
  • プログラムの合体。

    jump7799_4836さん 2018/7/2103:34:44 public class Test2 { public static int メソッド () { System.out.println("メソッド()が呼ばれました"); return 0; } public static int メソッド (int i) { System.out.println("メソッド(int i)が呼ばれました"); return i; } public static int メソッド (int i, int j) { System.out.println("メソッド(int i, int j)が呼ばれました"); return i; } public static int メソッド (short s) { System.out.println("メソッド(short s)が呼ばれました"); return s; } public static int メソッド (double d) { System.out.println("メソッド(double d)が呼ばれました"); return (int) d; } } public メソッド class Test2 { public メソッド static void main(String[] args) { Test2.メソッド (); Test2.メソッド (1); Test2.メソッド (1,2); Test2.メソッド (1.1); Test2.メソッド ((short) 1); Test2.メソッド ((double)1); } } kouzou@GD348ZZD9:/WORK$ javac Test2.java Test2.java:29: エラー: class、interfaceまたはenumがありません public メソッド class Test2 { ^ Test2.java:30: エラー: <identifier>がありません public メソッド static void main(String[] args) { ^ エラー2個 2つのプログラムが合体することってあるのですか? いつもすみません。 解説のほど、宜しくお願い申し上げます。

    • ベストアンサー
    • Java
  • スタックで成績表を作るプログラム。

    成績表を作りたい。Studentのクラスを要素とするクラスStackを完成させてプログラムが動作するようにせよという問題なのですがprivateの物をどうやって要素にすればよいのでしょうか? class Student { private int id; private String name; private int eng; private int math; private int kokugo; Student(int i,String nm,int e,int m,int k) { id=i;name=nm;eng=e;math=m;kokugo=k; } void show(){ System.out.println("("+id+","+name+","+ eng+","+ math+","+ kokugo+")"); } } class Stack { } class Sample { public static void main(String[] args) { Stack ss=new Stack(3); ss.push(new Student(1,"A",10,10,10)); ss.push(new Student(2,"B",20,10,10)); ss.push(new Student(3,"C",30,10,10)); ss.push(new Student(4,"D",40,10,10)); ss.pop(); ss.pop(); ss.pop(); ss.pop(); } }

    • ベストアンサー
    • Java
  • javaのプログラムについて

    以下のプログラムを実行するとエラーが起こるのですが原因はなんですか? class Tokuten { private String name; private int eng; private int math; private int sci; public void setData(String n, int e, int m, int s) { if(g>0 && g <1000){ name = n; eng = e; math = m; sci = s; } void show() { System.out.println("受験生の名前は" + name + "です。"); System.out.println("英語は" + eng + "点です。"); System.out.println("数学は" + math + "点です。"); System.out.println("理科は" + sci + "点です。"); } } class TokutenMain { public static void main(String[] args) { Tokuten jukensei = new Tokuten(); jukensei.setData("Hanako",81,67,78); jukensei.show(); } }

  • java iを1づつ増やすプログラムと2づつ増やすプログラム

    次のようにすればiを1づつ増やして表示されます。 class Calc{   int i=1;   int add(){     return i++;   } } class Count{   public static void main(String[] args){     Calc calc = new Calc();     System.out.println("i = " + calc.add());     System.out.println("i = " + calc.add());     System.out.println("i = " + calc.add());   } } 実行結果 i = 1 i = 2 i = 3 しかし次のように2づつ増やそうとすると、 class Calc{   int i=1;   int add(){     return i+2;   } } class Count{   public static void main(String[] args){     Calc calc = new Calc();     System.out.println("i = " + calc.add());     System.out.println("i = " + calc.add());     System.out.println("i = " + calc.add());   } } 実行結果 i = 3 i = 3 i = 3 このようになってしまいます。どこがおかしいのでしょうか?

    • ベストアンサー
    • Java
  • javaのプログラムについて

    java始めたばかりの者です。 class sample1 { public static void main(String[] args) { for(int i=1; i<=5; i++){ for(int j=0; j<i; j++){ System.out.println("*"); } System.out.println("\n"); } } } これを実行すると * * * * * * * * * * * * * * * こうなってしまい * ** *** **** ***** このようにするにはどうしたらいいのでしょうか??

    • ベストアンサー
    • Java
  • *を表示させるプログラムを

    //putChars()メソッドを呼ばず(使わず) for文のネストで、できますか import java.util.Scanner; class IsoscelesTriangleRB { //--- 文字cをn個連続表示 ---// static void putChars(char c, int n) { while (n-- > 0) System.out.print(c); } public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); System.out.println("右下直角の三角形を表示します。"); System.out.print("段数は:"); int n = stdIn.nextInt(); for (int i = 1; i <= n; i++) { putChars(' ', n - i); // ' 'をn - i個表示 putChars('+', i); // '+'を i 個表示 System.out.println(); } } }

  • コンストラクタで設定した値が表示されない

    以下のプログラムを見ていただけたら分かるとおり、コンストラクタで設定した値が、配列だと表示されるのに、配列を使用していない変数だと表示されません。なせなのでしょうか? よろしくお願いします。 package test; public class test { public test(int[] idt, double ddt, String title) { title = "テスト"; ddt = 99.9; for(int i=0; i<idt.length; i++) { idt[i] = i; } } public static void main(String[] args) { int[] idt = {0, 0, 0}; double ddt=0.0; String title= ""; test t = new test(idt, ddt, title); for(int i=0; i<idt.length; i++) { System.out.println(idt[i]); } System.out.println(ddt + ", " + title); } }

    • ベストアンサー
    • Java
  • [Java]Javaの文法が間違っているのでしょうか・・・?

    6人分の小テストの点数を記録し,平均点,最高点,平均点以下の人の一覧を計算するプログラムを作成したいのです。 入力はコマンドラインから行います。 しかし,TEST配列がうまく初期化がうまく記述できないため,コンパイル時点で”シンボルが見つけられません”というエラーが出てしまいます。 Javaの経験が浅いので、文法そのものが間違っているか心配です。C言語についてはある程度知識がありますから、C言語と対比して教えて頂けたりすると大変たすかります。 宜しくお願い致します。 class Lecture { static Lecture[] TEST; static double avg=0; static int max=0; static int i = 0; static String kamoku; int scorebox; String name; String student_number; Lecture(int size){ TEST = new Lecture[size]; for (int i = 0; i < size; i++) { Exercise a = new Exercise(); Student b = new Student(); TEST[i] = new Lecture(a,b); } } static void add(Exercise score, Student aStudent) { TEST[i].name = aStudent.name; TEST[i].student_number = aStudent.student_number; TEST[i].scorebox = score.score; i++; } static void avg() { int sum=0; for (int i = 0; i < 6; i++) { sum += TEST[i].scorebox; } avg = sum / 6; } static void max() { int max = 0; int temp = 0; for (int i = 0; i < 6; i++) { if (max < TEST[i].scorebox) { temp = i; max = TEST[i].scorebox; } } max = i; } static void show_kamoku(){ System.out.println("科目:"+kamoku); } static void show(){ Lecture.max(); System.out.println("平均点:"+avg); System.out.println("最高得点者:"+TEST[max]); } static void under_avg(){ Lecture.avg(); System.out.println("平均点を下回った者"); for(int i=0 ; i<6 ; i++){ if(avg > TEST[i].scorebox){ System.out.println(TEST[i]); } } } } class Exercise { int score; Exercise(int score) { this.score = score; } Exercise() { } public String toString() { return " 得点:" + score; } } class Student { String name; String student_number; Student(String student_number,String name ) { this.name = name; this.student_number = student_number; } Student() { } public String toString() { return "学籍番号:" + student_number + " 名前:" + name; } } class ExerciseEvaluation { public static void main(String args[]){ Lecture.kamoku=args[0]; Lecture[] lec = new Lecture[6]; Student Y0 = new Student(args[1],args[2]); Exercise X0 = new Exercise(Integer.parseInt(args[3])); lec[0].add(X0, Y0); Student Y1 = new Student(args[4], args[5]); Exercise X1 = new Exercise(Integer.parseInt(args[6])); lec[1].add(X1, Y1); Student Y2 = new Student(args[7], args[8]); Exercise X2 = new Exercise(Integer.parseInt(args[9])); lec[2].add(X2, Y2); Student Y3 = new Student(args[10], args[11]); Exercise X3 = new Exercise(Integer.parseInt(args[12])); lec[3].add(X3, Y3); Student Y4 = new Student(args[13], args[14]); Exercise X4 = new Exercise(Integer.parseInt(args[15])); lec[4].add(X4, Y4); Student Y5 = new Student(args[16], args[17]); Exercise X5 = new Exercise(Integer.parseInt(args[18])); lec[5].add(X5, Y5); Lecture.show_kamoku(); Lecture.show(); Lecture.under_avg(); } }

  • 空白にはなにを入れればいいのでしょうか?

    [A君,50,60,70] -> 180 [Bさん,90,70,80] -> 240 [C君,30,40,45] -> 115 という3教科の試験の合計点を学生毎に表示するものですが、<?>の部分になんと書けばいいのかわかりません。。教えてください。 import java.lang.*; import java.io.*; import java.util.*; class Student { private String name; private int[] score; public Student (String name, int[] score){ this.name = name; this.score = score; } public Student(String name, int x, int y, int z){ this.score = new int[3]; } public String toString(){ String s = "[" + name; for (int i=0; i < score.length; i++){ s += “ , “ + score[1]; } s += "]"; return s; } public int total(){ int sum = 0; for (int i=0; i<<?>; i++){ <?> } return sum; } } class StudentTest { public static void main(String[] args){ Student[] data = { new Student("A君",50,60,70), new Student("Bさん",90,70,80), new Student("C君",30,40,45), }; for (int i=0; i<data.length; i++){ System.out.println("" + data[i] + "\t-> " + data[i].total()); } } }  

    • ベストアンサー
    • Java

専門家に質問してみよう