0
我對Java很新,我需要一些幫助。這個任務是爲了獲得用戶輸入(半徑,x座標,y座標爲&)在drawingPanel中繪製3個不同的彩色圓圈,我將該部分向下。第二部分要求我們提供一種比較兩個圓的半徑的靜態方法,並讓用戶知道其中一個是更小,更大還是更大。我無法弄清楚如何在比較兩者的方法中使用半徑輸入。獲取用戶輸入的drawingpanel並在另一個方法中使用它
這是到目前爲止我的代碼:
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);
}
}
如果我有通過調用比較法3次比較每個圈子彼此應該怎麼辦。例如:compareCircles(rb,rg); compareCircles(rb,rr); compareCircles(RR,RG); –
你必須在你創建3個圈子之後3次調用comaparison函數,如你在上面評論中提到的 – Neero
這是適用於你的嗎?你需要幫助嗎 – Neero