Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need to be done in greenfoot application(java). In your World class , code a while loop so that it uses the default constructor in the

need to be done in greenfoot application(java).

  1. In your World class, code a while loop so that it uses the default constructor in the first name class, to add four (4) first name class objects to the scene at random locations in the World. (1 mark)
  2. In your World class, code a for loop so that it also uses the second constructor in the first name class, to add six (6) first name class objects to the scene in a straight line. The starting position can be anywhere on the scene BUT must increment on one axis (either the X axis or the Y axis). The position of each object should change 30 pixels each time the loop iterates. (3 marks)
  3. In your World class, write code so that you demonstrate a nested for loop. The nested loop should use the third constructor, using the String array you coded in FA8. (3 marks)
  4. answer:
  5. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

    /** * Write a description of class MyWorld here. * * @Bibek Shrestha(23653717) * @18/02/2018 */ public class MyWorld extends World { public static int score=0; private String i[] = {"good", "bad","normal"}; /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); } public static void main(String []args) { String[] array =new String[]{"good","bad","normal"}; int[] integerArray = new int[]{1,2,3,4,5,6,7,8,9,10,11}; int lastNumber=7; System.out.println(" value stored in the integer array at the index which equals the last number in student number is "+integerArray[7]); } public void act() { showScore(); example(); } public void addScore(int points)//it add the score. { score = score + points; showScore(); } public void showScore()//it shows the added score. { showText("score:" + score, 50, 25);

    } public void example() { } } this is world class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions