1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
motikmotik
2 years ago
13

Write a class Bug that models a bug moving along a horizontal line. The bug moves either to the right or left. Initially, the bu

g moves to the right, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. Provide a constructor
Computers and Technology
1 answer:
Zinaida [17]2 years ago
5 0

Answer:

Following are the constructor to the given code:

Bug(int position) //defining a constructor that defines a integer parameters

{

       this.position = position;//use this key word to hold parameter value

       right = true;//defining a variable right that hold a boolean value

   }

Explanation:

In this code, a constructor is declared that defines integer parameters with it, Inside the constructor, this keyword is used to holds the "position" parameter value and defines a boolean variable "right" that holds a boolean value.

Full program:

public class Bug //declaring a class Bug

{

   private int position;//declaring integer variable position

   private boolean right;//declaring boolean variable

   public Bug(int position) //defining a parameterized constructor

   {

       this.position = position;//use this to hold position value

       right = true;//holding boolean value

   }

   public void turn() //defining a method turn

   {

       right = !right;//holding value

   }

   public void move() //defining method move

   {

       if(right)//use if to check boolean value

       {

           position++;//incrementing position value

       }  

       else//else block

       {

           position--;//decreasing position value

       }

   }

   public int getPosition()//defining method getPosition  

   {

       return position;//return position value

   }

   public static void main(String[] args) //main method

   {

       Bug bug = new Bug(10);//creating class object

       System.out.println("Expected = 10, Actual = " + bug.getPosition());//calling method with printing value

       bug.move();//calling method

       System.out.println("Expected = 11, Actual = " + bug.getPosition());//calling method with printing value

       bug.move();//calling method

       bug.move();//calling method

       bug.move();//calling method

       System.out.println("Expected = 14, Actual = " + bug.getPosition());//calling method with printing value

       bug.turn();//calling method

       bug.move();//calling method

       bug.move();//calling method

       System.out.println("Expected = 12, Actual = " + bug.getPosition());//calling method with printing value

       bug.turn();//calling method

       bug.move();//calling method

       System.out.println("Expected = 13, Actual = " + bug.getPosition());//calling method with printing value

   }

}

Output:

Please find the attached file.

You might be interested in
Which one of the following oscilloscope controls is used to move the trace up and down the screen vertically
kakasveta [241]
B. is the answer to this question
3 0
3 years ago
PLEASE HELP ASAP! WILL MARK BRAINLIEST IF THE ANSWER IS CORRECT! I NEED HELP WITH THE 3RD ONE!
Bogdan [553]

Answer:

Explanation:

.1 Display all information from the customer table for all customers that have a balance that is greater than the average balance.

2. Display all information from the rep table for all representatives that have a rate which is equal to the minimum rate for representatives.

3. Display each unique description and price (no duplicates) for all parts that have a quoted price that is greater than the average quoted price for all parts ordered.

4. List all streets where either a customer or a representative is located

5 0
3 years ago
Question 1 of 19
shusha [124]

Answer:

UI Character Presets

Explanation:

User Interface is an option or go-to menu in a desktop application. For example, Photoshop. It allows a user to tweak the outlook to his or her own preference rather than the default settings.

To do this, a user is often tasked to do the following:

1. Click on the "Edit" menu

2. Navigate and click on "Preferences"

3. Select the "Interface" link

The options available to change includes:

a. UI Scaling

b. UI Font Size

c. UI Language.

Hence, in this case, the element that is not a selection in the Interface preferences is "UI Character preset"

7 0
3 years ago
Which of the following is good practice to ensure that you do not get malware on your computer from an online source?
Lina20 [59]

Answer:

go to a authorised site which is secure

Explanation:

5 0
3 years ago
Urgent. I will mark you brainliest. explain why cyber warfare is a real threat.​
stellarik [79]

Answer: Cyber warfare is a real threat since being able to hack another computer especially a countries computer with lots of info in their weaknesses can lead to their downfall. Since they can even possibly if their skilled enough hack their entire data base system and leak it to the public and that wouldn't be good for them not in a single possible way. That's the reason it's dangerous not only that but also because they can access their servers; which can let them access anything online from the whole country including banking information military info which can let them know which area there gonna go to next equipment there gonna bring and where they're gonna launch missiles, bombs, even nukes if they decide to launch one. And being able to hijack the computer that launches the nukes can make the hacker launch the nuke to a different place or launch the nuke on the country trying to launch the nuke.

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • In Linux, the most popular remote access tool is OpenSSH. Which software performs the same remote command line (CLI) access from
    7·1 answer
  • What is the maximum number of colors that should be used on a slide?
    5·2 answers
  • What do work places allow a company to do
    12·1 answer
  • In a game, your character cleverly places an electronic bug on an unsuspecting felon's jacket to track his movements. The bug tr
    10·2 answers
  • Identify the four basic categories of hardware in a microcomputer system. system unit, modem, ram, and microprocessor system uni
    5·1 answer
  • Order the steps to take when drawing electron dot diagrams.
    15·2 answers
  • A _____ refers to a product or service, such as a technical report, a training session, a piece of hardware, or a segment of sof
    12·2 answers
  • By what decade were books readily available to the public across the United States and Europe?
    7·1 answer
  • Explain why a holiday on a cruise liner will be an ideal holiday​
    12·1 answer
  • What feature preserves your open apps and data, but allows another user to log in to his or her own session of the same computer
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!