Advertisement
Marisichka

Student

Dec 2nd, 2022
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package org.example;
  2.  
  3. public class Student extends Person{
  4.     private int year_stud;
  5.  
  6.     public Student(String name, int age, int year_stud){
  7.         super(name, age);
  8.  
  9.         if (year_stud < 0)
  10.             throw new IllegalArgumentException("Amount of studying years must be >= 1");
  11.  
  12.         this.year_stud = year_stud;
  13.     }
  14.  
  15.     public int getYear_stud(){
  16.         return year_stud;
  17.     }
  18.  
  19.     public void setYear_stud(int year_stud){
  20.         if (year_stud < 0)
  21.             throw new IllegalArgumentException("Amount of studying years must be >= 1");
  22.  
  23.         this.year_stud = year_stud;
  24.     }
  25.  
  26.     public String toString(){
  27.         return "Student { " + name + " who is " + age + ", studies already: " + year_stud + " years }";
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement