SlideShare a Scribd company logo
1 of 12
Download to read offline
please send edited code of RCBug.java
RCBUG.java
import java.util.Random;
public class RCBug {
private EZImage bugPicture; // Member variable to store bug picture
private int x, y, startx, starty; // Member variables to store x, y, startx, starty
private int destx, desty; // Member variables to store destination values
private long starttime; // Member variable to store the start time
private long duration; // Member variable to store the duration
private boolean interpolation; // Member variable that is set to true if it is in the
interpolation state
//1) add the private static final variables here
// Constructor for RCBug takes 3 parameters
public RCBug(String filename,int posx, int posy){
// Set the current position of the bug
x=posx;y=posy;
// Create the image of the bug
bugPicture = EZ.addImage(filename, posx, posy);
// Move it to the starting position. This is actually redundant.
bugPicture.translateTo(x,y);
// Set interpolation mode to false initially
interpolation = false;
}
// Set the destination by giving it 3 variables
// Dur means duration and is measured in seconds
public void setDestination(int posx, int posy, long dur){
// Set destination position and duration
// Convert seconds to miliseconds
destx = posx; desty = posy; duration = dur*1000;
// Get the startting time (i.e. time according to your computer)
starttime = System.currentTimeMillis();
// Set the starting position of your bug
startx=x; starty=y;
// Set interolation mode to true
interpolation = true;
}
// If you?re in interpolation state then return true, else false.
public boolean moving() {
return interpolation;
}
// This moves the bug based on the current time and elapsed time according to the
interpolation equation
public void go(){
// If interpolation mode is true then do interpolation
if (interpolation == true) {
// Normalize the time (i.e. make it a number from 0 to 1)
float normTime = (float) (System.currentTimeMillis() - starttime)/ (float) duration;
// Calculate the interpolated position of the bug
x = (int) (startx + ((float) (destx - startx) * normTime));
y = (int) (starty + ((float) (desty - starty) * normTime));
// If the difference between current time and start time has exceeded the duration
// then the animation/interpolation is over.
if ((System.currentTimeMillis() - starttime) >= duration) {
// Set interpolation to false
interpolation = false;
// Move the bug all the way to the destination
x = destx; y = desty;
}
//2)add a random amount to the x and y coordinates
// Don?t forget to move the image itself.
bugPicture.translateTo(x,y);
}
}
}
RCBugMain.java
import java.awt.Color;
import java.io.InputStreamReader;
import java.util.Scanner;
public class RCBugMain {
public static void main(String[] args) {
// Setup EZ graphics system.
EZ.initialize(512, 512);
// Set background color to dark green
EZ.setBackgroundColor(new Color(0, 100, 0));
// Make an InputStreamReader object which reads from the keyboard.
// Make a Scanner object that uses the InputStreamReader
Scanner scanner = new Scanner(new InputStreamReader(System.in));
// Set exit variable to false.
boolean exit = false;
// Create an RCBug object and give it the image and starting position
RCBug aBug = new RCBug("bug.png", 256,256);
// My do loop
do {
// Print the words: "Enter a command:"
System.out.print("Enter a command: ");
// Retrieve the first TOKEN the user types in
String command = scanner.next();
// Declare variables x,y,dur for later use.
int x, y;
int dur;
// Switch statement uses value in command to deside what to do.
switch(command) {
// If the command is "move"
case "move":
// Read first integer and store that in x.
x = scanner.nextInt();
// Read second integer and store that in y.
y = scanner.nextInt();
// Read third integer and store that in dur (duration).
dur = scanner.nextInt();
// Using my bug object call the member function setDestination and give
// it the parameter values x, y, and dur
aBug.setDestination(x, y, dur);
// Break out of switch statement.
break;
// If the command is quit
case "quit":
// Set the exit variable to true
exit = true;
// Break out of the switch statement.
break;
default:
// If I enter a wrong command print the following message:
System.out.println("Commands you can invoke are:");
System.out.println("move x y duration");
System.out.println("quit");
}
// While the bug should be moving...
while(aBug.moving()){
// Call the go member function of the bug to make it move.
aBug.go();
// Refresh the screen
EZ.refreshScreen();
}
// If exist is NOT true then keep looping.
} while(exit != true);
//Otherwise print BYE!
System.out.println("Bye!");
// Close the Scanner since I am done using it.
scanner.close();
}
}
Solution
I have updated the code in the appropriate places and formatted them in bold. Also explanation
of what happens when spread = 2, 25, 300 is at the very end
Here is the updated code for RCBug.java
package GUI;
import java.util.Random;
public class RCBug {
private EZImage bugPicture; // Member variable to store bug picture
private int x, y, startx, starty; // Member variables to store x, y, startx, starty
private int destx, desty; // Member variables to store destination values
private long starttime; // Member variable to store the start time
private long duration; // Member variable to store the duration
private boolean interpolation; // Member variable that is set to true if it is in the interpolation
state
private static final Random rand = new Random(); // Member variable that is to generate a
randome number
private static final int spread = 2; // spread varaible to mark the speed in which the bug moves
//1) add the private static final variables here
// Constructor for RCBug takes 3 parameters
public RCBug(String filename,int posx, int posy){
// Set the current position of the bug
x=posx;y=posy;
// Create the image of the bug
bugPicture = EZ.addImage(filename, posx, posy);
// Move it to the starting position. This is actually redundant.
bugPicture.translateTo(x,y);
// Set interpolation mode to false initially
interpolation = false;
}
// Set the destination by giving it 3 variables
// Dur means duration and is measured in seconds
public void setDestination(int posx, int posy, long dur){
// Set destination position and duration
// Convert seconds to miliseconds
destx = posx; desty = posy; duration = dur*1000;
// Get the startting time (i.e. time according to your computer)
starttime = System.currentTimeMillis();
// Set the starting position of your bug
startx=x; starty=y;
// Set interolation mode to true
interpolation = true;
}
// If you're in interpolation state then return true, else false.
public boolean moving() {
return interpolation;
}
// This moves the bug based on the current time and elapsed time according to the interpolation
equation
public void go(){
// If interpolation mode is true then do interpolation
if (interpolation == true) {
// Normalize the time (i.e. make it a number from 0 to 1)
float normTime = (float) (System.currentTimeMillis() - starttime)/ (float) duration;
// Calculate the interpolated position of the bug
x = (int) (startx + ((float) (destx - startx) * normTime));
y = (int) (starty + ((float) (desty - starty) * normTime));
// If the difference between current time and start time has exceeded the duration
// then the animation/interpolation is over.
if ((System.currentTimeMillis() - starttime) >= duration) {
// Set interpolation to false
interpolation = false;
// Move the bug all the way to the destination
x = destx; y = desty;
}
//2)add a random amount to the x and y coordinates
x+=rand.nextInt(spread)-spread/2;
y+=rand.nextInt(spread)-spread/2;
// Don't forget to move the image itself.
bugPicture.translateTo(x,y);
}
}
}
This is the updated code for RCBugMain.java
package GUI;
import java.awt.Color;
import java.io.InputStreamReader;
import java.util.Scanner;
public class RCBugMain {
public static void main(String[] args) {
// Setup EZ graphics system.
EZ.initialize(512, 512);
// Set background color to dark green
EZ.setBackgroundColor(new Color(0, 100, 0));
// Make an InputStreamReader object which reads from the keyboard.
// Make a Scanner object that uses the InputStreamReader
Scanner scanner = new Scanner(new InputStreamReader(System.in));
// Set exit variable to false.
boolean exit = false;
// Create an RCBug object and give it the image and starting position
RCBug aBug = new RCBug("D:UserskastukDesktopCheggbug.png", 256,256);
// My do loop
do {
// Print the words: "Enter a command:"
System.out.print("Enter a command: ");
// Retrieve the first TOKEN the user types in
String command = scanner.next();
// Declare variables x,y,dur for later use.
int x, y;
int dur;
// Switch statement uses value in command to deside what to do.
if(command.equals("move"))
{
x = scanner.nextInt();
// Read second integer and store that in y.
y = scanner.nextInt();
// Read third integer and store that in dur (duration).
dur = scanner.nextInt();
// Using my bug object call the member function setDestination and give
// it the parameter values x, y, and dur
aBug.setDestination(x, y, dur);
}
else if(command.equals("quit"))
{
exit = true;
}
else
{
System.out.println("Commands you can invoke are:");
System.out.println("move x y duration");
System.out.println("quit");
}
/* switch(command) {
// If the command is "move"
case "move":
// Read first integer and store that in x.
x = scanner.nextInt();
// Read second integer and store that in y.
y = scanner.nextInt();
// Read third integer and store that in dur (duration).
dur = scanner.nextInt();
// Using my bug object call the member function setDestination and give
// it the parameter values x, y, and dur
aBug.setDestination(x, y, dur);
// Break out of switch statement.
break;
// If the command is quit
case "quit":
// Set the exit variable to true
exit = true;
// Break out of the switch statement.
break;
default:
// If I enter a wrong command print the following message:
System.out.println("Commands you can invoke are:");
System.out.println("move x y duration");
System.out.println("quit");
}*/
// While the bug should be moving...
while(aBug.moving()){
// Call the go member function of the bug to make it move.
aBug.go();
// Refresh the screen
EZ.refreshScreen();
}
// If exist is NOT true then keep looping.
} while(exit != true);
//Otherwise print BYE!
System.out.println("Bye!");
// Close the Scanner since I am done using it.
scanner.close();
}
}
Observation on O/P:
The spread variable is responsible for the speed in which the bug moves from one position to
another.
When spread =2, the bug moves at a very slow pace.
when spread = 25, it moves at a moderate pace.
when spread = 300, it moves at a very faster pace with a distorting image.

More Related Content

Similar to please send edited code of RCBug.javaRCBUG.javaimport java.util..pdf

Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
forwarder.java.txt java forwarder class waits for an in.docx
forwarder.java.txt java forwarder class waits for an in.docxforwarder.java.txt java forwarder class waits for an in.docx
forwarder.java.txt java forwarder class waits for an in.docxbudbarber38650
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observablesStefan Charsley
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbroncymbron
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfamrishinda
 
TASK #1In the domain class you will create a loop that will prompt.pdf
TASK #1In the domain class you will create a loop that will prompt.pdfTASK #1In the domain class you will create a loop that will prompt.pdf
TASK #1In the domain class you will create a loop that will prompt.pdfindiaartz
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...Francesco Casalegno
 
Implementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresImplementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresGowtham Reddy
 
3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdfatozshoppe
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3Jieyi Wu
 

Similar to please send edited code of RCBug.javaRCBUG.javaimport java.util..pdf (20)

Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Class ‘increment’
Class ‘increment’Class ‘increment’
Class ‘increment’
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
forwarder.java.txt java forwarder class waits for an in.docx
forwarder.java.txt java forwarder class waits for an in.docxforwarder.java.txt java forwarder class waits for an in.docx
forwarder.java.txt java forwarder class waits for an in.docx
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
 
