みなさん、こんにちは。宿題をしているのですが、行き詰まってしまったので、少しフィードバックが必要です。
1つのパッケージに抽象クラスGearと列挙型Infoがあり、次に、assertテストとjunitテストを使用してGearとInfoの正確さをテストするInfoTestがあります。
問題はInfoTestにあります。GearクラスにあるメソッドがInfo g = some Value;
ありg.getWeight()
、InfoTestからInfoオブジェクトを介してgetWeight()メソッドにアクセスできません。
そのため、InfoTestのInfoオブジェクトを使用してgetWeight()にアクセスする方法があるのか、それとも先生が間違えたのか疑問に思いました。サックス。
OKKKKKKKKKKKここにいくつかのコードサンプルがあります。
パブリック抽象クラスGear{
/** * weight stores the weight of the item in kg */ protected int weight; /** * code store the code for the item (bedding, food, medical or sanitary, but it is better to use array. */ protected char code; /**getWeight gets the weight of the item. * * @return weight */ public int getWeight() { return weight; } /**setWeight sets the weight for the item * * @param weight */ public void setWeight(int weight) { this.weight = weight; } /**getCode() gets the code of the item. * * @return code */ public char getCode() { return code; } /**setCode sets the code of the item. * * @param code */ public void setCode(char code) { this.code = code; } }
パブリック列挙型情報{
/** * BLANKETS represent the blankets. */ BLANKETS, /** * PILLOWS represent the pillows */ PILLOWS, /** * FOOD represent the food */ FOOD, /** * MEDKIT represent the medical kit. */ MEDKIT, /** * OXYGEN represent the oxygen */ OXYGEN, /** * NAPKINS represent the napkins. */ NAPKINS, /** * SICKNESSBAG represent the sickness bags. */ SICKNESSBAG }
> public class InfoTest {
/**
> * Test of getWeight() method, of class Info.
> */
> @Test
> public void testGetWeight() {
> System.out.print("\tChecking weights in Info");
> Info g = Info.BLANKETS;
> final int expectedValue1 = 2;
> assertEquals(expectedValue1, g.getWeight()); }
>
> }