/* * A program to calculate the imaginative yellow space. */ package shapes; import java.awt.Color; import painter.SPainter; import shapes.SCircle; import shapes.SSquare; public class YellowSpace { public static void main(String[] args){ SPainter Nani = new SPainter("Image", 500,500); // Declaring basic variables and binding them with values. double EdgeLength, Distance; EdgeLength = 400.0; Distance = 60.0; // Large GRAY Square. SSquare LargeGraySquare = new SSquare(EdgeLength); Nani.setColor(Color.gray); Nani.paint(LargeGraySquare); // Large YELLOW Diamond. SCircle ImaginativeCircle = new SCircle((LargeGraySquare.side()/2 - Distance)); SSquare LargeYellowDiamond = ImaginativeCircle.inscribingSquare(); Nani.setColor(Color.yellow); Nani.tl(45); Nani.paint(LargeYellowDiamond); Nani.tr(45); // Small GRAY Square. ImaginativeCircle = LargeYellowDiamond.inscribingCircle(); EdgeLength = ImaginativeCircle.diameter(); Distance = 30.0; ImaginativeCircle = new SCircle((EdgeLength/2 - Distance)); SSquare SmallGraySquare = ImaginativeCircle.inscribingSquare(); Nani.setColor(Color.GRAY); Nani.paint(SmallGraySquare); // Small YELLOW Diamond. EdgeLength = SmallGraySquare.side(); Distance = 15.0; ImaginativeCircle = new SCircle((EdgeLength/2 - Distance)); SSquare SmallYellowDiamond = ImaginativeCircle.inscribingSquare(); Nani.setColor(Color.YELLOW); Nani.tl(45); Nani.paint(SmallYellowDiamond); Nani.tr(45); // Calculate the yellow space. double YellowSpace = LargeYellowDiamond.area() - SmallGraySquare.area() + SmallYellowDiamond.area(); System.out.println("The area of the yellow space is " + YellowSpace + " squared milliliters"); } }