Homework 4
This commit is contained in:
parent
0afc86ceeb
commit
72cc3206c4
125 changed files with 4200 additions and 1636 deletions
8
javali_tests/HW4_nop90/Booleans/OkBooleanAndOr.javali
Normal file
8
javali_tests/HW4_nop90/Booleans/OkBooleanAndOr.javali
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Test boolean && and || operators
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
boolean a, b, c;
|
||||
a = b && c || a;
|
||||
}
|
||||
}
|
31
javali_tests/HW4_nop90/Booleans/OkEquals.javali
Normal file
31
javali_tests/HW4_nop90/Booleans/OkEquals.javali
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Test the equal/not equal operations, one of the types must be a subtype of the other
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
C1 c1;
|
||||
C2 c2;
|
||||
C3 c3;
|
||||
Object o1, o2;
|
||||
boolean s;
|
||||
|
||||
o1 = new Object();
|
||||
o2 = new Object();
|
||||
c1 = new C1();
|
||||
c2 = new C2();
|
||||
c3 = new C3();
|
||||
|
||||
s = o1 == o2;
|
||||
s = c1 != c2;
|
||||
s = c3 == c1;
|
||||
s = o2 != o1;
|
||||
s = null == c2;
|
||||
s = o1 == c2;
|
||||
//s = null == o;
|
||||
}
|
||||
}
|
||||
|
||||
class C1 {}
|
||||
|
||||
class C2 extends C1{}
|
||||
|
||||
class C3 extends C2{}
|
15
javali_tests/HW4_nop90/Booleans/OkEquals2.javali
Executable file
15
javali_tests/HW4_nop90/Booleans/OkEquals2.javali
Executable file
|
@ -0,0 +1,15 @@
|
|||
// Test the equal/not equal operations, one of the types must be a subtype of the other
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int a,b;
|
||||
boolean c;
|
||||
a = 8;
|
||||
b = 6;
|
||||
c = a==b;
|
||||
|
||||
if (!c){
|
||||
write(5);}
|
||||
}
|
||||
}
|
||||
|
14
javali_tests/HW4_nop90/Booleans/OkEquals3.javali
Executable file
14
javali_tests/HW4_nop90/Booleans/OkEquals3.javali
Executable file
|
@ -0,0 +1,14 @@
|
|||
// Test the equal/not equal operations, one of the types must be a subtype of the other
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
boolean a,b,c;
|
||||
a = true;
|
||||
b = 6<10;
|
||||
c = a==b;
|
||||
|
||||
if (c){
|
||||
write(5);}
|
||||
}
|
||||
}
|
||||
|
36
javali_tests/HW4_nop90/Booleans/OkNot.javali
Normal file
36
javali_tests/HW4_nop90/Booleans/OkNot.javali
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Test '!' operator
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
boolean a,b,c,d;
|
||||
int x,y;
|
||||
|
||||
a = true;
|
||||
c = !false;
|
||||
b = !a;
|
||||
x = 100;
|
||||
y = 5;
|
||||
|
||||
if (a) {
|
||||
write(1);}
|
||||
writeln();
|
||||
|
||||
if (!b){
|
||||
write(2);
|
||||
}
|
||||
writeln();
|
||||
|
||||
while(c){
|
||||
write(3);
|
||||
c = false;
|
||||
}
|
||||
writeln();
|
||||
|
||||
// !x < 2 * y --> !x type error
|
||||
// !(x < 2 * y) --> correct syntax
|
||||
while(!(x<2*y)){
|
||||
write(y);
|
||||
y = y*2;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue