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
}
}
我走的好吗?如何将字符串保存在字节中?谢谢