Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.kielce.tu.lab6;
- class Person {
- int id;
- String firstName, lastName;
- Person(int id, String firstName, String lastName) {
- this.id = id;
- this.firstName = firstName;
- this.lastName = lastName;
- }
- }
- class Student extends Person {
- String group;
- Student(int id, String firstName, String lastName, String group) {
- super(id, firstName, lastName);
- this.group = group;
- }
- @Override
- public String toString(){
- String ans = "S";
- ans += this.id;
- return ans;
- }
- @Override
- public boolean equals(Object s){
- Student st = (Student)s;
- if(this.id == st.id && this.firstName == st.firstName && this.lastName == st.lastName && this.group == st.group)
- return true;
- else
- return false;
- }
- @Override
- public int hashCode(){
- Integer id = this.id;
- String imie = this.firstName;
- String nazwisko = this.lastName;
- String grupa = this.group;
- int hash = id.hashCode() + imie.hashCode() + nazwisko.hashCode() + grupa.hashCode();
- return hash;
- }
- }
- class Teacher extends Person {
- String title;
- Teacher(int id, String title, String firstName, String lastName) {
- super(id, firstName, lastName);
- this.title = title;
- }
- @Override
- public String toString(){
- String ans = "T";
- ans += this.id;
- return ans;
- }
- @Override
- public boolean equals(Object t){
- Teacher tr = (Teacher)t;
- if(this.id == tr.id && this.firstName == tr.firstName && this.lastName == tr.lastName && this.title == tr.title)
- return true;
- else
- return false;
- }
- @Override
- public int hashCode(){
- Integer id = this.id;
- String imie = this.firstName;
- String nazwisko = this.lastName;
- String title = this.title;
- int hash = id.hashCode() + imie.hashCode() + nazwisko.hashCode() + title.hashCode();
- return hash;
- }
- }
- public class TestMyCollection {
- private static void testIntegers() {
- MyHashCollection list = new MyHashCollection(4, 4);
- list.add(1);
- list.add(1);
- list.add(9);
- list.add(2);
- list.add(3);
- System.out.println(list);
- list.delete(3);
- System.out.println(list);
- list.add(5);
- System.out.println(list);
- }
- private static void testStudentsAndTeachers() {
- MyHashCollection list = new MyHashCollection(4, 4);
- list.add(new Student(1, "Jan", "Kowalski", "Group_1"));
- list.add(new Student(1, "Jan", "Kowalski", "Group_1"));
- list.add(new Teacher(9, "prof.", "Adam", "Mickiewicz"));
- list.add(new Student(2, "Piotr", "Nowak", "Group_1"));
- list.add(new Student(3, "Tomasz", "Kowal", "Group_1"));
- System.out.println(list);
- list.delete(new Student(3, "Piotr", "Nowak", "Group_1"));
- System.out.println(list);
- list.add(new Student(5, "Wojciech", "Król", "Group_1"));
- System.out.println(list);
- }
- public static void main(String[] args) {
- testIntegers();
- testStudentsAndTeachers();
- }
- }
- package pl.kielce.tu.lab6;
- class PojazdGasienicowy extends PojazdKolowy {
- int iloscKolNosnych;
- public PojazdGasienicowy(String naz, int m, int ik, int ikn, int pl) {
- super(naz, m, ik, pl);
- this.iloscKolNosnych = ikn;
- }
- //przeciazenie metody z klasy bazowej
- @Override
- public void skrecaj(char kier) {
- if (kier == 'L')
- System.out
- .println("Lewa gasienica jedzie do tylu, prawa do przodu, skrecam w lewo");
- if (kier == 'P')
- System.out
- .println("Prawa gasienica jedzie do tylu, lewa do przodu, skrecam w prawo");
- }
- }
- class WozBojowy extends PojazdKolowy {
- int kaliberDziala;
- public WozBojowy(String naz, int m, int ik, int kal, int pl) {
- super(naz, m, ik, pl);
- this.kaliberDziala = kal;
- }
- public void laduj(int x, int y) {
- System.out.println("Zaladowalem " + x + " osob oraz " + y
- + " sztuk amunicji");
- }
- public void strzelaj() {
- System.out.println("Strzelam");
- }
- class Czolg extends PojazdGasienicowy {
- public Czolg(String naz, int m, int ik, int ikn, int kal, int pl) {
- super(naz, m, ik, ikn, pl);
- WozBojowy.this.kaliberDziala = kal;
- }
- }
- }
- public class PojazdKolowy {
- int masa;
- int iloscKol;
- int pojemnoscLudzka;
- String nazwa;
- public PojazdKolowy(String naz, int m, int ik, int pl) {
- this.masa = m;
- this.iloscKol = ik;
- this.pojemnoscLudzka = pl;
- this.nazwa = naz;
- }
- public void jedz() {
- System.out.println("Jade");
- }
- public void skrecaj(char kier) {
- if (kier == 'L')
- System.out.println("Kieruje przednie kola w lewo, skrecam w lewo");
- if (kier == 'P')
- System.out
- .println("Kieruje przednie kola w prawo, skrecam w prawo");
- }
- public void laduj(int x) {
- System.out.println("Zaladowalem " + x + " osob");
- }
- public static void main(String[] args) {
- PojazdKolowy poj = new PojazdKolowy("Nissan", 25000, 4, 5);
- PojazdGasienicowy gas = new PojazdGasienicowy("Czolg", 25000, 4, 10, 4);
- WozBojowy woz = new WozBojowy("Czolg", 25000, 4, 10, 4);
- WozBojowy.Czolg cz = woz.new Czolg("IS3",56000,4,12,122,4);
- cz.WozBojowy.strzelaj();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment