package npw; import painter.SPainter; import shapes.SCircle; import shapes.SSquare; import javax.swing.*; import java.awt.*; import java.util.Scanner; public class Invention1 { private void paintTheImage(){ //prompt user for colors String primaryColor = getColor("First Color"); String secondaryColor = getColor("Second Color"); double circleSize = getNumber("Circle Size"); int nrOfsquares = getNumber("Number of Squares"); //create painter and the objects SCircle circle = new SCircle(circleSize); SCircle circle2 = new SCircle(circleSize / 2.0); SSquare square1 = circle.circumscribingSquare(); SSquare square2 = circle.inscribingSquare(); SSquare square3 = circle2.circumscribingSquare(); SSquare square4 = circle2.inscribingSquare(); int squareDiag = (int) square1.diagonal(); SPainter sean = new SPainter("My Invention", squareDiag, squareDiag); //initialize sean position sean.tr(45); //paint squares 1 and 3 if (primaryColor.equalsIgnoreCase("green")) { sean.setColor(Color.GREEN); } else if (primaryColor.equalsIgnoreCase("red")){ sean.setColor(Color.RED); } else if (primaryColor.equalsIgnoreCase("blue")){ sean.setColor(Color.BLUE); } else{ sean.setColor(Color.BLACK); } int i = 0; while (i <= nrOfsquares){ oneRotation(sean, nrOfsquares); sean.draw(square1); sean.draw(square3); i++; } //painter squares 2 and 4 if (secondaryColor.equalsIgnoreCase("green")) { sean.setColor(Color.GREEN); } else if (secondaryColor.equalsIgnoreCase("red")){ sean.setColor(Color.RED); } else if (secondaryColor.equalsIgnoreCase("blue")){ sean.setColor(Color.BLUE); } else{ sean.setColor(Color.BLACK); } int j = 0; while (j <= nrOfsquares){ oneRotation(sean, nrOfsquares); sean.draw(square2); sean.draw(square4); j++; } } private void oneRotation(SPainter painter, int nrOfSquares){ painter.tr((360.0 / nrOfSquares)); } private static String getColor(String prompt) { String nss = JOptionPane.showInputDialog(null, prompt + "?"); Scanner scanner = new Scanner(nss); return scanner.next(); } private static int getNumber(String prompt) { String nss = JOptionPane.showInputDialog(null,prompt+"?"); Scanner scanner = new Scanner(nss); return scanner.nextInt(); } public Invention1() { paintTheImage(); } public static void main(String[] args) { SwingUtilities.invokeLater (new Runnable(){ public void run(){ new Invention1(); } }); } }