B3

package sk.paz1a.practicals.task3;

import java.awt.Color;

import sk.upjs.jpaz2.*;

public class SmartTurtle extends Turtle {

        public void mystery() {
                for (int i = 0; i < 256; i++) {
                        Color c = new Color(i, 100, 100);
                        this.setPenColor(c);
                        this.setPosition(i, 0);
                        this.moveTo(i, 150);
                }
        }

        public void setRandomPenColor() {
                int r = (int) (Math.random() * 256);
                int g = (int) (Math.random() * 256);
                int b = (int) (Math.random() * 256);
                Color c = new Color(r, g, b);
                this.setPenColor(c);
        }


        public double concentricCircles(double radius) {
                double result = 0;

                while (radius > 1) {
                        // pripocitam obsah aktualneho kruhu
                        result = result + Math.PI * radius * radius;
                        this.circle(radius);
                        radius = 0.8 * radius;
                }

                return result;
        }
}
 
package sk.paz1a.practicals.task3;

import sk.upjs.jpaz2.*;

public class Launcher {

        public static void main(String[] args) {
                WinPane sandbox = new WinPane();

                SmartTurtle franklin = new SmartTurtle();
                sandbox.add(franklin);

                ObjectInspector oi = new ObjectInspector();
                oi.inspect(franklin);
                oi.inspect(sandbox);

                //franklin.mystery();
                //franklin.setRandomPenColor();
                //franklin.step(100);

                double sum = franklin.concentricCircles(120);
                System.out.println(sum);

                //System.out.println(franklin.concentricCircles(100));


                franklin.step(100);

        }
}
 
package sk.paz1a.practicals.task3;

public class ScientificTurtle {


        public long power(int n, int k) {
                long res = 1;
                for (int i = 0; i < k; i++) {
                        res = res * n;
                }
                return res;
        }







        public int countDivisors(int n) {
                int divisors = 0;
                for (int i = 1; i <= n; i++) {
                        if (n % i == 0) {
                                divisors++;
                        }
                }
                return divisors;
        }

        public boolean isPrime(int n) {
                return this.countDivisors(n) == 2;
        }



        public boolean containsDigit(byte c, int n) {
                if (n == 0) {
                        return c == 0;
                }

                // na tomto mieste vieme ze n != 0

                while (n > 0) {
                        if (n % 10 == c) {
                                return true;
                        }
                        n = n / 10;
                }
                return false;
        }
}
 
package sk.paz1a.practicals.task3;

import sk.upjs.jpaz2.*;

public class Launcher {

        public static void main(String[] args) {
                ScientificTurtle franklin = new ScientificTurtle();

                // zmenit na 15
                for (int i = 0; i < 15; i++) {
                        System.out.println(franklin.power(10, i));     
                }


        }
}