第一年CS考试,需要指导

first year CS exam, need guidense

我明天 java 有考试。它着重于封装、内聚、耦合、继承和接口。我制作了一个包含七个 classes 的项目,扬声器和耳机 class 继承自声音 class 和产品 class 并且 DjMixer 实现仅来自 product.The main class 仍然是空的。我需要知道我在代码设计中是否犯了任何重大错误。

public interface Product
{

    double getPrice();

    void setPrice(double price);

    String getId();

    void setId(String Id);

    String getPlace();

    void setPlace(String place);
}

public abstract class Sound
{

public abstract void setDesibel(int desibel);

public abstract int getDesibel();

public void amp() {
        System.out.println("Recomended amplifier effect is 40-250 watts");
    }

}

public class Speaker extends Sound implements Product
{

    double price;
    String id;
    String place;
    int desibel;

    /**Price in Norwegain Kroner */    
public double getPrice(){
        return price;
    }

    /**Price is set in Norwegain Kroner */ 
public void setPrice(double price){
        this.price = price;
    }

    /**Location of the product*/
public String getPlace(){
        return place;
    }

public void setPlace(String place){
        this.place = place;
    }

    /**The products European Article Number*/
public String getId(){
        return id;
    }

    /**type in the European Article Number under the barcode*/
public void setId(String serialNum){
        id = serialNum;
    }

    //Constructor
public Speaker(double price, String location, String serialNum) {
        super.amp();
        this.price = price;
        place = location;
        id = serialNum;
    }

public int getDesibel() {
        return this.desibel;
    }

public void setDesibel(int desibel) {
        this.desibel = desibel;
    } 
}

public class Headset extends Sound implements Product
{

    double price;
    String place;
    String id;
    int desibel;
    boolean wireless = true;

    /**Price is in Norwegain Kroner */ 
public double getPrice(){
        return price;
    }

    /**Price is set in Norwegain Kroner */ 
public void setPrice(double price){
        this.price = price;
    }

    /**Location of the product*/
public String getPlace(){
        return place;
    }

    /**Set location where item is stored */
public void setPlace(String location){
        place = location;
    }

    /**The products European Article Number*/
public String getId(){
        return id;
    }

    /**type in the European Article Number under the barcode*/
public void setId(String serialNum){
        id = serialNum;
    }

    //Constructor
public Headset(double price, String location, String serialNum) {
        super();
        this.price = price;
        place = location;
        id = serialNum;
    }

public void setDesibel(int desibel) {
        this.desibel = desibel;
    }

public int getDesibel() {
        return this.desibel;
    }
}

public class DjMixer implements Product
{


    double price;
    String id;
    String place = "Storage room, shelf 3";

    /**Price in Norwegain Kroner */
public double getPrice(){
        return price;
    }

    /**Price is set in Norwegain Kroner */ 
public void setPrice(double price){
        this.price = price;
    }

    /**Mixing tables is stored on shelf 3, if moved please set new place */
public String getPlace(){
        return place;
    }

    /**Set new place for mixing table if moved */
public void setPlace(String location){
        place = location;
    }

    /**The products European Article Number*/
public String getId(){
        return id;
    }

    /**type in the European Article Number under the barcode*/
public void setId(String serialNum){
        id = serialNum;
    }

public DjMixer(double price, String serialNum){
        this.price = price;
        id = serialNum;
    }
}

最好将任何可通过 "get" 方法访问的变量声明为私有变量。此外,您在某些方法中使用 "desibel" 而不是 "decibel"。如果你的老师教过你 final 关键字,无线 boolean 似乎应该这样声明。