Question

Years of research have revealed the spec class that implements this unique movem random point (with integer coordinates x and y). When it decid coordinates by the followin example, if x is 37 and y is 12 ial mechanism behind Tiggers bouncy step. Design a Tigger ent, which I will describe below. A Tigger always starts in a es to bounce, a Tigger changes its x and y g rule: x becomes the sum of the squares of its digits, and so does y. For they turn into 58 (32+72) and 5 (1+22) respectively. In your main method create such an object and make it bounce a few times, for example: java One Tigger just bounced to (162, 105) Tigger just bounced to 41, 26) Tigger just bounced to 17, 4o) Tigger just bounced to 50, 16) Tigger just bounced to 25, 37) Tigger just bounced to ( 29, 58) Tigger just bounced to 85, 89) Tigger just bounced to 89, 145) Tigger just bounced to (145, 42) Tigger just bounced to 42, 20) Tigger just bounced to (20, 4) Tigger just bounced to 4, 16) Tigger just bounced to (16, 37) Tigger just bounced to (37, 58) Tigger just bounced to (58, 89) Solve the problem in Java
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for TiggerBounce.java:

import java.util.*;
class TiggerBounce
{
    int x;
    int y;
    public TiggerBounce()   //Default constructor, which initializes x, and y with random values.
    {
       Random randGen = new Random();
       x = randGen.nextInt();
       y = randGen.nextInt();
    }
    public TiggerBounce(int x, int y)   //Parameterized constructor, which initializes x, and y with given values.
    {
       this.x = x;
       this.y = y;
    }
    private int sumOfSquaresOfDigits(int value)   //Private function to compute the sum of digits in a number.
    {
       int sum = 0;
       while(value != 0)
       {
          int rem = value % 10;
          sum += rem * rem;
          value /= 10;
       }
       return sum;
    }
    public void computeNextBounce()   //Computes the next point.
    {
       x = sumOfSquaresOfDigits(x);
       y = sumOfSquaresOfDigits(y);
    }
    public int getX() { return x; }   //Getter for x.
    public int getY() { return y; }   //Getter for y.
    public String toString()       //toString() method.
    {
       return "(" + x + ", " + y + ")";
    }
      
}

And the code for TiggerBounceDemo.java is:

class TiggerBounceDemo
{
    public static void main(String[] args)
    {
       TiggerBounce myBounce = new TiggerBounce(162, 105);
       for(int i = 0; i < 15; i++)
       {
          System.out.println("Tigger just bounced to " + myBounce);
          myBounce.computeNextBounce();
       }
    }
}

And the output screenshot is:

《 Terminal Shell Edit View Window Help E @ 1.11 GB h。< >し令동 ))) 98% E ฏิเ Sun 15 Oct 07:10 ANANDA KUMAR THUMMAPUDI Q。Е Curren

Add a comment
Know the answer?
Add Answer to:
Solve the problem in Java Years of research have revealed the spec class that implements this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • == Programming Assignment == For this assignment you will write a program that controls a set...

    == Programming Assignment == For this assignment you will write a program that controls a set of rovers and sends them commands to navigate on the Martian surface where they take samples. Each rover performs several missions and each mission follows the same sequence: deploy, perform one or more moves and scans, then return to base and report the results. While on a mission each rover needs to remember the scan results, in the same order as they were taken,...

  • Problem #1: TO SELECT THE MOST ECONOMICAL Wio SHAPE COLUMN ZO FEET IN HEIGHT SUPPORT AH...

    Problem #1: TO SELECT THE MOST ECONOMICAL Wio SHAPE COLUMN ZO FEET IN HEIGHT SUPPORT AH AXIAL LORD OF 370 KIPS using soksi STEEL! ASSUME A FIXED BASE ANDA PINGED TOP (CASE C) WIDE FLANGE SHAPES HP Axis Y-Y Theoretical Dimensions and Properties for Designing Flange Axis X-X | Weight Area Depth Web Section per of of Thick- Thick- Number Foot Section Section Width S 'T Sy Ty ness ness < * A by tw in. in. in.' in. in....

  • so i have my c++ code and ive been working on this for hours but i...

    so i have my c++ code and ive been working on this for hours but i cant get it to run im not allowed to use arrays. im not sure how to fix it thank you for the help our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses...

  • starter code To write a program using the starter code which is TestLinkedList to see if...

    starter code To write a program using the starter code which is TestLinkedList to see if the LinkedList program has bugs. It will produce ether a pass or fail.More information is in the first two pictures. LinkedList.java /** * @author someone * * Implements a double-linked list with four errors */ public class LinkedList<E> { // The first and last nodes in the list private Node<E> head, tail; // Number of items stored in the list private int size; //...

  • Assume I have a table. The values inside the table are determined by y and x...

    Assume I have a table. The values inside the table are determined by y and x variables. But in this case it is t and p (or temperature and pressure). Those values for t and p don't correlate to my array in code ( for example on column = 0 the temperature= -120). That's what a and b are for. I want to be able to input a value between two rows or columns and use a y=mx+b equation to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT