Question

Implement a class Moth that models a moth flying along a straight line. The moth has...

Implement a class Moth that models a moth flying along a straight line. The moth has a position which is the distance from a fixed origin. When the moth moves toward a point of light its new position is halfway between its old position and the position of the light source.

public Moth(double initialPosition)
public void moveToLight(double lightPosition)
public double getPosition()

Homework Answers

Answer #1

All Class are Implemented in Java and executed

import java.io.*;
import java.util.*;
class Moth
{
private double position;
public Moth(double initialPostion)
{
position = initialPostion;
}
public void moveToLight(double lightPosition)
{
position = (position + lightPosition);
}

public double getPosition()
{
return position;
}
}
public class MothTester
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Initial Position");
int n = sc.nextInt();
System.out.println("Enter New Position");
float b = sc.nextFloat();
Moth moth = new Moth(n);
System.out.println("Initial Position of the Moth =" +moth.getPosition());
moth.moveToLight(b);
System.out.println("New Position of Moth =" +moth.getPosition());
}
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A car moves along a straight line with velocity, in feet/second, given by v(t)=35-5t for t≥0....
A car moves along a straight line with velocity, in feet/second, given by v(t)=35-5t for t≥0. (a) With forward being the direction of positive velocity, when is the car moving forward? Backward? Stopped? The car is moving forward for ≤t< . The car is moving backward for t> . The car is not moving at the instant t= . (b) Does the car ever return to its starting point? If so, when? If the car never returns to its starting...
Anna and Bonnie are located on a straight line in the following way: Anna is standing...
Anna and Bonnie are located on a straight line in the following way: Anna is standing at the origin of the x-axis and when Bonnie is located 20 m away in the positive x direction, running at the constant speed of 4.6m/s toward Anna, Anna begins running toward Bonnie with a constant acceleration of 1.8m/s2 . (a) Using the diagram below, provide all information given (i.e. Anna’s and Bonnie’s initial velocities and accelerations, marking any vectors in the diagram corresponding...
Compile and execute the application. You will discover that is has a bug in it -...
Compile and execute the application. You will discover that is has a bug in it - the filled checkbox has no effect - filled shapes are not drawn. Your first task is to debug the starter application so that it correctly draws filled shapes. The bug can be corrected with three characters at one location in the code. Java 2D introduces many new capabilities for creating unique and impressive graphics. We’ll add a small subset of these features to the...
Item 1 In the case below, the original source material is given along with a sample...
Item 1 In the case below, the original source material is given along with a sample of student work. Determine the type of plagiarism by clicking the appropriate radio button. Original Source Material Student Version There is a design methodology called rapid prototyping, which has been used successfully in software engineering. Given similarities between software design and instructional design, we argue that rapid prototyping is a viable method for instructional design, especially for computer-based instruction. References: Tripp, S. D., &...
Item 1 In the case below, the original source material is given along with a sample...
Item 1 In the case below, the original source material is given along with a sample of student work. Determine the type of plagiarism by clicking the appropriate radio button. Original Source Material Student Version There is a desperate need for theorists and researchers to generate and refine a new breed of learning-focused instructional design theoriesthat help educators and trainers to meet those needs, (i.e., that focus on learning and that foster development of initiative, teamwork, thinking skills, and diversity)....
Item 1 In the case below, the original source material is given along with a sample...
Item 1 In the case below, the original source material is given along with a sample of student work. Determine the type of plagiarism by clicking the appropriate radio button. Original Source Material Student Version I accept the point that whenever learning occurs, some medium or mix of media must be present to deliver instruction. However, if learning occurs as a result of exposure to any media, the learning is caused by the instructional method embedded in the media presentation....
Item 1 In the case below, the original source material is given along with a sample...
Item 1 In the case below, the original source material is given along with a sample of student work. Determine the type of plagiarism by clicking the appropriate radio button. Original Source Material Student Version Major changes within organizations are usually initiated by those who are in power. Such decision-makers sponsor the change and then appoint someone else - perhaps the director of training - to be responsible for implementing and managing change. Whether the appointed change agent is in...
These tests are intended for undergraduate students in college or those under 18 years of age....
These tests are intended for undergraduate students in college or those under 18 years of age. Read these directions carefully! The below test includes 10 questions, randomly selected from a large inventory. Most questions will be different each time you take the test, You must answer at least 9 out of 10 questions correctly to receive your Certificate. You have 40 minutes to complete each test, and you must answer all 10 questions in order to to see your results....
ch 6 1: It is generally a good idea to gain an understanding of the "size"...
ch 6 1: It is generally a good idea to gain an understanding of the "size" of units. Consider the objects and calculate the kinetic energy of each one. A ladybug weighing 37.3 mg flies by your head at 3.83 km/h . ×10 J A 7.15 kg bowling ball slides (not rolls) down an alley at 17.5 km/h . J A car weighing 1260 kg moves at a speed of 49.5 km/h. 5: The graph shows the ?-directed force ??...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons for the failure and how did the breakdown harm Nike? 2. What are the important elements to be kept in mind while implementing a new system in an organization? What is the importance of a good working relationship between partners and the sharing of responsibility in implementing critical projects? What mistakes did Nike and i2 make? 3. comment on the lessons learned and the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT