Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IN JAVA PART A PART B 16 /** 2 A class that simulates a moth flying. */ public class Moth public private double position; 7
IN JAVA
PART A
PART B
16 /** 2 A class that simulates a moth flying. */ public class Moth public private double position; 7 /** 9 Initializes the moth given a position. 10 @param initialPosition the initial position 11 */ 12 public Moth(double initialPosition) 13 { 14 -Start below here. To do: approximate lines of code = 1 15 // set the position to the given parameter initialPosition 16 17 -End here. Please do not remove this comment. Reminder: no changes outside the todo regions. 18 } 19 20 /** 21 Moves the moth halfway to the lightPosition. 22 */ 23 public void moveToLight (double lightposition) 24 25 11 -Start below here. To do: approximate lines of code = 1 26 1/ update the current position to be halfway to (i.e. closer so position should be getting smaller) the light Position 27 28 17 -End here. Please do not remove this comment. Reminder: no changes outside the todo regions. 29 } 30 316 /** 32 Reports the current position of the moth. 33 @return the current position 34 */ 35 public double getPosition() 36 37 return position; 38 } 39 40 public static void main(String[] args) 41 42 Moth myMoth = new Moth(10); 43 myMoth.moveToLight (20); System.out.println("Expected position 15.0; Current position + myMoth.getPosition(); 45 myMoth.moveToLight(0); 46 System.out.println("Expected position 7.5; Current position" + myMoth.getPosition()); 47 myMoth.moveToLight(0); 48 System.out.println("Expected position 3.75; Current position" + myMoth.getPosition()); 49 myMoth.moveToLight(0); 50 System.out.println("Expected position 1.875: Current position" + myMoth.getPosition()); 51 } 52 } 44 1 import java.util.ArrayList; 3e /ok 4 A class that keeps track of a dynamic menu. */ 6 public class Menu 7 { private ArrayListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started