Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Student extends Person {
- private double score;
- public Student(String name, int age, boolean isMan, double score) {
- super(name, age, isMan);
- this.setScore(score);
- }
- private void setScore(double score) {
- if (score < 2 || score > 6) {
- throw new IllegalArgumentException("Score must been [2...6]");
- }
- this.score = score;
- }
- @Override
- public void showStudentInfo() {
- System.out.println(String.format("Name: %s%n" +
- "Age: %d", super.getName(), super.getAge()));
- if (super.isMan()) {
- System.out.println("Sex: male");
- } else {
- System.out.println("Sex: female");
- }
- System.out.println(String.format("Score: %f%n" , this.score));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement