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

  Death penalty either practiced or banned in other countries

From a global perspective, how is the death penalty either practiced or banned in other countries? Give at least one example with a citation that illustrates your response.

  Confucianism teaches that the life of the gentleman

"Confucianism teaches that the life of the gentleman-scholar is the highest calling. The informed, educated, public servant is viewed as a person who can distribute human kindness among society." What does this mean to you and how does one apply this..

  About alcoholism and crime

ALCOHOLISM AND CRIME

  What is cyber security and what are some of its key concepts

What is cyber security, and what are some of its key concepts? What are the most significant threats to a company's data, and what are some of the root causes of those threats?

  Explain the principal issues of epistemology

Explain the principal issues of epistemology, for example, is how to define knowledge.

  Compare discrete-trial and free-operant methods

Compare discrete-trial and free-operant methods of instrumental conditioning. What are the advantages of each class of procedure? What factors would influence your choice of procedure type if you were to explore instrumental behaviors?

  Scores on a recent national statistics exam

Scores on a recent national statistics exam were normallydistributed with a mean of 80 and a standard deviation of 6.

  Discussed temperature danger zones

We had previously discussed temperature danger zones, and still there are certain detrimental temperature within that range that can allow harmful microorganisms to grow in certain food items.how does this relate to temperature control?

  Identify three significant elements of the

1identify three significant elements of the constitutionincluding amendments that embody the republican principle of

  Federal government through its exercise of commerce power

Which of the following activities is regulated by the federal government through its exercise of the commerce power?

  Community psychology action and research tools

How can community psychology action and research tools be applied to issues such as colonization, racism, immigration or adaptation within a global context.

  Subsets of consumers with common needs or characteristics

The process of dividing a market into subsets of consumers with common needs or characteristics is known as _____.

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