id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

gaurav.gupta@mq.edu.au delegation > overlap
prev  |  next  |  chance

Two circles are said to overlap if the distance between their centers is less than or equal to the sum of their radii. Given the function that calculates the distance between two points (x1, y1) and (x2, y2), define a function that when passed the centers and radii of two circles, returns true if they overlap, false otherwise.

double distance(int x1, int y1, int x2, int y2) {
   double dx = x1 - x2;
   double dy = y1 - y2;
   double D = dx*dx + dy*dy;
   return Math.sqrt(D);
}

overlap(10, 20, 10, 30, 20, 10) → true
overlap(10, 20, 10, 30, 20, 9) → false
overlap(50, 50, 10, 40, 40, 10) → true

...Save, Compile, Run (ctrl-enter)

boolean overlap(int x1, int y1, int radius1, int x2, int y2, int radius2) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 1 Post-solution available

Copyright Nick Parlante 2017 - privacy