Examples of java to write a simulation to buy mobile phones and phone cards

Software NetBeans IDE 7.0.1, need to write the main class alone.

Write a simulation example to buy mobile phones and phone cards.
Package phone card interface SIMable, which represents a phone card, can be applied as a removable card may be Unicom card, declare a method to adapt generic phone: VOD setNumer (String n-); String givNumereo: Tring gveCorpName) ...
(2) Packaging phone Molcelephne class can be either a single phone card, the card may be a double dual standby mobile phone, the phone card or may not, depending on the SIM card, and therefore, need to be declared SIMable three types of properties, to correspond to a single card, two cards, no card , write three constructors. The latter may also be changing the card, it is necessary to write two ways to adapt to modify the card:. Void useSIM (SIMablecard), void useSIM (SIMable cardI, SIMable card2), write to view the phone card information showMess method void ()
(3) mobile package phone cards SIMOfChinaMobile, the need to achieve SIMable interfaces, while encapsulating the phone number Stringnumber.
(4) package Unicom mobile phone card SIMOChinaUnicom, the need to achieve SIMable interfaces, while encapsulating the phone number String
numberf
(5) end write emulation program execution entrance Test. create Mobile objects and moving objects, and China Unicom card card object to view the information.

The main class

import com.cn.jiekou.SIMable;
import com.cn.lei.MobileTelephone;
import com.cn.lei.SIMOFChinaMoblie;
import com.cn.lei.SIMOFChinaUnicom;
 public static void main(String[] args) {
        // TODO code application logic here
      SIMable Moblie=new SIMOFChinaMoblie("158555555555555");
      SIMable Unicom=new SIMOFChinaUnicom("134355353336363");
       MobileTelephone phone=new MobileTelephone(Moblie,Unicom);
       phone.showMess();
}

SIMable Interface:

public interface SIMable {
    void setNumber(String n);
    String giveNumber();
    String giveCorpName();
}

MobileTelephone 类:

import com.cn.jiekou.SIMable;
public class MobileTelephone{
    private SIMable card;
    private SIMable card1;
    private SIMable card2;
   
    public MobileTelephone(SIMable card) {
        this.card = card;
    }

    public MobileTelephone(SIMable card1, SIMable card2) {
        this.card1 = card1;
        this.card2 = card2;
    }
 
    public MobileTelephone() {
    }


    public void useSIM(SIMable card){
        this.card1=card;

    } 
    public void SIM(SIMable card1,SIMable card2){
         this.card1=card1;
        this.card2=card2;

    }
    public void showMess(){
       if(card1==null){
            System.out.println("此手机无卡");
        }
        if((card1!=null&&card2==null)||(card1==null&&card2!=null)){
            System.out.println("手机为单卡手机");
            System.out.println(card1.giveCorpName());
            System.out.println("手机卡为:"+card1.giveNumber());
        }
        if(card1!=null&&card2!=null){
            System.out.println("手机为双卡手机");
            System.out.println("手机卡1为:"+card1.giveNumber());
            System.out.println(card1.giveCorpName());
            System.out.println("手机卡2为:"+card2.giveNumber());
            System.out.println(card2.giveCorpName());
        }
    }


    }

SIMOFChinaMoblie categories:

import com.cn.jiekou.SIMable;

public class SIMOFChinaMoblie implements SIMable{
    private String number;

    public SIMOFChinaMoblie() {
        
    }   
    public SIMOFChinaMoblie(String number) {
        this.number = number;
    }
    public String getNumber() {
        return number;
    }
    public void setNumber(String number) {
        this.number = number;
    }

    public String giveNumber(){
        return number;
    }
    
   
    @Override
    public String giveCorpName() {
        return "ChinaMobile";
    }

}

SIMOFChinaUnicom categories:

import com.cn.jiekou.SIMable;
lass SIMOFChinaUnicom implements SIMable{
    private String number;

  
    public String getNumber() {
        return number;
    }

   
    public void setNumber(String number) {
        this.number = number;
    }

    public SIMOFChinaUnicom(String number) {
        this.number = number;
    }
     public String giveNumber(){
        return number;
    }
   

    @Override
    public String giveCorpName() {
        return "ChinaUnion";
    }

}
Published 24 original articles · won praise 28 · views 2274

Guess you like

Origin blog.csdn.net/weixin_46292455/article/details/104971147