Crenox

Circle Class

Apr 3rd, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package com.samkough.main;
  2.  
  3. public class Circle
  4. {
  5. // instance variables, fields
  6. String color;
  7. double diameter;
  8. double radius;
  9.  
  10. public Circle(String c, double d)
  11. {
  12. color = c;
  13. diameter = d;
  14. }
  15.  
  16. public double getRadius()
  17. {
  18. radius = diameter / 2;
  19. return radius;
  20. }
  21.  
  22. public String toString()
  23. {
  24. String statement = "The diameter is " + diameter + ", the radius is " +
  25. getRadius() + " and the color is " + color + ".";
  26.  
  27. return statement;
  28. }
  29. }
  30. --------------------------------------------------------------------------------------------------------------------------------------
  31. package com.samkough.main;
  32.  
  33. public class CircleTester
  34. {
  35. public static void main(String args[])
  36. {
  37. Circle c1 = new Circle("Red", 20);
  38. System.out.println(c1.toString());
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment