定義表示學生卡的類,類名為StudentCard,屬相包含∶卡號、學號、學生姓名、余額等屬
定義表示學生卡的類,類名為StudentCard,屬相包含∶卡號、學號、學生姓名、余額等屬性,編寫兩個帶參的構(gòu)造方法,一個構(gòu)造方法實現(xiàn)給四個屬性賦值,另外一個構(gòu)造方法實現(xiàn)給卡號、學號和學生姓名三個屬性賦值,編寫一個方法,實現(xiàn)輸出學生卡的基本信息的功能。編寫測試類使用StudentCard類創(chuàng)建對象,分別調(diào)用兩個構(gòu)造方法,創(chuàng)建兩個學生卡,并調(diào)用對象的方法。

package kehouxiti;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
public class zuoye1 {
//? 定義表示學生卡的類,類名為StudentCard,屬相包含∶卡號、學號、學生姓名、余額等屬性,編寫兩個帶參的構(gòu)造方法,一個構(gòu)造方法實現(xiàn)給四個屬性賦值,另外一個構(gòu)造方法實現(xiàn)給卡號、學號和學生姓名三個屬性賦值,編寫一個方法,實現(xiàn)輸出學生卡的基本信息的功能。編寫測試類使用StudentCard類創(chuàng)建對象,分別調(diào)用兩個構(gòu)造方法,創(chuàng)建兩個學生卡,并調(diào)用對象的方法。
?
public static void main(String[] args) throws UnsupportedEncodingException {
StudentCard a = new StudentCard();
StudentCard a1 = new StudentCard("22208020111", "wuyanzu", "222088888", 0);
StudentCard a2 = new StudentCard("22208020222", "wuyifan", "222086666", 0);
?
}
}
?
class StudentCard {
StudentCard() {
String card;
String number;
String name;
double money;
}
?
StudentCard(String card, String number, String name, double money) throws UnsupportedEncodingException {
PrintStream ps = new PrintStream(System.out, true, "UTF-8");
ps.println(card + "," + number + "," + name + "," + money);
?
}
?
}