Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.samkough.main;
- public class Circle
- {
- // instance variables, fields
- String color;
- double diameter;
- double radius;
- public Circle(String c, double d)
- {
- color = c;
- diameter = d;
- }
- public double getRadius()
- {
- radius = diameter / 2;
- return radius;
- }
- public String toString()
- {
- String statement = "The diameter is " + diameter + ", the radius is " +
- getRadius() + " and the color is " + color + ".";
- return statement;
- }
- }
- --------------------------------------------------------------------------------------------------------------------------------------
- package com.samkough.main;
- public class CircleTester
- {
- public static void main(String args[])
- {
- Circle c1 = new Circle("Red", 20);
- System.out.println(c1.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment