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
Nadusha1986 [10]
3 years ago
7

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 public Bug(int initialPosition) and methods public void turnC * public void move( °public int getPositionO Sample usage: Bug bugsy new Bug(10) bugsy.moveO; // Now the position is 11 bugsy.turnO bugsy.moveO; // Now the position is 10 Your main method should construct a bug, make it move and turn a few times, and print the actual and expected positions
Computers and Technology
1 answer:
Harrizon [31]3 years ago
7 0

Answer:

Explanation:

The following code is written in Java. It creates the Bug class with the position and direction variables. Then it creates a constructor, move method, turn method, and getPosition method. Finally, a bug object called bugsy is created in the main method, and we move it once to the right, then again to the right, and then we turn it and move it 5 times to the left, printing out the position when it is done moving. Output can be seen in the attached picture below.

class Brainly {

   public static void main(String[] args) {

       Bug bugsy = new Bug(10);

       bugsy.move();

       System.out.println("Current bug position: " + bugsy.getPosition());

       bugsy.move();

       System.out.println("Current bug position: " + bugsy.getPosition());

       bugsy.turn();

       bugsy.move();

       bugsy.move();

       bugsy.move();

       bugsy.move();

       bugsy.move();

       System.out.println("Current bug position: " + bugsy.getPosition());

   }

}

class Bug {

   char direction = 'r';

   int position = 0;

   public Bug(int initialPosition) {

       this.position = initialPosition;

   }

   public void turn() {

       if (this.direction == 'r') {

           this.direction = 'l';

       } else {

           this.direction = 'r';

       }

   }

   public void move() {

       if (this.direction == 'r') {

           this.position += 1;

       } else {

           this.position -= 1;

       }

   }

   public int getPosition() {

       return this.position;

   }

}

You might be interested in
For how long should a media piece hold the user's attention?
Nastasia [14]

Answer:

C) until the message has been communicated

5 0
3 years ago
Read 2 more answers
Which of the following conditions will maximize the amount of interest you earn
choli [55]
The answer is the amount of money you put in it, brainliest please.
4 0
3 years ago
How has technology effected the way we communicate?
horsena [70]

Indeed it has.

Advancements in technology and changes in communication generally go hand in hand. Landlines displaced the telegraph and cell phones replaced landlines. The arrival of the internet opened new doors of personal communication. E-mails replaced postal mails and social media took the place of text messages.

Communication technology, such as mobile phones, email, text messaging, instant messaging and social networking have had a profound effect on nearly everyone's business and personal lives. While technology makes communications faster and easier, at times it can also be intrusive and misinterpreted.

Increased isolation, reduced social interaction and social skills, and increased human-to-machine interactions are all a result of an overuse of technology, which has created a wall between many people globally.

Technology has the ability to enhance daily living from appliances to mobile devices and computers, technology is everywhere. ... In the rise of digital communication, technology can actually help communication skills because it allows people to learn written communication to varying audiences.

<em>-Astolfo</em>

3 0
3 years ago
You are the IT administrator for a small corporate network. You have installed the Windows Server 2016 operating system on a ser
Elan Coil [88]

Answer:

In this lab, you perform the following tasks:

• On Disk 1, create a mirrored volume of the System (C:) volume to add fault tolerance.

• Using Disk 2, Disk 3, and Disk 4, create a RAID 5 volume that provides both fault tolerance and improved performance using the following settings:

o Volume size: 2 TB

o Drive letter: R

o Format: NTFS

o Volume label: Data

Complete this lab as follows:

1. Mirror an existing volume as follows:

a. Right-click Start and select Disk Management.

b. Click OK to initialize new disks.

c. Maximize the Disk Management window to better view the volumes.

d. Right-click the System (C:) volume and select Add Mirror.

e. Select Disk 1 that will be used for the mirrored copy.

f. Select Add Mirror.

g. Click Yes to convert the basic disk to a dynamic disk.

2. Create a RAID 5 volume as follows:

a. In Disk Management, right-click a disk with free space and select New RAID 5 Volume.

b. Click Next.

c. Under Available, holding down the Ctrl key, select Disk 3 and Disk 4 to be part of the new volume with Disk 2.

d. Select Add.

e. Click Next.

f. From the drive letter drop-down dialog, select R; then click Next.

g. Make sure that NTFS is selected as the file system.

h. In the Volume label field, enter Data.

i. Select Next.

j. Click Finish to create the volume.

k. Click Yes to convert the basic disk to a dynamic disk.

Explanation:

5 0
3 years ago
Just help :(((((((((((((((((((((((((((((((((((
saveliy_v [14]

Answer:

I am sure the answer is A

Explanation:

As you can see from the graph, the first time they pumped air, the numbers were 6, 1.2, and 2. Once they start pumping the numbers decrease. Therefore, I think the answer is A. It went to 5.7, 4, and 2 from 6, 1.2, and 2.1.

5 0
2 years ago
Other questions:
  • It is okay to use a dust rag when cleaning the inside of a computer.
    9·2 answers
  • Need Help !!! Please
    8·1 answer
  • To change a chart's data series, make the chart active, then in the data group on the chart tools design tab, click the _____ bu
    9·1 answer
  • Use NumPy to recreate your answer to Question 1b. The input parameters will both be python lists, so you will need to convert th
    8·1 answer
  • If you see ##### in a cell, you should
    10·1 answer
  • Excel supports all of the following types of sparklines except ____.
    13·1 answer
  • g If a class named Student has a data member named gpa , and one of its member functions has a parameter also named gpa , how ca
    7·1 answer
  • The velocity dimension of Big Data refers to _____.
    15·1 answer
  • A healthcare organization received notification that a hospital employee’s laptop that contained PHI was inadvertently left at a
    14·1 answer
  • Knowing the meaning of the acronym WAS I WHY can be most helpful to you when you?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!