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

2015/6/25

Prime number generator

skueper skueper

2015/6/25

#
I've been doing some at home problems and i'm stuck (heh, ironic...) I've tried a lot of different approaches and I feel like I'm almost there I'm aware that I most likely have to many variables but we'll see what I can do about that. I only have the code in one class called Calulator (I know it's misspelled it's an inside joke.) When you run the program, it displays the number "7" continously. Here's my code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Calulator here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Calulator extends Actor
{
    int n = 1;
    int m = 1;
    int d = 2;
    int e = 2;
    int q = 6*n+1;
    int w = 6*m-1;
    int t = q/d;
    int y = w/d;
    int f = 1000000;
    boolean a = false;
    boolean b = false;
    public Calulator()
    {
        System.out.println("n = 2");
        System.out.println("n = 3");
    }
    /**
     * Act - do whatever the Calulator wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        calculateT();
        calculateY();
    }    
    public void calculateT()
    {
        while (d < n)
        {
            if (d == e)
            {                
                d++;
                d = 3;
                e = 0;
                a = false;
            }
            while (d < e)
            {
                if (t == e)
                {
                    n++;
                    d = 2;
                    e = 0;
                    a = false;
                    calculateT();
                }
            }
            if ( d >= q)
            {
                n++;
                d = 2;
                a = false;
                calculateT();
            }
            a = true;
            trueA();
        }
        if (q >= f)
        {
            Greenfoot.stop();
        }
    }
        public void calculateY()
    {
        while (d < m)
        {
            if (d == e)
            {                
                    d++;
                    d = 3;
                    e = 0;
                    b = false;
            }
            while (d < e)
            {
                if (y == e)
                {
                    m++;
                    d = 2;
                    e = 0;
                    b = false;
                    calculateT();
                }
            }
            if ( d >= n)
            {
                m++;
                d = 2;
                b = false;
                calculateT();                
            }
        }
        if (q >= f)
        {
            Greenfoot.stop();
        }
        b = true;
        trueB();
    }
    public void trueA()
    {
        System.out.println("n = " + q);
        n++;
        calculateT();
        a = false;
    }
    public void trueB()
    {
        System.out.println("n = " + q);
        n++;
        calculateY();
        b = false;
    }
}
lordhershey lordhershey

2015/6/25

#
what are you trying to calculate?
danpost danpost

2015/6/25

#
lordhershey wrote...
what are you trying to calculate?
Yeah, really. The field names are not descriptive at all and there is no documentation to explain what any of them are for (for starters).
skueper skueper

2015/6/25

#
Yeah, im realizing that now... I will post an updated version as soon as I'm done.
You need to login to post a reply.