Created
June 11, 2012 09:00
-
-
Save editnuki/2909177 to your computer and use it in GitHub Desktop.
2科目の成績の合計、平均点を出す。(クラスメソッド、インスタンス、コンストラクタありVer)
This file contains hidden or 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 MainStudents{ | |
public static void main(String[] args) { | |
Students onuki = new Students(); | |
int onukiSum = onuki.sum(82,70); | |
System.out.println("小貫の合計点は" + onukiSum); | |
Students suzuki = new Students(); | |
int suzukiSum = suzuki.sum(85,74); | |
System.out.println("鈴木の合計点は" + suzukiSum); | |
Students yamada = new Students(); | |
int yamadaSum = yamada.sum(74,88); | |
System.out.println("山田の合計点は" + yamadaSum); | |
Students gotou = new Students(); | |
int gotouSum = gotou.sum(90,74); | |
System.out.println("後藤の合計点は" + yamadaSum); | |
Students ikeda = new Students(); | |
int ikedaSum = ikeda.sum(70,82); | |
System.out.println("池田の合計点は" + ikedaSum); | |
System.out.println("生徒の数は" + Students.count + "です。"); | |
System.out.println("国語の平均点は" + Students.jaavr / Students.count + "です"); | |
System.out.println("英語の平均点は" + Students.enavr / Students.count + "です"); | |
} | |
} |
This file contains hidden or 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 Students{ | |
public int japanese; | |
public int english; | |
int sum; | |
static int jaavr; | |
static int enavr; | |
//String name; | |
static int count; | |
public int sum(int japanese,int english){ | |
this.sum = japanese + english; | |
jaavr += japanese; | |
enavr += english; | |
return sum; | |
} | |
public Students(){ | |
count++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment