# Information Technology

I have an assignment after 5 hours please I need it on timethanks
labbbb.doc

Unformatted Attachment Preview

Don't use plagiarized sources. Get Your Custom Essay on
Information Technology
Just from \$13/Page

Classes
1. Define a class named RandomWalker. A RandomWalker object should keep track of its (x, y) location. All
walkers start at the coordinates (0, 0). When a walker is asked to move, it randomly moves either left, right,
up or down. Each of these four moves should occur with equal probability. The resulting behavior is
known as a “random walk.” (A 2-dimensional random walk example is pictured at right.)
Each RandomWalker object should have the following public methods. You may add whatever fields or
methods you feel are necessary to implement these methods:
move()
Instructs this random walker to randomly make one of the 4 possible moves (up, down, left, or right).
getX()
Returns this random walker’s current x-coordinate.
getY()
Returns this random walker’s current y-coordinate.
getSteps()
Returns the number of steps this random walker has taken.
Random walks have interesting mathematical properties. For example, given infinitely many steps, a
random walks, visit http://mathworld.wolfram.com/RandomWalk.html .
Test your RandomWalker by running it with the TestRandomWalker test class, found on the Labs section of
the course web site. The TestRandomWalker will run your random walker in a loop and animate its position
as it moves.
1 of 4
2. Define a class named Rectangle. A Rectangle object stores an (x, y) coordinate of its top/left corner, a
width, and a height.
Each Rectangle object should have the following public methods:
Rectangle(x, y, width, height)
Constructs a new rectangle whose top-left corner is specified by the given coordinates and with the given
width and height.
getX()
Returns this rectangle’s leftmost x-coordinate.
getY()
Returns this rectangle’s top y-coordinate.
getWidth()
Returns this rectangle’s width.
getHeight()
Returns this rectangle’s height.
toString()
Returns a String representation of this rectangle, such as “Rectangle[x=1,y=2,width=3,height=4]”.
contains(x, y)
Returns whether the given Point’s coordinates lie inside the bounds of this rectangle.
intersect(rect)
Turns this rectangle into the intersection of itself and the given other rectangle rect;
that is, the largest rectangular region completely contained within both this rectangle
and the given other rectangle. (In the picture at right, the intersection of the two
rectagles is the shaded black region.) You may assume that the two rectangles do
overlap and therefore have a nonempty intersection.
equals(o)
Returns whether the given other object o is a rectangle with the same x/y coordinates, width, and height as
this rectangle. You may assume that o refers to a Rectangle object.
Test your program by running it with the TestRectangle class, which is found on the Labs section of the
course web site.
2 of 4
3. Define a class named CandyDistributor. A CandyDistributor object represents a hungry child who is
going to divide a set of candies between herself and her hungry sibling. This will be done fairly by
alternating who gets a candy. Each CandyDistributor object should have the following method:
public void nextCandy()
Each time nextCandy is called, the method prints a message about who gets a candy, and how many candies
that person has. Each call to nextCandy produces a single line of output. The code below constructs a
CandyDistributor object and calls its nextCandy 8 times. The output appears at right.
public class TestCandy {
public static void main(String[] args) {
CandyDistributor nice = new CandyDistributor();
nice.nextCandy();
// 1 for you.
nice.nextCandy();
// 1 for me.
nice.nextCandy();
// 2 for you.
nice.nextCandy();
// 2 for me.
nice.nextCandy();
// 3 for you.
nice.nextCandy();
// 3 for me.
nice.nextCandy();
// 4 for you.
nice.nextCandy();
// 4 for me.
}
}
4. Define a class named UnfairCandyDistributor. An UnfairCandyDistributor object represents a mean
big brother who is going to divide a set of candies between himself and his hungry little brother. This will
be done unfairly: for every candy given to the sibling, the big brother takes for himself a number of
additional candies equal to the younger sibling’s total. Each UnfairCandyDistributor object should have
the same method:
public void nextCandy()
Each time nextCandy is called, the method prints a message about who gets a candy. Each call to
nextCandy produces a single line of output. This time the output is the following:
public class TestCandy2 {
public static void main(String[] args) {
UnfairCandyDistributor mean = new UnfairCandyDistributor();
mean.nextCandy();
// 1 for you.
mean.nextCandy();
// 1 for me.
mean.nextCandy();
// 2 for you.
mean.nextCandy();
// 1 for me.
mean.nextCandy();
// 2 for me.
mean.nextCandy();
// 3 for you.
mean.nextCandy();
// 1 for me.
mean.nextCandy();
// 2 for me.
mean.nextCandy();
// 3 for me.
mean.nextCandy();
// 4 for you.
mean.nextCandy();
// 1 for me.
mean.nextCandy();
// 2 for me.
mean.nextCandy();
// 3 for me.
mean.nextCandy();
// 4 for me.
}
}
3 of 4
5. Define a class named TimeSpan. A TimeSpan object stores a span of time in hours and
minutes (for example, the time span between Monday 8AM and Wednesday 10:30AM is
50 hours, 30 minutes). Each TimeSpan object should have the following public methods:
TimeSpan(hours, minutes)
Constructs a TimeSpan object storing the
given time span of minutes and seconds.
Adds the given amount of time to the current time span (e.g. 2 hours, 15 min + 1 hour, 45 min = 4 hours).
Assume that the arguments are valid: the hours are non-negative, and the minutes are between 0 and 59.
Adds the given amount of time (stored as a time span) to the current time span.
getTotalHours()
Returns the total time in this time span as the real number of hours (such as 9.75 for 9 hours, 45 min).
toString()
Returns a string representation of the time span of hours and minutes, such as “28h46m”.
The minutes should always be reported as being in the range of 0 to 59. That means that you may have to
“carry” 60 minutes into a full hour. For example, consider the following code:
TimeSpan t1 = new TimeSpan(3, 45);
System.out.println(t1 + ” is ” + t1.getTotalHours() + ” hours”);
System.out.println(t1 + ” is ” + t1.getTotalHours() + ” hours”);
TimeSpan t2 = new TimeSpan(0, 55);
System.out.println(t1 + ” is ” + t1.getTotalHours() + ” hours”);
This code creates a TimeSpan object and adds three different times to it. The output should be:
3h45m is 3.75 hours
6h15m is 6.25 hours
7h10m is 7.166666666666667 hours
Notice that the second time is not 5 hours, 75 minutes, although that’s what you’d get by just adding values.
4 of 4

attachment

Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

## Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.