write a java program that enters students names, test 1, test 2, test 3 scores and calculate average for each student " use arrays"
import java.util.Scanner;
class Student{
String name;
int[] test =new int[3];
public double avgTests(){
return (test[0]+test[1]+test[2])/3;
}
Student(int[] test, String name){
this.test=test;
this.name=name;
}
@Override
public String toString() {
return avgTests()+" "+ name;
}
}
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int[] igor=new int[3];
igor[0]= scan.nextInt();
igor[1]= scan.nextInt();
igor[2]= scan.nextInt();
String name=scan.next();
Student chika=new Student(igor,name);
System.out.print(chika);
}
}
Comments
Leave a comment