byte color
必須保持顏色(如紅色或綠色)。 結果show()
方法必須使用開關來分類和描述這個顏色(在不同的變體,如:紅,藍,綠,紅等)*不能使用枚舉開關語句和字符串到字節
public class Candy {
//fields
int quantity;
byte color;
double price;
//constructor
Candy(int quantity, byte color, double price)
{
this.quantity = quantity;
this.color = color;
this.price = price;
}
//this method have to show class fields
public void show(String colors)
{
switch(color)
{
case 1: colors = "red";
case 2: colors = "green";
case 3: colors = "blue";
}
//tried to convert
//String red = "Red";
//byte[] red1 = red.getBytes();
//String green = "Green";
//byte[] green1 = green.getBytes();
public static void main(String[] args)
{
//program
}
}
我是在好辦法嗎?如何保持字符串的字符串?由於
你的意思是編碼一個字節的這三種顏色的所有可能的組合? – bellum
你的問題是什麼? –
@bellum該字節(顏色)的每一位都必須存儲一種顏色。 – Fastkowy