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

  Environments shape organizations in turn organizations as

environments shape organizations. in turn organizations also shape the environments in which they interact. explain how

  Compute the semi-major axis and the eccentricity

This question involves orbital mechanics. Find the semi-major axis a, the eccentricity e, and the inclination i, from the given information?

  Concept of corporate crime is misguided because

Donald Cressey argued that the whole concept of corporate crime is misguided because

  Tourist area life cycle

integrated resorts on the local community and on the environment of the site

  What data support their current role or level of involvement

What resource shortfall precludes a more effective response? What data (identify and summarize) supports their current role or level of involvement? What data (identify and summarize) may dictate a change in that role?

  What are the consequences of globalization

Why did Erikson emphasize adolescence as the crucial time for identity development and why has the focus now shifted to emerging adulthood?

  Prejudice-stereotyping-racism and discrimination

You have been asked to give a presentation to students at a local high school about prejudice, stereotyping, racism, and discrimination.

  Define what is ultimately real as living nature

What do you think Antinomians mean when they define what is ultimately real as Living Nature

  Illustrate out the social self

Illustrate out the social self? Provide examples. What are some moral and ethical factors of the social self? What are some of the major agents of socialization? Which do you think most influenced you? Why?

  What are the implications of this theory to your practice

Discuss the contribution of theories to nursing research, practice, education, management, and administration. Identify a theory that is relevant to your practice. What are the implications of this theory to your practice?

  Review your financial management of your department

Describe your thoughts about having an outside auditor review your financial management of your department. What would be your reaction if the auditor found that supplies were unaccounted for, and what causes would you consider for this finding

  Explain risk assessment which is performed before the

discuss the risk assessment that is performed before an offender is placed on community supervision including the

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