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());
1#Use the class function and give the class a name
2#next use the def __init__() to initilaize and give it some properties.
3class Fruits():
4 def __init__(self, name, colour, taste):
5 self.name = name
6 self.colour = colour
7 self.taste = taste
8#Now create an object by first calling the class
9fruit1 = Fruits(apple, red, sweet)
10print(fruit1.name)
11#this will print the name which is apple
12print(fruit1.colour)
13#this will print the colour which is red
14print(fruit1.taste)
15#this will print the taste which is sweet