Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 3 - Magical Gardens In the magical world of Narnia, there is a gardener

ID: 3756523 • Letter: P

Question

Problem 3 - Magical Gardens In the magical world of Narnia, there is a gardener who specializes in growing infinitely large gardens. These gardens have two interesting properties. First, they have a fixed width, although their length is infinite. Second, the trees are planted row by row and each new tree grows 1 meter taller than the previous one. Different gardens may have different widths; the figure shows a garden of width 4. Assuming that the top-left position is the origin of coordinates : 0, Y: 0), with X axis increasing right and Y axis increasing down. your program should determine the height of a tree, given its coordinates as inputs. You will, of course, need to ask the width of the garden first. 9 10 11 12 BiueJ: Terminal Window Magical Gardens... What is the width of the garden: 6 X coordinate of the tree: 4 Y coordinate of the tree: 3 13 A sample execution might lookThe height of the tree is 23 like the one pictured to the right: Submitting your assignment: As for AS1, submit a single zip file containing the BlueJ project folders for all 3 problems using the link provided on our Moodle page. Name your zip file using the format: as2 YourName.zip (using your own name)

Explanation / Answer

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class prime

{

public static void main (String[] args)

{

Scanner sc=new Scanner(System.in);

int width=sc.nextInt();

int x=sc.nextInt();

int y=sc.nextInt();

int p=0,c=0;

for(int i=0;i<=y;i++) //because y axis is increasing downwards

{

for(int j=0;j<width;j++) //count of columns

{

c++; //counter running

if(i==y && j==x) //checking if counter has reached given x and y

{

p=-1;break; // p is just a check variable

}

}

if(p==-1)break; //if p value is chaned in previous loop we quit the loop

}

System.out.println(c); //printing the height of the tree

// your code goes here

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote