0
我需要知道如何將我的平均函數橫切到這個結果函數,如果你越來越?如何橫向arraylist
這是主類:
import java.util.ArrayList;
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList <Calculations> students = new ArrayList <Calculations>();
for (int i = 0; i < 5; ++i) {
Calculations s = new Calculations();
System.out.print("Enter name : ");
s.name = scan.next();
System.out.print("Eter percentage : ");
s.percetage = scan.nextDouble();
students.add(s);
System.out.println("Enter Mrks Obtained");
}
for (Calculations s: students) {
s.result();
for (Calculations i: students) {
s.Average();
}
}
}
}
這是結果類:
import java.util.Scanner;
public class Calculations {
public String name;
public double percetage;
public int integer;
public void result() {
System.out.println((percetage >= 35.0 f ? (name + " Pass") : (name + " Fail")));
}
public void Average() {
// TODO Auto-generated method stub
int mark[] = new int[5];
int i;
float sum = 0;
float avg, perc;
Scanner scan = new Scanner(System.in);
System.out.print("Enter marks Obtained in 5 Subjects : ");
for (i = 0; i < 5; i++) {
mark[i] = scan.nextInt();
sum = sum + mark[i];
}
avg = sum/5;
perc = (sum/500) * 100;
System.out.print("Average Marks = " + avg);
System.out.print("\nPercentage = " + perc + "%");
}
}
究竟是什麼問題?你想達到什麼目的,這段代碼片斷失敗了? – Mureinik