Advertisement
Ivelin_1936

class Student

Feb 11th, 2018
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Student extends Person {
  4.  
  5.     private double score;
  6.  
  7.     public Student(String name, int age, boolean isMan, double score) {
  8.         super(name, age, isMan);
  9.         this.setScore(score);
  10.     }
  11.  
  12.     private void setScore(double score) {
  13.         if (score < 2 || score > 6) {
  14.             throw new IllegalArgumentException("Score must been [2...6]");
  15.         }
  16.         this.score = score;
  17.     }
  18.  
  19.     @Override
  20.     public void  showStudentInfo() {
  21.         System.out.println(String.format("Name: %s%n" +
  22.                 "Age: %d", super.getName(), super.getAge()));
  23.         if (super.isMan()) {
  24.             System.out.println("Sex: male");
  25.         } else {
  26.             System.out.println("Sex: female");
  27.         }
  28.         System.out.println(String.format("Score: %f%n" , this.score));
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement