main
unknown
java
2 years ago
2.2 kB
6
Indexable
package com.example.whatever;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Scanner;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
welcome();
}
public static void welcome() {
Scanner scan = new Scanner(System.in);
System.out.println("Welcome, how big do you want the group to be?");
try{
int size = scan.nextInt();
if(size<=0) {
System.out.println("Size is smaller than 1, therefore cant do much");
} else{
Group group = new Group(size);
runRoll(size, scan, group);
}
} catch(IllegalArgumentException e){
e.printStackTrace();
}
}
private static void runRoll(int size, Scanner scan, Group group) {
for(int i=0; i<size; i++){
System.out.println("Please enter a student (StudentNumber FirstName LastName):");
int st = scan.nextInt();
if (st == -1) {
break;
}
String firstName = scan.next();
String lastName = scan.next();
scan.nextLine();
Student student = new Student(firstName, lastName, st);
group.addStudent(student);
printGroup(group);
}
}
private static void printGroup(Group group) {
Student[] all = group.getAll();
for (Student st : all) {
if (st != null) {
System.out.println(st.getFirstName() + " " + st.getLastName() + ", s" + st.getStNumber());
}
}
}
}Editor is loading...
Leave a Comment