Microkernel Development
Microkernel DevelopmentMicrokernel Development
Microkernel Development
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdf
 
TASK #1In the domain class you will create a loop that will prompt.pdf
TASK #1In the domain class you will create a loop that will prompt.pdfTASK #1In the domain class you will create a loop that will prompt.pdf
TASK #1In the domain class you will create a loop that will prompt.pdf
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 
Implementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresImplementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphores
 
3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3
 
JavaScript Lessons 2023
JavaScript Lessons 2023JavaScript Lessons 2023
JavaScript Lessons 2023
 
Thread
ThreadThread
Thread
 

More from FashionBoutiquedelhi

Questions1) How does multimedia transmission differ than messag.pdf
Questions1) How does multimedia transmission differ than messag.pdfQuestions1) How does multimedia transmission differ than messag.pdf
Questions1) How does multimedia transmission differ than messag.pdfFashionBoutiquedelhi
 
Question 1 of 10 Map sapling learning Based on the chart to the right.pdf
Question 1 of 10 Map sapling learning Based on the chart to the right.pdfQuestion 1 of 10 Map sapling learning Based on the chart to the right.pdf
Question 1 of 10 Map sapling learning Based on the chart to the right.pdfFashionBoutiquedelhi
 
On January 1, 2002, Germany officially adopted the euro as its curre.pdf
On January 1, 2002, Germany officially adopted the euro as its curre.pdfOn January 1, 2002, Germany officially adopted the euro as its curre.pdf
On January 1, 2002, Germany officially adopted the euro as its curre.pdfFashionBoutiquedelhi
 
