Answer to Question #323044 in Java | JSP | JSF for jack

Question #323044

write a java program that enters students names, test 1, test 2, test 3 scores and calculate average for each student " use arrays"


1
Expert's answer
2022-04-03T16:10:13-0400
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);

    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS