Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Alo ich brauche Hilfe und weiß net an wen ich mich wenden soll also dachte ich ich wende mich mal an euch^^

also ich lerne java und objektorientiertes pogrammieren anhand von greenfoot und habe nun ein problem

bwei mir soll sich ein actor meine krabbe zu fällig drehen

also haben ich diesen code(is code richtig?) geschrieben;


import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


/**

 * Write a description of class Krabbe here.

 * 

 * @author (your name) 

 * @version (a version number or a date)

 */

public class Krabbe  extends Actor

{

    /**

     * Act - do whatever the Krabbe wants to do. This method is called whenever

     * the 'Act' or 'Run' button gets pressed in the environment.

     */

    int a = Greenfoot.getRandomNumber(4);

    int i = 1;

    int b = 0;

    public void act() {

     for(i = 0 ;i < 1 ; i++){

     System.out.println(a);

     a= a*90;

     setRotation(a);

     }     

    }

}

er soll sich also drehen, das pogramm ist sicher für jeden profi verständlich, wie soll ich aber nun die variable a nach der for schleife zurüclsetzten?

wenn ich sieh in der for schleife zurücksetzte mit a=b; kriegt er immer nur null ruas und dreht sich nicht^^

aber wenn ich das ganze nach der for schleife mache will ehr nicht weil ich a ja schon defieniert habe!

Bearbeitet von flashpixx
Codetags eingefügt und Titel geändert (war: Anfänger braucht Hilfe )

Ich rate einfach mal.

Wieso setzt du nicht ein


a = Greenfoot.getRandomNumber(4);

in die Methode über die Schleife und lässt die Wertezuweisung davor weg?

(Wenn du a gleich a = 0 setzt, dann hat a natürlich beim nächsten Methodenaufruf wieder 0, weil deine Wertezuweisung im Klassenkontext bzw. außerhalb der Methode stattfindet.

Bearbeitet von lupo49

hey ich habe auch mal mit greenfoot gearbeitet...

allerdings nie so ausführlich das machen wir gerade nur mit bluej aber is fast dasselbe...

kann er nich eigentlich um die jeweiligen codes die er geschrieben hat testen indem er irwie a von ausserhalb eingibt?! geht das nich?! geht zumindest bei bluej:S

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.