Networking problem help Consider the following TCP session between h.pdf
Networking problem help Consider the following TCP session between h.pdfNetworking problem help Consider the following TCP session between h.pdf
Networking problem help Consider the following TCP session between h.pdfFashionBoutiquedelhi
 
Lipid bilayers can only be synthesized by biological organisms. This .pdf
Lipid bilayers can only be synthesized by biological organisms. This .pdfLipid bilayers can only be synthesized by biological organisms. This .pdf
Lipid bilayers can only be synthesized by biological organisms. This .pdfFashionBoutiquedelhi
 
Is a neutral trait (meaning it is neither deleterious nor advantageo.pdf
Is a neutral trait (meaning it is neither deleterious nor advantageo.pdfIs a neutral trait (meaning it is neither deleterious nor advantageo.pdf
Is a neutral trait (meaning it is neither deleterious nor advantageo.pdfFashionBoutiquedelhi
 
Let T R^n rightarrow R^m be a linear transformation. Given a subspa.pdf
Let T  R^n rightarrow R^m be a linear transformation. Given a subspa.pdfLet T  R^n rightarrow R^m be a linear transformation. Given a subspa.pdf
Let T R^n rightarrow R^m be a linear transformation. Given a subspa.pdfFashionBoutiquedelhi
 
Just a general question on some vocab words I cannot piece together .pdf
Just a general question on some vocab words I cannot piece together .pdfJust a general question on some vocab words I cannot piece together .pdf
Just a general question on some vocab words I cannot piece together .pdfFashionBoutiquedelhi
 
In order to be useful to managers, management accounting reports shou.pdf
In order to be useful to managers, management accounting reports shou.pdfIn order to be useful to managers, management accounting reports shou.pdf
In order to be useful to managers, management accounting reports shou.pdfFashionBoutiquedelhi
 
Im also confused on question 9 and 10 On which point(s) would Charle.pdf
Im also confused on question 9 and 10 On which point(s) would Charle.pdfIm also confused on question 9 and 10 On which point(s) would Charle.pdf
Im also confused on question 9 and 10 On which point(s) would Charle.pdfFashionBoutiquedelhi
 
In about six billion years, our suns luminosity (a.k.a. power outpu.pdf
In about six billion years, our suns luminosity (a.k.a. power outpu.pdfIn about six billion years, our suns luminosity (a.k.a. power outpu.pdf
In about six billion years, our suns luminosity (a.k.a. power outpu.pdfFashionBoutiquedelhi
 
I have to write a java program . So basically I have to take my in.pdf
I have to write a java program . So basically I have to take my in.pdfI have to write a java program . So basically I have to take my in.pdf
I have to write a java program . So basically I have to take my in.pdfFashionBoutiquedelhi
 
Fill in the blanks.Intensity of orangebrownred color of reduced .pdf
Fill in the blanks.Intensity of orangebrownred color of reduced .pdfFill in the blanks.Intensity of orangebrownred color of reduced .pdf
Fill in the blanks.Intensity of orangebrownred color of reduced .pdfFashionBoutiquedelhi
 
Explain how cellular respiration (O2 consumption and CO2 production).pdf
Explain how cellular respiration (O2 consumption and CO2 production).pdfExplain how cellular respiration (O2 consumption and CO2 production).pdf
Explain how cellular respiration (O2 consumption and CO2 production).pdfFashionBoutiquedelhi
 
Entrepreneurship isA. one of the basic rights of the private enter.pdf
Entrepreneurship isA. one of the basic rights of the private enter.pdfEntrepreneurship isA. one of the basic rights of the private enter.pdf
Entrepreneurship isA. one of the basic rights of the private enter.pdfFashionBoutiquedelhi
 
Discrete Random Variables we are working with commonly used discre.pdf
Discrete Random Variables we are working with commonly used discre.pdfDiscrete Random Variables we are working with commonly used discre.pdf
Discrete Random Variables we are working with commonly used discre.pdfFashionBoutiquedelhi
 
Determine the open intervals over which the function is increasing an.pdf
Determine the open intervals over which the function is increasing an.pdfDetermine the open intervals over which the function is increasing an.pdf
Determine the open intervals over which the function is increasing an.pdfFashionBoutiquedelhi
 
Discuss and define Isotropy. Anisotropy and Orthotropy with regards t.pdf
Discuss and define Isotropy. Anisotropy and Orthotropy with regards t.pdfDiscuss and define Isotropy. Anisotropy and Orthotropy with regards t.pdf
Discuss and define Isotropy. Anisotropy and Orthotropy with regards t.pdfFashionBoutiquedelhi
 
Consider the circuits in figure 2.32. If we assume the transistors ar.pdf
Consider the circuits in figure 2.32. If we assume the transistors ar.pdfConsider the circuits in figure 2.32. If we assume the transistors ar.pdf
Consider the circuits in figure 2.32. If we assume the transistors ar.pdfFashionBoutiquedelhi
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfFashionBoutiquedelhi
 

More from FashionBoutiquedelhi (20)

Questions1) How does multimedia transmission differ than messag.pdf
Questions1) How does multimedia transmission differ than messag.pdfQuestions1) How does multimedia transmission differ than messag.pdf
Questions1) How does multimedia transmission differ than messag.pdf
 
Question 1 of 10 Map sapling learning Based on the chart to the right.pdf
Question 1 of 10 Map sapling learning Based on the chart to the right.pdfQuestion 1 of 10 Map sapling learning Based on the chart to the right.pdf
Question 1 of 10 Map sapling learning Based on the chart to the right.pdf
 
On January 1, 2002, Germany officially adopted the euro as its curre.pdf
On January 1, 2002, Germany officially adopted the euro as its curre.pdfOn January 1, 2002, Germany officially adopted the euro as its curre.pdf
On January 1, 2002, Germany officially adopted the euro as its curre.pdf
 
Networking problem help Consider the following TCP session between h.pdf
Networking problem help Consider the following TCP session between h.pdfNetworking problem help Consider the following TCP session between h.pdf
Networking problem help Consider the following TCP session between h.pdf
 
Lipid bilayers can only be synthesized by biological organisms. This .pdf
Lipid bilayers can only be synthesized by biological organisms. This .pdfLipid bilayers can only be synthesized by biological organisms. This .pdf
Lipid bilayers can only be synthesized by biological organisms. This .pdf
 
Is a neutral trait (meaning it is neither deleterious nor advantageo.pdf
Is a neutral trait (meaning it is neither deleterious nor advantageo.pdfIs a neutral trait (meaning it is neither deleterious nor advantageo.pdf
Is a neutral trait (meaning it is neither deleterious nor advantageo.pdf
 
Let T R^n rightarrow R^m be a linear transformation. Given a subspa.pdf
Let T  R^n rightarrow R^m be a linear transformation. Given a subspa.pdfLet T  R^n rightarrow R^m be a linear transformation. Given a subspa.pdf
Let T R^n rightarrow R^m be a linear transformation. Given a subspa.pdf
 
Just a general question on some vocab words I cannot piece together .pdf
Just a general question on some vocab words I cannot piece together .pdfJust a general question on some vocab words I cannot piece together .pdf
Just a general question on some vocab words I cannot piece together .pdf
 
In order to be useful to managers, management accounting reports shou.pdf
In order to be useful to managers, management accounting reports shou.pdfIn order to be useful to managers, management accounting reports shou.pdf
In order to be useful to managers, management accounting reports shou.pdf
 
Im also confused on question 9 and 10 On which point(s) would Charle.pdf
Im also confused on question 9 and 10 On which point(s) would Charle.pdfIm also confused on question 9 and 10 On which point(s) would Charle.pdf
Im also confused on question 9 and 10 On which point(s) would Charle.pdf
 
In about six billion years, our suns luminosity (a.k.a. power outpu.pdf
In about six billion years, our suns luminosity (a.k.a. power outpu.pdfIn about six billion years, our suns luminosity (a.k.a. power outpu.pdf
In about six billion years, our suns luminosity (a.k.a. power outpu.pdf
 
I have to write a java program . So basically I have to take my in.pdf
I have to write a java program . So basically I have to take my in.pdfI have to write a java program . So basically I have to take my in.pdf
I have to write a java program . So basically I have to take my in.pdf
 
Fill in the blanks.Intensity of orangebrownred color of reduced .pdf
Fill in the blanks.Intensity of orangebrownred color of reduced .pdfFill in the blanks.Intensity of orangebrownred color of reduced .pdf
Fill in the blanks.Intensity of orangebrownred color of reduced .pdf
 
Explain how cellular respiration (O2 consumption and CO2 production).pdf
Explain how cellular respiration (O2 consumption and CO2 production).pdfExplain how cellular respiration (O2 consumption and CO2 production).pdf
Explain how cellular respiration (O2 consumption and CO2 production).pdf
 
Entrepreneurship isA. one of the basic rights of the private enter.pdf
Entrepreneurship isA. one of the basic rights of the private enter.pdfEntrepreneurship isA. one of the basic rights of the private enter.pdf
Entrepreneurship isA. one of the basic rights of the private enter.pdf
 
Discrete Random Variables we are working with commonly used discre.pdf
Discrete Random Variables we are working with commonly used discre.pdfDiscrete Random Variables we are working with commonly used discre.pdf
Discrete Random Variables we are working with commonly used discre.pdf
 
Determine the open intervals over which the function is increasing an.pdf
Determine the open intervals over which the function is increasing an.pdfDetermine the open intervals over which the function is increasing an.pdf
Determine the open intervals over which the function is increasing an.pdf
 
Discuss and define Isotropy. Anisotropy and Orthotropy with regards t.pdf
Discuss and define Isotropy. Anisotropy and Orthotropy with regards t.pdfDiscuss and define Isotropy. Anisotropy and Orthotropy with regards t.pdf
Discuss and define Isotropy. Anisotropy and Orthotropy with regards t.pdf
 
Consider the circuits in figure 2.32. If we assume the transistors ar.pdf
Consider the circuits in figure 2.32. If we assume the transistors ar.pdfConsider the circuits in figure 2.32. If we assume the transistors ar.pdf
Consider the circuits in figure 2.32. If we assume the transistors ar.pdf
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

please send edited code of RCBug.javaRCBUG.javaimport java.util..pdf

  • 1. please send edited code of RCBug.java RCBUG.java import java.util.Random; public class RCBug { private EZImage bugPicture; // Member variable to store bug picture private int x, y, startx, starty; // Member variables to store x, y, startx, starty private int destx, desty; // Member variables to store destination values private long starttime; // Member variable to store the start time private long duration; // Member variable to store the duration private boolean interpolation; // Member variable that is set to true if it is in the interpolation state //1) add the private static final variables here // Constructor for RCBug takes 3 parameters public RCBug(String filename,int posx, int posy){ // Set the current position of the bug x=posx;y=posy; // Create the image of the bug bugPicture = EZ.addImage(filename, posx, posy); // Move it to the starting position. This is actually redundant. bugPicture.translateTo(x,y); // Set interpolation mode to false initially interpolation = false; } // Set the destination by giving it 3 variables // Dur means duration and is measured in seconds public void setDestination(int posx, int posy, long dur){ // Set destination position and duration
  • 2. // Convert seconds to miliseconds destx = posx; desty = posy; duration = dur*1000; // Get the startting time (i.e. time according to your computer) starttime = System.currentTimeMillis(); // Set the starting position of your bug startx=x; starty=y; // Set interolation mode to true interpolation = true; } // If you?re in interpolation state then return true, else false. public boolean moving() { return interpolation; } // This moves the bug based on the current time and elapsed time according to the interpolation equation public void go(){ // If interpolation mode is true then do interpolation if (interpolation == true) { // Normalize the time (i.e. make it a number from 0 to 1) float normTime = (float) (System.currentTimeMillis() - starttime)/ (float) duration; // Calculate the interpolated position of the bug x = (int) (startx + ((float) (destx - startx) * normTime)); y = (int) (starty + ((float) (desty - starty) * normTime));
  • 3. // If the difference between current time and start time has exceeded the duration // then the animation/interpolation is over. if ((System.currentTimeMillis() - starttime) >= duration) { // Set interpolation to false interpolation = false; // Move the bug all the way to the destination x = destx; y = desty; } //2)add a random amount to the x and y coordinates // Don?t forget to move the image itself. bugPicture.translateTo(x,y); } } } RCBugMain.java import java.awt.Color; import java.io.InputStreamReader; import java.util.Scanner; public class RCBugMain { public static void main(String[] args) { // Setup EZ graphics system. EZ.initialize(512, 512); // Set background color to dark green EZ.setBackgroundColor(new Color(0, 100, 0)); // Make an InputStreamReader object which reads from the keyboard. // Make a Scanner object that uses the InputStreamReader Scanner scanner = new Scanner(new InputStreamReader(System.in));
  • 4. // Set exit variable to false. boolean exit = false; // Create an RCBug object and give it the image and starting position RCBug aBug = new RCBug("bug.png", 256,256); // My do loop do { // Print the words: "Enter a command:" System.out.print("Enter a command: "); // Retrieve the first TOKEN the user types in String command = scanner.next(); // Declare variables x,y,dur for later use. int x, y; int dur; // Switch statement uses value in command to deside what to do. switch(command) { // If the command is "move" case "move": // Read first integer and store that in x. x = scanner.nextInt(); // Read second integer and store that in y. y = scanner.nextInt(); // Read third integer and store that in dur (duration). dur = scanner.nextInt(); // Using my bug object call the member function setDestination and give // it the parameter values x, y, and dur aBug.setDestination(x, y, dur);
  • 5. // Break out of switch statement. break; // If the command is quit case "quit": // Set the exit variable to true exit = true; // Break out of the switch statement. break; default: // If I enter a wrong command print the following message: System.out.println("Commands you can invoke are:"); System.out.println("move x y duration"); System.out.println("quit"); } // While the bug should be moving... while(aBug.moving()){ // Call the go member function of the bug to make it move. aBug.go(); // Refresh the screen EZ.refreshScreen(); } // If exist is NOT true then keep looping. } while(exit != true); //Otherwise print BYE! System.out.println("Bye!");
  • 6. // Close the Scanner since I am done using it. scanner.close(); } } Solution I have updated the code in the appropriate places and formatted them in bold. Also explanation of what happens when spread = 2, 25, 300 is at the very end Here is the updated code for RCBug.java package GUI; import java.util.Random; public class RCBug { private EZImage bugPicture; // Member variable to store bug picture private int x, y, startx, starty; // Member variables to store x, y, startx, starty private int destx, desty; // Member variables to store destination values private long starttime; // Member variable to store the start time private long duration; // Member variable to store the duration private boolean interpolation; // Member variable that is set to true if it is in the interpolation state private static final Random rand = new Random(); // Member variable that is to generate a randome number private static final int spread = 2; // spread varaible to mark the speed in which the bug moves //1) add the private static final variables here // Constructor for RCBug takes 3 parameters public RCBug(String filename,int posx, int posy){ // Set the current position of the bug x=posx;y=posy; // Create the image of the bug bugPicture = EZ.addImage(filename, posx, posy); // Move it to the starting position. This is actually redundant. bugPicture.translateTo(x,y); // Set interpolation mode to false initially
  • 7. interpolation = false; } // Set the destination by giving it 3 variables // Dur means duration and is measured in seconds public void setDestination(int posx, int posy, long dur){ // Set destination position and duration // Convert seconds to miliseconds destx = posx; desty = posy; duration = dur*1000; // Get the startting time (i.e. time according to your computer) starttime = System.currentTimeMillis(); // Set the starting position of your bug startx=x; starty=y; // Set interolation mode to true interpolation = true; } // If you're in interpolation state then return true, else false. public boolean moving() { return interpolation; } // This moves the bug based on the current time and elapsed time according to the interpolation equation public void go(){ // If interpolation mode is true then do interpolation if (interpolation == true) { // Normalize the time (i.e. make it a number from 0 to 1) float normTime = (float) (System.currentTimeMillis() - starttime)/ (float) duration;
  • 8. // Calculate the interpolated position of the bug x = (int) (startx + ((float) (destx - startx) * normTime)); y = (int) (starty + ((float) (desty - starty) * normTime)); // If the difference between current time and start time has exceeded the duration // then the animation/interpolation is over. if ((System.currentTimeMillis() - starttime) >= duration) { // Set interpolation to false interpolation = false; // Move the bug all the way to the destination x = destx; y = desty; } //2)add a random amount to the x and y coordinates x+=rand.nextInt(spread)-spread/2; y+=rand.nextInt(spread)-spread/2; // Don't forget to move the image itself. bugPicture.translateTo(x,y); } } } This is the updated code for RCBugMain.java package GUI; import java.awt.Color; import java.io.InputStreamReader; import java.util.Scanner; public class RCBugMain { public static void main(String[] args) { // Setup EZ graphics system.
  • 9. EZ.initialize(512, 512); // Set background color to dark green EZ.setBackgroundColor(new Color(0, 100, 0)); // Make an InputStreamReader object which reads from the keyboard. // Make a Scanner object that uses the InputStreamReader Scanner scanner = new Scanner(new InputStreamReader(System.in)); // Set exit variable to false. boolean exit = false; // Create an RCBug object and give it the image and starting position RCBug aBug = new RCBug("D:UserskastukDesktopCheggbug.png", 256,256); // My do loop do { // Print the words: "Enter a command:" System.out.print("Enter a command: "); // Retrieve the first TOKEN the user types in String command = scanner.next(); // Declare variables x,y,dur for later use. int x, y; int dur; // Switch statement uses value in command to deside what to do. if(command.equals("move")) { x = scanner.nextInt(); // Read second integer and store that in y. y = scanner.nextInt(); // Read third integer and store that in dur (duration).
  • 10. dur = scanner.nextInt(); // Using my bug object call the member function setDestination and give // it the parameter values x, y, and dur aBug.setDestination(x, y, dur); } else if(command.equals("quit")) { exit = true; } else { System.out.println("Commands you can invoke are:"); System.out.println("move x y duration"); System.out.println("quit"); } /* switch(command) { // If the command is "move" case "move": // Read first integer and store that in x. x = scanner.nextInt(); // Read second integer and store that in y. y = scanner.nextInt(); // Read third integer and store that in dur (duration). dur = scanner.nextInt(); // Using my bug object call the member function setDestination and give // it the parameter values x, y, and dur aBug.setDestination(x, y, dur); // Break out of switch statement. break;
  • 11. // If the command is quit case "quit": // Set the exit variable to true exit = true; // Break out of the switch statement. break; default: // If I enter a wrong command print the following message: System.out.println("Commands you can invoke are:"); System.out.println("move x y duration"); System.out.println("quit"); }*/ // While the bug should be moving... while(aBug.moving()){ // Call the go member function of the bug to make it move. aBug.go(); // Refresh the screen EZ.refreshScreen(); } // If exist is NOT true then keep looping. } while(exit != true); //Otherwise print BYE! System.out.println("Bye!"); // Close the Scanner since I am done using it. scanner.close(); }
  • 12. } Observation on O/P: The spread variable is responsible for the speed in which the bug moves from one position to another. When spread =2, the bug moves at a very slow pace. when spread = 25, it moves at a moderate pace. when spread = 300, it moves at a very faster pace with a distorting image.