Compare commits

...

2 Commits

Author SHA1 Message Date
Oleksii Aleshchenko 827fa59bf9 add lab6 2023-06-08 16:09:12 +03:00
Oleksii Aleshchenko 5ca1856e6b update lab5 2023-06-08 15:19:36 +03:00
8 changed files with 92 additions and 1 deletions

View File

@ -1,9 +1,24 @@
package lab5; package lab5;
import java.util.Objects;
public class Letter { public class Letter {
private char symbol; private char symbol;
public Letter(char symbol) { public Letter(char symbol) {
this.symbol = symbol; this.symbol = symbol;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Letter letter = (Letter) o;
return symbol == letter.symbol;
}
@Override
public int hashCode() {
return Objects.hash(symbol);
}
} }

View File

@ -2,8 +2,17 @@ package lab5;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Word word = new Word("Hello");
Word word2 = new Word(new Letter[]{
new Letter('H'),
new Letter('e'),
new Letter('l'),
new Letter('l'),
new Letter('o'),
});
System.out.println(word.equals(word2));
System.out.println(word == word2);
System.out.println("Done!"); System.out.println("Done!");
} }

View File

@ -1,5 +1,7 @@
package lab5; package lab5;
import java.util.Arrays;
public class Word { public class Word {
private Letter[] letters; private Letter[] letters;
@ -15,4 +17,17 @@ public class Word {
letters[i] = new Letter(chars[i]); letters[i] = new Letter(chars[i]);
} }
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Word word = (Word) o;
return Arrays.equals(letters, word.letters);
}
@Override
public int hashCode() {
return Arrays.hashCode(letters);
}
} }

7
src/lab6/Jazz.java Normal file
View File

@ -0,0 +1,7 @@
package lab6;
public class Jazz extends МузичнаКомпозиція {
public Jazz(int length) {
super(length);
}
}

16
src/lab6/Main.java Normal file
View File

@ -0,0 +1,16 @@
package lab6;
public class Main {
public static void main(String[] args) {
МузичнаКомпозиція музичнаКомпозиція = new МузичнаКомпозиція(40);
МузичнаКомпозиція[] музичніКомпозиції = {
new МузичнаКомпозиція(60),
new Jazz(670),
new Pop(670),
new Rock(670),
};
музичнаКомпозиція = new Jazz(670);
System.out.println(музичнаКомпозиція.getClass().getSimpleName());
System.out.println("Done!");
}
}

7
src/lab6/Pop.java Normal file
View File

@ -0,0 +1,7 @@
package lab6;
public class Pop extends МузичнаКомпозиція {
public Pop(int length) {
super(length);
}
}

7
src/lab6/Rock.java Normal file
View File

@ -0,0 +1,7 @@
package lab6;
public class Rock extends МузичнаКомпозиція {
public Rock(int length) {
super(length);
}
}

View File

@ -0,0 +1,15 @@
package lab6;
public class МузичнаКомпозиція {
/**
* Length in seconds
*/
private int length;
public МузичнаКомпозиція(int length) {
this.length = length;
}
/*public МузичнаКомпозиція() {
}*/
}