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
An intranet is an external network.TrueFalse
maria [59]

Answer:

False

Explanation:

An intranet is not an external network.

An intranet is an internal network which is established by an organization for its own use.

External people can not access the Intranet unlike the internet which is accessible to every one.

An organization owns a private network which is called an intranet. Private means that the network is accessible to all those employed within the organization, staff of the company.

Intranet exists only within the company and indicates the following.

1. The company establishes its own network inside the company so that the staff of the company can access and exchange information among themselves.

2. The staff can communicate and have discussions on the network.

3. The information is not accessible to outside parties such as customers, stakeholders, and others.

4. The network is not accessible and does not exists for the outside parties.

5. The term intra means inside and net means network.

Intranet leads to the following benefits.

1. The staff can view and exchange information with more ease and comfort and in less time.

2. Faster access to information increases employee output. Employees can perform better and have more time to focus on their work.

3. Communication among the employees is encouraged and made easy. Any one can communicate with every one in the company.

4. More communication leads to better working relationships among the staff. Cooperation and collaboration among the staff is given a boost.

5. Staff can give their input for the type of information to be held in the respository. This serves as the single point of information which enables smooth work flow.

Intranet also has some drawbacks.

The employees can take undue advantage of this communication channel for personal communications and information exchange.

Unproductive communication can only hamper the culture of the workplace.

Guidelines should be enforced to avoid unnecessary communication.

3 0
3 years ago
What’s some WiFi passwords for some big brands that I can connect to while traveling?
Wewaii [24]

Answer:

download the app instabridge.

With Instabridge you get more than a million up-to-date WiFi passwords and spots on your phone.

7 0
3 years ago
which of the following are good ways for virtual team members to get to know one another? (choose every correct answer.)
pav-90 [236]

what are the choicess

8 0
2 years ago
Designing advanced power systems for naval vessels is an example of nuclear engineering.
Ugo [173]

The answer to your question is,

True.

-Mabel <3

7 0
3 years ago
Read 2 more answers
Is there any website online to use android studio live?​
slavikrds [6]

Answer:

May bhe here

https://developer.android.com/studio/intro

Explanation:

5 0
3 years ago
Other questions:
  • Jerry is making an address book using a digital database. He has a list of his immediate family and friends but wants to add a f
    9·2 answers
  • . Write a swift programming code to perform following tasks a) Declare a variable that stores the age of a person b) Declare a c
    5·1 answer
  • What is the multiple source test
    15·1 answer
  • Given an initialized String variable outfile, write a statement that declares a PrintWriter reference variable named output and
    12·1 answer
  • When you are working in Performance Monitor, in the "Add Counters" dialog box, and need more information about a particular coun
    8·1 answer
  • Edhesive 9.3 code practice
    11·1 answer
  • Caps lock key is used to type alphabets. _________​
    6·2 answers
  • What is the purpose of extent in lines in engineering drawing
    12·1 answer
  • Naseer has inserted an image into his document but needs the image to appear on its own line.
    8·1 answer
  • By definition, what is the process of reducing security exposure and tightening security controls?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!