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

2021/5/31

CONSOLE TUTO JAVA

ronald ronald

2021/5/31

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

/**
 * Write a description of class MyWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MyWorld extends World
{

    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        super(900, 600, 1); 
        prepare();
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {       
        System.out.println("---Constructor/Model---");
        
        Model model01 = new Model();                            // object class Class
        //addObject(model01, 100, 200);                         // constructor no arguments
        model01.display();                                      // Model
        System.out.println(model01.abc);
        System.out.println(model01.nameOne);
        
        Model model02 = new Model(50, "deux");                  // object class Class
        //addObject(model02, 100, 300);                         // constructor with arguments
        model02.display();                                      // Model
        System.out.println(model02.abc);
        System.out.println(model02.nameOne);
        
        System.out.println("--Constructor/Model01--");
        
        Model01 model03 = new Model01();                        // Model01
        model03.display();
        System.out.println(model03.ghi);
        System.out.println(model03.nameThree);
        
        Model01 model04 = new Model01(01, "three");             // Model01
        model04.display();
        System.out.println(model04.ghi);
        System.out.println(model04.nameThree);
        
        System.out.println("-------Encapsulation-------");
        
        Encapsulation encap = new Encapsulation();              // encapsulation
        encap.setAge(26);
        encap.setName("Mia");
        System.out.println("Age : " + encap.getAge());
        System.out.println("Name : " + encap.getName());
        
        System.out.println("----Overriding/Vehicle-----");
        
        Bike02 bike02 = new Bike02();                           // overriding
        bike02.run();                                           // Vehicle
        
        System.out.println("-------Overloading---------");
        
        Overloading overloading = new Overloading();            // overloading
        System.out.println(overloading.sum(11, 11));
        
        System.out.println(overloading.sum(11, 11, 11));
        
        overloading.loading(12);
        overloading.loading(12, 3.0, 'f');
        
        System.out.println("-------Polymorphism--------");
        
        Polymorphism polymorphism = new Polymorphism();         // polymorphism
        polymorphism.see();
        Polymorphism poly01 = new Poly01();             
        poly01.see();
        Polymorphism poly02 = new Poly02();
        poly02.see();
        
        System.out.println("------Abstraction/Cat------");      
        
        Animal animal = new Cat();                                    // abstraction
        animal.sound();                                            // Cat
        animal.sleep();
        
        System.out.println("-------Inheritance---------");      // inheritance
        System.out.println("------My_Calcualtion-------");      // My_Calculation
        
        My_Calculation demo = new My_Calculation();
        int a = 20;
        int b = 10;
        demo.addition(a, b);
        demo.subtraction(a, b);
        demo.multiplication(a, b);
        
        System.out.println("----Aggregation/Address----");      // aggregation
                                                                // address
        Address ad = new Address(55, "Agra", "UP", "India");
        StudentClass obj = new StudentClass(123, "Chaitanya", ad);
        System.out.println(obj.rollNum);
        System.out.println(obj.studentName);
        System.out.println(obj.studentAddr.streetNum);
        System.out.println(obj.studentAddr.city);
        System.out.println(obj.studentAddr.state);
        System.out.println(obj.studentAddr.country);
        
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Overloading here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Overloading
{
    /**
     * Act - do whatever the Overloading wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }
    
    public int sum(int a, int b)
    {
        System.out.println("First Sum");
        return a + b;
    }
    
    public int sum(int a, int b, int c)
    {
        System.out.println("Second Sum");
        return a + b + c;
    }
    
    public void loading(int x)
    {
        System.out.println(x);
    }
    
    public void loading(int x, double y, char z)
    {
        System.out.println(x + " " + y + " " + z);
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Inheritance here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

class Calculation
{
    int z;
    
    public void addition(int x, int y)
    {
        z = x + y;
        System.out.println("sum of addition : " + z);
    }
    
    public void subtraction(int x, int y) 
    {
        z = x - y;
        System.out.println("difference of subraction : " + z);
    }    
}

public class My_Calculation extends Calculation
{    
    public void multiplication(int x, int y)
    {
        z = x * y;
        System.out.println("product of multiplication : " + z);
    }    
}


Hello I have fun with the console I tried to display the java tutorial on the console History to understand the encaps, polymorphism ... but some classes have no heritage with the actor I give you an example of code on overloading and heritage is this normal good ??? thank you for your understanding
danpost danpost

2021/5/31

#
ronald wrote...
is this normal good ?
Fair enough.
ronald ronald

2021/5/31

#
thank you
You need to login to post a reply.