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

2015/4/29

Help with this scenario in programming please !!

avishka1 avishka1

2015/4/29

#
it is a grid 25 X 25 and this is the scenario Problem 2 – Putting Cakes From the previous exercise Clara already knows how to draw a basket, but to keep her grandmother happy she needs to populate this basket with small cakes. Each cake is represented by a leaf and Clara must put as many cakes as possible inside the basket of the specified dimensions. she must request the width and height of the cake from the user. Once the width and height are entered correctly, Clara must draw the basket as before, but then she also has to fill it with cakes, so that the entire basket is filled with them When drawing the cakes you need to make sure that they are separated by empty cells from one-another and that they are arranged in a checkerboard pattern . The number of cakes must be automatically calculated depending on the width and height of the basket. the leaves are cakes the actor MyClara is a ladybug and he starts off at the bottom, the 2nd last row from bottom , problem 1 code can be used for this , the basket is made by problem 1 and i am not sure how to make a checkerboard design inside basket . Below in the code , the actions and sensors and the type of statement are shown this is the code i used to make basket , i used this in problem 1
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
import javax.swing.JOptionPane;
import java.util.*;
 
/**
 * MyClara is a subclass of Clara. Therefore, it inherits all methods of Clara: <p>
 *
 *
 * PERMITTED COMMANDS
 * Actions:     move(), turnLeft(), turnRight(), putLeaf(), removeLeaf(), showWarning(), intInput()
 * Sensors:     onLeaf(), treeFront()
 * JAVA:        if, else, while, for, !, &&, ||
 */
public class MyClara extends Clara
{
    /**
     * In the 'run()' method you can write your program for Clara
     */
 
    public void run()
    {  
        // TODO: Write your code below
        int z = 0 ;
        int d = 0 ;
        int e = 0 ;
 
        public void run()
        {  
            // TODO: Write your code below
            turnLeft();
            width();
            for ( int i = 0 ; i <z ; i ++)
            {
                putLeaf();
                move();
 
            }
            turnAround();
        }
 
        void width ()
        {
            z = readInt ( " how tall is row " ) ;
            System.out.println ( z ) ;
        }
 
        void turnAround ()
        {
            turnLeft();
            turnLeft();
            for ( int i = 0 ; i < z; i ++ )
            {
                move();
            }
            moveleft();
        }
 
        void moveleft ()
        {
 
            turnLeft();
            check ();
            move();
            d= d-1 ;
            for (int i = 0 ; i < d ; i ++ )
            {
                putLeaf();
                move();
            }
            lookback();
 
        }
 
        void lookback ()
        {
            turnLeft();
            turnLeft();
            move();
            turnRight();
            goup();
        }
 
        void check ()
        {
            d = readInt ( " how long is row " ) ;
            System.out.println ( d ) ;
        }
 
        void checkagain()
        {
            e = readInt ( " how long is row " ) ;
            System.out.println ( e ) ;
        }
 
        void goup()
        {
            checkagain();
            removeLeaf();
            for ( int i =0 ; i < e ; i ++ )
            {
                putLeaf();
                move();
            }
        }
    }
 
}
 
}
avi9927 avi9927

2016/5/10

#
Hi Avishka, Have you got the solution ? Could you please assist me ?
You need to login to post a reply.