【发布时间】:2017-10-16 21:27:02
【问题描述】:
我对 java 很陌生,我需要一些关于作业的帮助。任务是让用户输入(半径、x 坐标和 y 坐标)在绘图面板中绘制 3 个不同颜色的圆圈,我把那部分放在了下面。第二部分要求我们提供一种静态方法,该方法比较两个圆的半径,并让用户知道一个圆更小、更大还是与另一个相同。我无法弄清楚如何在比较两者的方法中使用半径的输入。
到目前为止,这是我的代码:
import java.awt.*;
import java.util.*;
public class Circles {
public static final Scanner CONSOLE = new Scanner(System.in);
public static void blueCircle(Graphics g) {
g.setColor(Color.BLUE);
int r = CONSOLE.nextInt();
int x = CONSOLE.nextInt();
int y = CONSOLE.nextInt();
g.fillOval(0 + x, 0 + y, r * 2, r * 2);
}
public static void greenCircle(Graphics g) {
g.setColor(Color.GREEN);
int r = CONSOLE.nextInt();
int x = CONSOLE.nextInt();
int y = CONSOLE.nextInt();
g.fillOval(0 + x, 0 + y, r * 2, r * 2);
}
public static void redCircle(Graphics g) {
g.setColor(Color.RED);
int r = CONSOLE.nextInt();
int x = CONSOLE.nextInt();
int y = CONSOLE.nextInt();
g.fillOval(0 + x, 0 + y, r * 2, r * 2);
}
public static void compareCircles(int r1, int r2) {
int x;
if (r1 < r2)
x = -1;
if (r1 == r2)
x = 0;
if (r1 > r2)
x = 1;
return;
}
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(400, 300);
Graphics g = panel.getGraphics();
System.out.println("Enter values for the radius, x , & y-coordinates of blue circle: ");
blueCircle(g);
System.out.println("Enter values for the radius, x , & y-coordinates of green circle: ");
greenCircle(g);
System.out.println("Enter values for the radius, x , & y-coordinates of red circle: ");
redCircle(g);
}
}
【问题讨论】:
标签: java methods user-input