Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class Classroom {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- int quantity;
- System.out.printf("How many students are studying in your class? ");
- quantity = in.nextInt();
- Student[] students = new Student[quantity];
- for(int i = 0; i < quantity; i++)
- {
- System.out.printf("Student No. %d:\n", i + 1);
- System.out.printf("Name: ");
- String currentName = in.next();
- System.out.printf("Favorite subject: ");
- String currentFavoriteSubject = in.next();
- System.out.printf("Age: ");
- int currentAge = in.nextInt();
- students[i] = new Student(currentName, currentFavoriteSubject, currentAge);
- }
- System.out.printf("The \"special\" students are:\n");
- for(int i = 0; i < quantity; i++)
- {
- boolean special = true;
- for(int j = 0; j < quantity; j++)
- {
- if(i == j)
- continue;
- if(students[i].getName().equals(students[j].getName()))
- special = false;
- }
- if(special)
- students[i].getData();
- }
- in.close();
- }
- }
- // Next class
- public class Student
- {
- private String name;
- private String favoriteSubject;
- private int age;
- public Student (String name, String favoriteSubject, int age)
- {
- this.name = name;
- this.favoriteSubject = favoriteSubject;
- this.age = age;
- }
- public String getName()
- {
- return name;
- }
- public void getData()
- {
- System.out.printf("___________________________\n");
- System.out.printf("Name: %s\n", name);
- System.out.printf("Favorite Subject: %s\n", favoriteSubject);
- System.out.printf("Age: %d\n", age);
- System.out.printf("___________________________\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement