1
2public class HelloWorld {
3 public static void main(String[] args) {
4
5 // how to use class in java
6 class User{
7
8 int score;
9 }
10
11 User dave = new User();
12
13 dave.score = 20;
14
15 System.out.println(dave.score);
16
17
18 }
19}
20
1class Number {
2
3 int number;
4
5 // square numbers
6 public boolean isSquare(){
7
8 double squareRoot = Math.sqrt(number);
9
10
11 if(squareRoot == Math.floor(squareRoot))
12 {
13 return true;
14 } else {
15 return false;
16 }
17
18 }
19
20 // triangular numbers
21 public boolean isTriangular(){
22
23 int x = 1;
24
25 int triangularNumber = 1;
26
27 while(triangularNumber < number){
28
29 x++;
30 triangularNumber = triangularNumber + x;
31
32 }
33
34 if(triangularNumber == number){
35 return true;
36 } else {
37 return false;
38 }
39 }
40 }
41
42 // testing
43 Number myNumber = new Number();
44 myNumber.number = 16;
45
46 System.out.println(myNumber.isSquare());
1public class HelloWorld {
2 public static void main(String[] args) {
3
4
5 class Number{
6
7 int number;
8
9 public boolean isPos(){
10 if(number > 0){
11 return true;
12 } else {
13 return false;
14 }
15
16 }
17 }
18
19 Number myNumber = new Number();
20
21 myNumber.number = 7;
22
23 if(myNumber.isPos()){
24 System.out.println(myNumber.number + " is positive!!!");
25 } else {
26 System.out.println(myNumber.number + " is not positive!!!");
27 }
28
29 }
30}
31
1
2public class HelloWorld {
3 public static void main(String[] args) {
4
5 // how to use class in java
6 class User{
7
8 int score;
9
10 // method that can be used outside the class
11 public boolean hasWon(){
12 if(score >= 100){
13 return true;
14 } else {
15 return false;
16 }
17 }
18 }
19
20 User dave = new User();
21
22 dave.score = 20;
23
24 System.out.println(dave.hasWon());
25
26
27 }
28}
29