Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Homework Help/Study Tips Expert

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

Homework Help/Study Tips, Others

  • Category:- Homework Help/Study Tips
  • Reference No.:- M92063559

Have any Question?


Related Questions in Homework Help/Study Tips

Answer the following question what are some common

Answer the following Question : What are some common misconceptions about marketing for nonprofits? What are some of the pressures that nonprofits face in regards to advertising? 250 words please

Question business ethics questionswhy is ethical misconduct

Question: Business Ethics Questions: Why is ethical misconduct more difficult to overcome than poor financial performance? Do some stakeholders suffer more from ethical misconduct than from poor financial performance? Ex ...

This weeks assignment is the second part of a three-part

This week's assignment is the second part of a three-part Course Project which requires you to develop a financial plan for a department within an institution of higher education. Continue using the "Develop a Financial ...

Essay assignment - importance of caffeine to the human

Essay Assignment - Importance of Caffeine to the human brain Description - Length 3-5 pages (900-1500 words), double-spaced, 11 or 12 point Font, APA Format. Five references properly cited in text. When looking up refere ...

Assignment 1 discussion-biological causes of crimenatalie

Assignment 1: Discussion-Biological Causes of Crime Natalie was growing concerned about her daughter Brandi's school performance. Her grades had dropped since the beginning of the school year, and she seemed reluctant to ...

Assessment -create and develop a 10-minute powerpoint

Assessment - Create and develop a 10-minute PowerPoint presentation (including audio) based on an area of Developmental Psychology (of your choosing). The focus of the presentation will be to use the relevant theories an ...

Question write a 500-750 word argumentationpersuasion essay

Question: Write a 500-750 word argumentation/persuasion essay using any approach as a method of development. An effective argumentative essay must have evidence to make its case; most arguments that occur in daily life h ...

Assignment 4 annual reviewimagine you work at a company and

Assignment 4: Annual Review Imagine you work at a company and it is time for an employee named Jim's annual review. While he was a model employee the first nine (9) months of the year, recently Jim has been coming in lat ...

Question during the course of your employment you may have

Question: During the course of your employment you may have experienced working for both a male and female supervisor. Discuss from your personal point of view the advantages/disadvantages and like/dislike of working for ...

Assignment contracts- choose one- typed pages between 2

Assignment : Contracts - Choose One - Typed pages between 2 and 3 pages double-spaced. Write an essay describing how you would advise a business with cash flow problems that wishes to break several unprofitable contracts ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As