This site requires JavaScript, please enable it in your browser!
Greenfoot back
Lukakku
Lukakku wrote ...

2018/6/12

What effect have this commands sections?

Lukakku Lukakku

2018/6/12

#
Hello, I have to write a class test about our last project in school. I just copied what the teatcher wrote down in the script, but nobody undersands what effect those command blocks have. If I would know what they cause, I would maybe be able to change them. I will mark the command-parts with Just write what simple effect the entered commands have. Thank you :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.Random;
import java.util.*;
import java.lang.*;
--------------------------------------------------
/**
 * Write a description of class MyWorld here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
 
public class Medium extends World
{
    public static final int cellsX = 80;
    public static final int cellsY = 80;
    private static final int cellSize = 10;
     
    public static final double forceConst = 1.0;
    public static double attractiveForce = 0.1;
    public static double forceThreshold = 0.1;
    public static double temperature = 5;
     
    public enum Kind
    {
        KATION, ANION, NEUT
    }
     
    Random rand = new Random(); // Initialisierung einer Zufallszahl
     
    public static class Vector
    {
        public double x,y;
         
        public Vector()
        {
            this.x = 0.0;
            this.y = 0.0;
        }
         
        public Vector (double x, double y)
        {
            this.x = x;
            this.y = y;
        }
    }
     
    public static class Cell
    {
        public int x,y;
        public Particle particle;
        boolean occupied;
         
        public Cell()
        {
            this.x = 0;
            this.y = 0;
            this.particle = null;
            this.occupied = false;
        }
         
         public Cell(int x, int y, Particle particle, boolean occupied)
        {
            this.x = x;
            this.y = y;
            this.particle = particle;
            this.occupied = occupied;
        }
         
    }
     
    public static Cell[][] cell = new Cell[cellsX][cellsY];
    public static List<Cell> freeCells = new ArrayList<Cell>();
    public static List<Cell> occupiedCells = new ArrayList<Cell>();
    public static List<Cell> chargedCells = new ArrayList<Cell>();
    public static List<Particle> chargedParticles = new ArrayList<Particle>();
   ------------------------------------------------
    /**
     * Constructor for objects of class MyWorld.
     *
     */
    public Medium()
    
        // Create a new world with cellsX x cellsY cells with a cell size of cellSize x cellSize pixels.
        super(cellsX, cellsY, cellSize);
         
        /*
         * Initialisierung aller Zellen
         * und Vorbereiten der Mengen der freien und besetzen Zellen
         */
         
        freeCells.clear(); // Liste freier Zellen leeren
        occupiedCells.clear(); // Liste besetzter Zellen leeren
        chargedCells.clear(); // Liste besetzter geladener Zellen leeren
        chargedParticles.clear(); // Liste geladener Teilchen leeren
         
        for (int x=0; x<cellsX; x++) // Initialisierung aller Zellen des Mediums
        {
            for (int y=0; y<cellsY; y++)
            {
               cell[x][y] = new Cell(x,y,null,false); // Verwendung des polymorphen Konstruktors
               freeCells.add(cell[x][y]);  // Liste freier Zellen füllen
            }
        }
         
    }
  --------------------------------------------------
    /**
     * createParticle - erzeugt ein Particle der Art kind und der Ladung charge
     * an einer gegebenen Position
     */
    public void createParticle(Kind kind, int charge, int x, int y)
    {
       Particle particle;
        
       particle=new Particle(kind, charge, x, y);
       addObject(particle,x,y);
       cell[x][y].particle = particle;
       cell[x][y].occupied = true;
       freeCells.remove(cell[x][y]);
       occupiedCells.add(cell[x][y]);
       if (charge!=0)
       {
           chargedCells.add(cell[x][y]);
           chargedParticles.add(particle);
       }
    }
    -----------------------------------------------------
    /**
     * createParticles - erzeugt n Teilchen der Art kind und der Ladung charge an zufälligen Positionen
     */
    public void createParticles(int n, Kind kind, int charge)
    {
       int x,y;
       Cell freeCell;
       if (freeCells.size()>=n) {
           for(int i=0; i<n; i++)
           {
               freeCell = freeCells.get(rand.nextInt(freeCells.size()));
               createParticle(kind, charge,freeCell.x,freeCell.y);
           }
        }
        else
        {
            System.out.println("Not enough free cells, only "+freeCells.size()+" cells available!"); // exception
        }
    }
   --------------------------------------------
    /**
     * createKations - erzeugt n Teilchen der Art KATION und der Ladung charge=1 an zufälligen Positionen
     */
    public void createKations(int n)
    {
        createParticles(n, Kind.KATION, 1);
    }
