52 lines
1.4 KiB
Java
52 lines
1.4 KiB
Java
/**
|
|
|
|
* Assignment 10
|
|
|
|
* Course: CISS238
|
|
|
|
* Student: Scott Steely
|
|
|
|
* Date: Sep 19, 2025
|
|
|
|
*/
|
|
package dropbox10;
|
|
import java.util.Scanner;
|
|
public class StudentTest {
|
|
public static void main(String[] args) {
|
|
Scanner input = new Scanner(System.in);
|
|
// variables
|
|
int numberofstudents = 0;
|
|
String name;
|
|
int score;
|
|
int bonus;
|
|
// prompt user for number of students
|
|
System.out.println("enter number of students: ");
|
|
numberofstudents = input.nextInt();
|
|
// create an array
|
|
Student[] students = new Student[numberofstudents];
|
|
// use a loop for student data
|
|
for(int i = 0 ; i < students.length; i++) {
|
|
// remove the enter key when the user enters the number above
|
|
input.nextLine();
|
|
System.out.println("enter student " + (i+1) + "'s name: ");
|
|
name = input.nextLine();
|
|
System.out.println("enter student " + (i+1) + "'s score: ");
|
|
score = input.nextInt();
|
|
// create the student
|
|
Student s = new Student(name, score);
|
|
// add the student to the array
|
|
students[i] =s;
|
|
}
|
|
// prompt for bonus if any
|
|
System.out.println("enter bonus: ");
|
|
bonus = input.nextInt();
|
|
// set bonus for just one student
|
|
students[0].setBonus(bonus);
|
|
// display by using a shorthand for loop
|
|
for(Student s: students) {
|
|
System.out.println(s);
|
|
}
|
|
input.close();
|
|
}
|
|
}
|