Represent a square with x and y

Assignment Help Other Subject
Reference no: EM131308932

Exercise -

You will read a line of data with either 1, 3 or 4 doubles numbers. Numbers will be separate with a space, last number terminates with a newline When you read in a line with only number it will have a -1, once you read this line terminate your program. If you have 3 doubles on the line the values represent a square with x, y and radius x, y is center of the square

Radius is the distance from the center to the four sides.

The height and width are twice the radius.

If you have 4 doubles the values represent x, y, width, height x, y are the center of the rectangle, they can have negative values; radius, width and height are always positive.

Output consists of 4 lines...

perimeter: doubleValue with 3 digits right of decimal point

area: doubleValue with 3 digits right of decimal point

then read in another rectangle 3 or 4 doubles

contains: true or false (true if second rectangle is contained with first rectangle, otherwise false )

overlaps: true of false ( true if second rectangle overlaps first, if rect 2 is contained in rect 1, then it also overlaps, otherwise false)

Sample Run: (user enters 4 5 2 then 1 1 3 1 then 5 6 7 then 6 6 6 6 then -1 )

Enter rectangle: 4 5 2

perimeter: 16.000

area: 16.000

Enter rectangle: 1 1 3 1

contains: false

overlaps: false

Enter rectangle: 5 6 7

perimeter: 56.000

area: 196.000

Enter rectangle: 6 6 6 6

contains: true

overlaps: true

Enter rectangle: -1

Hints: for reading line you need to use a nextLine, then parse the incoming string using Scanner( line ) w hasNext, nextDouble, and/or parse into individual words using String.split and then wrapper classes.

Exercise is a little harder than most of the previous assignments, you need to move from solving problems using a sequential brute force, into OOP. With OOP we break up a problem into Classes, each class has methods and properties. Each method accomplishes a single task. You may want to refer to this API, but in general never violate these guidelines....

Never perform the same task twice, you should be creating a method and calling it twice.

If else should never be more than 3 levels deep.

Avoid too many variables, if something is used once or easily calculated it should not be a separate variable. Rectangle should have only 4 global variables. (x,y,width, height).

More than 30 lines of sequential code.

If you violate any of the above guidelines, then you are not breaking your code down into the proper number of classes and corresponding methods.

After analyzing the API, and thinking about this problem, it should be evident that the key method for solving this is boolean contains( double x, double y).

You should use this code for testing your contains...

public static boolean testMyContains( )

    {

        Rectangle rect = new Rectangle( 0, 0, 2, 4 );

        /* gives rect with test four corners...

             -1,2 ...       1,2

                  0,0 center

             -1, -2 ....  1, -2

        */

        double[][] point = {  {0,0}, {1,0},    {1,1}, {0,-2},

                            {0,3}, {1.1, 0}, {1,2.1}, {0, 3},

                            {0,1.5}, {.75,0}, {0,1.75}, {-0.9, 1.5}  };

        boolean[] solution = { true, true, true, true,

                           false, false, false, false,

                           true, true,   true,  true };

        for( int i=0; i < point.length; ++i ) {

            if( rect.contains( point[i][0], point[i][1] ) != solution[i] ) {

                System.out.println("Error on point " + i + " x,y " +

                        point[i][0] + ", " + point[i][1] + " contains:" +

                        solution[ i ] );

                return false;

            }

        }

        return true;

    }

Attachment:- Exercise.rar

Reference no: EM131308932

Questions Cloud

Project manager point of view : After watching the video, from a project manager point of view, discuss the importance of knowing the scope of the project, the scenario of the project, in this case an expedition on extreme weather conditions, and then discuss the importance of p..
Analyze the data and write a report for anderson : Develop a questionnaire and administer it either in hard copy or online to a sample of students. Then analyze the data and write a report for Anderson.
Efforts to increase market share : Let me take an example from automobile industry in Indian market. It's known the competition is intense, and all players except Suzuki are making lot of efforts to increase market share. Now, can you share thoughts on what would be the key strategic ..
What is the business model for the corporation : What is the business model for the corporation? Where is technology strong? Where is it weak? What is our sustainability policy? What is our technology innovation strategy?
Represent a square with x and y : You will read a line of data with either 1, 3 or 4 doubles numbers. Numbers will be separate with a space, last number terminates with a newline When you read in a line with only number it will have a -1, once you read this line terminate your pro..
Proofread it carefully for spelling errors and misused words : Proofread it carefully for spelling errors, misused words, and grammar errors. Rewrite the passage showing the corrections you made.
Bond rating affect an investors required rate of return : The dividend for Weaver, Inc., is expected to grow at 21 percent for the next 4 years before leveling off at a 5.8 percent rate indefinitely. If the firm just paid a dividend of $1.2 and you require a return of 14 percent on the stock, what is the mo..
Rising fuel costs and a slow world economy : Like many airlines around the world, leading Australian airline Qantas is facing very difficult times in spite of having a 65% market share in its home market of Australia. Due to rising fuel costs and a slow world economy, Qantas has recently bee..
What would you expect to be the effect on interest rates : Illustrate your answer with aggregate demand and supply curves. What would you expect to be the effect on interest rates if the Fed held the money supply constant? Tell a complete story.

Reviews

Write a Review

 

Other Subject Questions & Answers

  Health disparities based on socioeconomic status

Describe the problem of lack of health care for children and propose some solution(s) to the problem.

  Define developmental psychopathology

Describe the typical course of schizophrenia throughout the lifespan. Distinguish between positive, negative, and disorganized symptoms of schizophrenia. Define developmental psychopathology. Describe the incidence and prevalence of mental retardatio..

  Analyze the changing nature of the health care industry

Analyze the changing nature of the health care industry, including health care reform, the volume to value-based shift, and the industry's emphasis on a culture of excellence.

  What global forces are affecting the us economy

What global forces are affecting the U.S. economy and politics? How do those global forces affect your own life? Discuss

  Assignment internal and external persuasive communication

Assignment Internal and External Persuasive Communication

  Ability to focus on the key issues of relevance with

write a 4000-word essay on the following assigned topic. apa style at least 12 academic sources mixed journal articles

  Briefly describe the social movement

IDENTIFY a current or historical social movement that interests you. Ensure that it meets the definition of a social movement pursuant to the class text. Briefly DESCRIBE the social movement and its objectives or political positions

  How energy lost heat at second through fourth trophic levels

How did amount of energy gained in the banana compare to amount of energy lost as heat at second through fourth trophic levels?

  Describe three push and three pull factors

Describe three push and three pull factors that have influenced the demographic shift from rural areas to urban areas

  Story about leif ericsson

Certainly many of us have heard the story about Leif Ericsson (son of Eric the Red), the great Norwegian explorer who sailed west from Greenland around 1000 AD and came upon Newfoundland Island, which he called 'Vinland'.

  Brief description of the injury prevention intervention

Brief description of the injury prevention intervention you selected. Then, explain how you might apply the Diffusion of Innovations theory to that intervention. Your explanation must include characteristics of the innovation, characteristics of a..

  What description of culture does this fall under

Evolutionary psychologists use interviews and questionnaires to depict and observe people's behaviors. However, the argument against this method is that these survey tools do not always describe a person's actual decisions. What description of cul..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd