標題:
[隨堂練習] 學生成績計算
[打印本頁]
作者:
周政輝
時間:
2016-12-3 11:25
標題:
[隨堂練習] 學生成績計算
建構一個Student 類別
其中裡面內含三個欄位以及一個方法
分別是 國英數 三個欄位 以及計算平均的方法
透過使用者輸入 各科成績
計算出三位不同的學生她們的平均成績
最後儲存在陣列
再依序輸出
作者:
蔡庭豪
時間:
2016-12-3 12:03
package site.istak.org.tw;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
int[]frank =new int[3];
int[]eric =new int[3];
int[]terry =new int[3];
for(int i=0;i<frank.length;i++){
frank[i]=scanner.nextInt();
}
for(int i=0;i<eric.length;i++){
eric[i]=scanner.nextInt();
}
for(int i=0;i<terry.length;i++){
terry[i]=scanner.nextInt();
}
Studens studens=new Studens();
Studens.Avg(frank[0],frank[1],frank[2]);
Studens.Avg(eric[0],eric[1],eric[2]);
Studens.Avg(terry[0],terry[1],terry[2]);
}
}
複製代碼
package site.istak.org.tw;
public class Studens {
private float c;
private float e;
private float m;
private float total;
public Studens(){
this.c = c;
this.e = e;
this.m = m;
this.total=total;
}
public static void Avg(int c,int e,int m){
int total=c+e+m;
System.out.println(total/3);
}
}
複製代碼
作者:
張健勳
時間:
2016-12-4 20:07
package site.istak.org.tw;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[]StuA = new int [3];
int[]StuB = new int [3];
int[]StuC = new int [3];
for(int i=0;i<StuA.length;i++)
{
StuA[i] = scanner.nextInt();
}
for(int i=0;i<StuB.length;i++)
{
StuB[i] = scanner.nextInt();
}
for(int i=0;i<StuC.length;i++)
{
StuC[i] = scanner.nextInt();
}
Stu stu = new Stu();
Stu.Avg(StuA[0],StuA[1],StuA[2]);
Stu.Avg(StuB[0],StuB[1],StuB[2]);
Stu.Avg(StuC[0],StuC[1],StuC[2]);
}
}
複製代碼
package site.istak.org.tw;
public class Stu {
private float Chinese;
private float English;
private float Math;
private float Total;
public Stu(){
this.Chinese = Chinese;
this.English = English;
this.Math = Math;
}
public static void Avg(int Chinese , int English , int Math)
{
int total = Chinese + English + Math ;
System.out.print(total / 3);
}
}
複製代碼
作者:
王彥甯
時間:
2016-12-7 15:33
main
package site.istak.org.tw;
import java.util.Scanner;
public class main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int [] num = new int [3];
for(int i=0;i<num.length;i++)
{
System.out.println("輸入成績");
int Mandarin = scanner.nextInt();
int English = scanner.nextInt();
int Math = scanner.nextInt();
students students = new students(Mandarin, English, Math);
num[i]=(int) students.studentsAvg();
}
for(int j=0;j<num.length;j++)
System.out.println(num[j]);
}
}
複製代碼
students
package site.istak.org.tw;
import java.util.Scanner;
public class students {
private static float Mandarin;
private static float English;
private static float Math;
private static float Avg;
public students(int num , int num2 , int num3)
{
this.Mandarin = num;
this.English = num2;
this.Math = num3;
}
public static float studentsAvg(){
Avg = (Mandarin+English+Math)/3;
return Avg;
}
}
複製代碼
作者:
謝瀞儀
時間:
2016-12-9 20:47
package 泛形;
import java.util.Scanner;
public class Ch01
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int[]Ann = new int[3];
int[]Chris = new int[3];
int[]Bunny = new int[3];
for(int i=0;i<Ann.length;i++){
Ann[i] = s.nextInt();
}
for(int i=0;i<Chris.length;i++){
Chris[i] = s.nextInt();
}
for(int i=0;i<Bunny.length;i++){
Bunny[i] = s.nextInt();
}
Ch02 students = new Ch02();
students.avg(Ann[0],Ann[1],Ann[2]);
students.avg(Chris[0],Chris[1],Chris[2]);
students.avg(Bunny[0],Bunny[1],Bunny[2]);
}
}
複製代碼
package 泛形;
public class Ch02
{
private float chinese;
private float english;
private float math;
private float total;
public Ch02()
{
this.chinese = chinese;
this.english = english;
this.math = math;
this.total = total;
}
public static void avg(int chinese,int english,int math)
{
int total=chinese+english+math;
System.out.println(total/3);
}
}
複製代碼
作者:
蔡季樺
時間:
2016-12-11 20:56
package site.istak.org.tw;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x[] = new int[3];
int y[] = new int[3];
int z[] = new int[3];
System.out.print("小明成績:");
for(int i=0;i<x.length;i++)
{
x[i] = scanner.nextInt();
}
System.out.print("小志成績:");
for(int i=0;i<y.length;i++)
{
y[i] = scanner.nextInt();
}
System.out.print("小美成績:");
for(int i=0;i<z.length;i++)
{
z[i] = scanner.nextInt();
}
Student stu = new Student();
System.out.print("小明平均成績:");
Student.average(x[0], x[1], x[2]);
System.out.print("小志平均成績:");
Student.average(y[0], y[1], y[2]);
System.out.print("小美平均成績:");
Student.average(z[0], z[1], z[2]);
}
}
複製代碼
package site.istak.org.tw;
public class Student {
private static float total;
private static float c;
private static float e;
private static float m;
public void Student()
{
this.c = c;
this.e = e;
this.m = m;
this.total = total;
}
public static void average(int c,int e,int m)
{
total = c+e+m;
System.out.println(total/3);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2