-------------------------------------------------------
    /**
     * createKations - erzeugt n Teilchen der Art KATION und der Ladung charge an zufälligen Positionen
     */
    public void createKations(int n, int charge)
    {
        createParticles(n, Kind.KATION, charge);
    }
-----------------------------------------------------
    /**
     * createAnions - erzeugt n Teilchen der Art ANION und der Ladung charge=-1 an zufälligen Positionen
     */
    public void createAnions(int n)
    {
        createParticles(n, Kind.ANION, -1);
    }
---------------------------------------------------
    /**
     * createAnions - erzeugt n Teilchen der Art ANION und der Ladung charge an zufälligen Positionen
     */
    public void createAnions(int n, int charge)
    {
        createParticles(n, Kind.ANION, charge);
    }
------------------------------------------------
    /**
     * createNeuts - erzeugt n Teilchen der Art NEUT und der Ladung charge=0 an zufälligen Positionen
     */
    public void createNeuts(int n)
    {
        createParticles(n, Kind.NEUT, 0);
    }
--------------------------------------------------------
    /**
     * createKationsAnions - erzeugt jeweils n Teilchen der Art KATION und ANION und der Ladung +1 und -1 an zufälligen Positionen
     */
    public void createKationsAnions(int n)
    {
        createKations(n);
        createAnions(n);
    }
-----------------------------------   
    /**
     * createKationsAnions - erzeugt jeweils n Teilchen der Art KATION und ANION und der Ladung +charge und -charge an zufälligen Positionen
     */
    public void createKationsAnions(int n, int charge)
    {
        int chargeKation, chargeAnion;
        chargeKation = charge;
        chargeAnion = -charge;
        createKations(n,chargeKation);
        createAnions(n,chargeAnion);
    }   
   -------------------------------------------
    /**
     * force - Kraft auf ein Teilchen particle von einem anderen otherParticle
     */
    public static Vector force(Particle particle, Particle otherParticle)
    {
        Vector unitVector, force=new Vector();
        double distanceSquare, distance, forceValue;
         
        if (particle != otherParticle)
        {
            distanceSquare = Math.pow(otherParticle.x - particle.x, 2) + Math.pow(otherParticle.y - particle.y, 2);
            distance = Math.sqrt(distanceSquare);
            forceValue = (-forceConst*particle.charge*otherParticle.charge + Medium.attractiveForce)/Math.pow(distance,2);
            unitVector = unitVector((otherParticle.x - particle.x), (otherParticle.y - particle.y));
            force = multiplyVector(unitVector, forceValue);
        }
        return force;
    }
   ---------------------------------------
    /**
     * totalForce - Kraft auf ein Teilchen particle von allen anderen Teilchen in der Liste otherParticles
     */
    public static Vector totalForce(Particle particle, List<Particle> otherParticles)
    {
        Vector totalForce = new Vector();
        Particle otherParticle;
         
        for (int i=0; i<otherParticles.size();i++)
        {
            otherParticle = otherParticles.get(i);
            totalForce.x += force(particle,otherParticle).x;
            totalForce.y += force(particle,otherParticle).y;
        }
        return totalForce;
    }
    -------------------------------------------
    /**
     * unitVector - erzeugt einen Einheitsvektor in Richtung der Koordinaten x,y
     */   
    public static Vector unitVector(double x, double y)
    {
        double length;
        length = Math.sqrt(x*x + y*y);
        return new Vector(x/length,y/length);
    }
    ----------------------------------------------
    /**
     * multiplyVector - multipliziert Vector vector mit dem Skalar scalar
     */   
    public static Vector multiplyVector(Vector vector, double scalar)
    {
        vector.x *= scalar;
        vector.y *= scalar;
        return vector;
    }
    ----------------------------------------------
    /**
     * Setze temperatur Wert
     */
    public void setTemperature(double temperature)
    {
        this.temperature = temperature;
    }
   -------------------------------------------------------
    /**
     * Setze forceThreshold Wert
     */
    public void setForceThreshold(double forceThreshold)
    {
        this.forceThreshold = forceThreshold;
    }
-----------------------------------------
    /**
     * Setze attractiveForce Wert
     */
    public void setAttractiveForce(double attractiveForce)
    {
        this.attractiveForce = attractiveForce;
    }
---------------------------------------------------
}
danpost danpost

2018/6/12

#
Lukakku wrote...
Just write what simple effect the entered commands have.
What lines (or blocks) are you referring to? List them one by one giving first and last line of each. You mentioned "command blocks", which leads me to believe you are asking about the methods. However, it seems they are all already documented.
You need to login to post a reply.