我必須能夠在一定變量轉換在我的課。我有一個布爾變量,WaGa(代表工作站/遊戲電腦),如果它是真的,我想轉換字符串WorGam如何改變一個變量,在一個Java類
我必須通過服務和支持方法來做到這一點,我一直試圖,但我堅持失敗。它只是打印出驅動程序中的內容。幫幫我。
public class Graphics
//instance data
{
private int Ram;
private String Brand;
private int Res;
private int BiWi;
private int BaCl;
private boolean K4;
private boolean WaGa;
private String WorGam;
//boolean WaGa, boolean K4, int BaCl, int BiWi, int Res, String Brand, int Ram
public Graphics (int R, String B, int Re, int Bi, int Ba, boolean K4, boolean Wa, String Wor) // constructor
{
Ram = R;
Brand = B;
Res = Re;
BiWi = Bi;
BaCl = Ba;
K4 = K4;
WaGa = Wa;
Wor = WorGam;
}
public int get_Ram() //Accessor Method - there are 3 of them
{
return Ram;
}
public String get_Brand() //Accessor Method - there are 3 of them
{
return Brand;
}
public int get_Res() //Accessor Method - there are 3 of them
{
return Res;
}
public int get_BiWi() //Accessor Method - there are 3 of them
{
return BiWi;
}
public int get_BaCl()
{
return BaCl;
}
public boolean get_K4()
{
return K4;
}
public String WorGam(boolean WaGa)
{
String WorGam;
if (WaGa == true) {
return WorGam = "Workstation";
} else {
return WorGam = "True";
}
}
public String toString()
{
return ("Ram" + " " + Ram + ". " + "Brand:" + " " + Brand + ". " + "Resolution" + " " + Res + ". " + "Processer" + " " + BiWi + "." + " " + "Base Clock" + " " + BaCl+ " " + "K4?" + " " + K4+ " " +WorGam);
}
}
public class Graphicse_Driver
{
public static void main(String [] args)
{
Graphics unique=new Graphics(4, "Nvinda", 6, 7, 9, false, false, "sdf" );
System.out.println(unique);
老實說,我不知道你在問什麼。 「改變變量」是什麼意思? 「轉換某些變量」是什麼意思?什麼是「服務和支持方法」?描述「失敗」意味着什麼 - 你期望看到什麼,而你看到了什麼? – VGR
我想打印WorGam,如果賀是真的,那麼WorGam打印「工作站」,如果假的,它打印「遊戲」 –
聽起來就像if語句。你真的應該使用適當的變量和方法命名約定。 –