① 求一套完整的java WEB項目的網路購物網站源代碼
/**
*@description:
*@authorchenshiqiangE-mail:[email protected]
*@date2014年9月7日下午2:51:50
*@version1.0
*/
packagecom.example.map;
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.HashSet;
importjava.util.List;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.support.v4.view.PagerAdapter;
importandroid.support.v4.view.PagerTabStrip;
importandroid.support.v4.view.ViewPager;
importandroid.text.Editable;
importandroid.util.Log;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.ExpandableListView;
importandroid.widget.ListView;
importcom..mapapi.map.offline.MKOLSearchRecord;
importcom..mapapi.map.offline.MKOLUpdateElement;
importcom..mapapi.map.offline.MKOfflineMap;
importcom..mapapi.map.offline.MKOfflineMapListener;
importcom.example.map.adapters.OfflineExpandableListAdapter;
importcom.example.map.adapters.OfflineMapAdapter;
importcom.example.map.adapters.OfflineMapManagerAdapter;
importcom.example.map.interfaces.;
importcom.example.map.models.OfflineMapItem;
importcom.example.map.utils.CsqBackgroundTask;
importcom.example.map.utils.ToastUtil;
importcom.example.system.R;
istener,
{
//------------------------Constants------------------------
//-------------------------Fields--------------------------
privateViewPagerviewpager;
privatePagerTabStrippagertab;
privateMySearchViewsvDown;
privateListViewlvDown;
privateMySearchViewsvAll;
;
privateListViewlvSearchResult;
privateList<View>views=newArrayList<View>(2);
privateList<String>titles=newArrayList<String>(2);
privateMKOfflineMapmOffline=null;
;
;
;
privateList<OfflineMapItem>itemsDown;//下載或下載中城市
privateList<OfflineMapItem>itemsAll;//所有城市,與熱門城市及下載管理對象相同
privateList<OfflineMapItem>itemsProvince;
privateList<List<OfflineMapItem>>itemsProvinceCity;
//-----------------------Constructors----------------------
//--------Methodsfor/fromSuperClass/Interfaces-----------
@Override
protectedvoidonCreate(BundlesavedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offline_map);
// finalStringpackname=this.getPackageName();
// PackageInfopackageInfo;
// try
// {
// packageInfo=this.getPackageManager().getPackageInfo(packname,PackageManager.GET_SIGNATURES);
//
//
// if(code==-00)
// {
//初始化離線地圖管理
mOffline=newMKOfflineMap();
mOffline.init(this);
initViews();
viewpager.setCurrentItem(1);
// }
// }
// catch(NameNotFoundExceptione)
// {
// e.printStackTrace();
// }
}
privatebooleanisResumed=false;
@Override
protectedvoidonResume()
{
super.onResume();
if(!isResumed)
{
isResumed=true;
loadData();
}
}
@Override
protectedvoidonDestroy()
{
super.onDestroy();
mOffline.destroy();
}
/**
*
*@authorchenshiqiangE-mail:[email protected]
*@paramtype
*事件類型:MKOfflineMap.TYPE_NEW_OFFLINE,MKOfflineMap.TYPE_DOWNLOAD_UPDATE,MKOfflineMap.TYPE_VER_UPDATE.
*@paramstate
*事件狀態:當type為TYPE_NEW_OFFLINE時,表示新安裝的離線地圖數目.當type為TYPE_DOWNLOAD_UPDATE時,表示更新的城市ID.
*/
@Override
(inttype,intstate)
{
switch(type)
{
caseMKOfflineMap.TYPE_DOWNLOAD_UPDATE:
MKOLUpdateElementupdate=mOffline.getUpdateInfo(state);
if(setElement(update,true)!=null)
{
if(itemsDown!=null&&itemsDown.size()>1)
{
Collections.sort(itemsDown);
}
refreshDownList();
}
else
{
downAdapter.notifyDataSetChanged();
}
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
break;
caseMKOfflineMap.TYPE_NEW_OFFLINE:
//有新離線地圖安裝
Log.d("OfflineDemo",String.format("addofflinemapnum:%d",state));
break;
caseMKOfflineMap.TYPE_VER_UPDATE:
//版本更新提示
break;
}
}
/**
*網路下載狀態改變(暫停--》恢復)居然不回調,所以改變狀態時自己得增加介面監聽狀態改變刷新界面
*
*@authorchenshiqiangE-mail:[email protected]
*@paramitem
*有狀態改變的item
*@paramremoved
*item是否被刪除
*/
@Override
publicvoidstatusChanged(OfflineMapItemitem,booleanremoved)
{
if(removed)
{
for(inti=itemsDown.size()-1;i>=0;i--)
{
OfflineMapItemtemp=itemsDown.get(i);
if(temp.getCityId()==item.getCityId())
{
itemsDown.remove(i);
}
}
refreshDownList();
}
else
{
loadData();
downAdapter.notifyDataSetChanged();
}
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
}
//---------------------Methodspublic----------------------
publicvoidtoDownloadPage()
{
viewpager.setCurrentItem(0);
}
//---------------------Methodsprivate---------------------
privatevoidinitViews()
{
//TODO
viewpager=(ViewPager)findViewById(R.id.viewpager);
pagertab=(PagerTabStrip)findViewById(R.id.pagertab);
LayoutInflaterinf=LayoutInflater.from(this);
Viewv1=inf.inflate(R.layout.view_offline_download,null,false);
svDown=(MySearchView)v1.findViewById(R.id.svDown);
lvDown=(ListView)v1.findViewById(R.id.lvDown);
views.add(v1);
Viewv2=inf.inflate(R.layout.view_offline_countrys,null,false);
svAll=(MySearchView)v2.findViewById(R.id.svAll);
lvWholeCountry=(ExpandableListView)v2.findViewById(R.id.lvWholeCountry);
lvSearchResult=(ListView)v2.findViewById(R.id.lvSearchResult);
views.add(v2);
titles.add("下載管理");
titles.add("城市列表");
pagertab.setTabIndicatorColor(0xff00cccc);
pagertab.setDrawFullUnderline(false);
pagertab.setBackgroundColor(0xFF38B0DE);
pagertab.setTextSpacing(50);
viewpager.setOffscreenPageLimit(2);
viewpager.setAdapter(newMyPagerAdapter());
svDown.setSearchListener(newMySearchView.SearchListener()
{
@Override
publicvoidafterTextChanged(Editabletext)
{
refreshDownList();
}
@Override
publicvoidsearch(Stringtext)
{
}
});
svAll.setSearchListener(newMySearchView.SearchListener()
{
@Override
publicvoidafterTextChanged(Editabletext)
{
refreshAllSearchList();
}
@Override
publicvoidsearch(Stringtext)
{
}
});
downAdapter=newOfflineMapManagerAdapter(this,mOffline,this);
lvDown.setAdapter(downAdapter);
allSearchAdapter=newOfflineMapAdapter(this,mOffline,this);
lvSearchResult.setAdapter(allSearchAdapter);
allCountryAdapter=(this,mOffline,this);
lvWholeCountry.setAdapter(allCountryAdapter);
lvWholeCountry.setGroupIndicator(null);
}
/**
*刷新下載列表,根據搜索關鍵字及itemsDown下載管理數量變動時調用
*/
privatevoidrefreshDownList()
{
Stringkey=svDown.getInputText();
if(key==null||key.length()<1)
{
downAdapter.setDatas(itemsDown);
}
else
{
List<OfflineMapItem>filterList=newArrayList<OfflineMapItem>();
if(itemsDown!=null&&!itemsDown.isEmpty())
{
for(OfflineMapItemi:itemsDown)
{
if(i.getCityName().contains(key))
{
filterList.add(i);
}
}
}
downAdapter.setDatas(filterList);
}
}
/**
*刷新所有城市搜索結果
*/
()
{
Stringkey=svAll.getInputText();
if(key==null||key.length()<1)
{
lvSearchResult.setVisibility(View.GONE);
lvWholeCountry.setVisibility(View.VISIBLE);
allSearchAdapter.setDatas(null);
}
else
{
lvSearchResult.setVisibility(View.VISIBLE);
lvWholeCountry.setVisibility(View.GONE);
List<OfflineMapItem>filterList=newArrayList<OfflineMapItem>();
if(itemsAll!=null&&!itemsAll.isEmpty())
{
for(OfflineMapItemi:itemsAll)
{
if(i.getCityName().contains(key))
{
filterList.add(i);
}
}
}
allSearchAdapter.setDatas(filterList);
}
}
privatevoidloadData()
{
newCsqBackgroundTask<Void>(this)
{
@Override
protectedVoidonRun()
{
//TODOAuto-generatedmethodstub
//導入離線地圖包
//將從官網下載的離線包解壓,把vmp文件夾拷入SD卡根目錄下的BaiMapSdk文件夾內。
//把網站上下載的文件解壓,將BaiMapvmpl裡面的.dat_svc文件,拷貝到手機BaiMapSDK/vmp/h目錄下
intnum=mOffline.importOfflineData();
if(num>0)
{
ToastUtil.showToastInfo(BaiOfflineMapActivity.this,"成功導入"+num+"個離線包",false);
}
List<MKOLSearchRecord>all=null;
try
{
all=mOffline.getOfflineCityList();
}
catch(Exceptione)
{
e.printStackTrace();
}
if(all==null||all.isEmpty())
{
ToastUtil.showToastInfo(BaiOfflineMapActivity.this,"未獲取到離線地圖城市數據,可能有其他應用正在使用網路離線地圖功能!",false);
returnnull;
}
List<MKOLSearchRecord>hotCity=mOffline.getHotCityList();
HashSet<Integer>hotCityIds=newHashSet<Integer>();
if(!hotCity.isEmpty())
{
for(MKOLSearchRecordr:hotCity)
{
hotCityIds.add(r.cityID);
}
}
itemsAll=newArrayList<OfflineMapItem>();
itemsDown=newArrayList<OfflineMapItem>();
itemsProvince=newArrayList<OfflineMapItem>();
itemsProvinceCity=newArrayList<List<OfflineMapItem>>();
//cityType0:全國;1:省份;2:城市,如果是省份,可以通過childCities得到子城市列表
//全國概略圖、直轄市、港澳子城市列表
ArrayList<MKOLSearchRecord>childMunicipalities=newArrayList<MKOLSearchRecord>();
proHot.cityName="熱門城市";
proHot.childCities=cs;
List<MKOLUpdateElement>updates=mOffline.getAllUpdateInfo();
if(updates!=null&&updates.size()>0)
{
}
@Override
protectedvoidonResult(Voidresult)
{
//TODOAuto-generatedmethodstub
refreshDownList();
refreshAllSearchList();
allCountryAdapter.setDatas(itemsProvince,itemsProvinceCity);
}
}.execute();
}
② java 源代碼 基礎點的 謝謝
package com.regex;
import java.io.*;
import java.net.URLDecoder;
import java.util.regex.*;
public class Regex {
private int REMARK=0;
private int LOGIC=0;
private int PHYSIC=0;
boolean start=false;
/**
* @param args
*/
public static void main(String[] args) { //測試方法
// TODO Auto-generated method stub
Regex re=new Regex();
re.regCount("Regex.java");
System.out.println("remark Line: "+re.REMARK);
System.out.println("logic Line: "+re.LOGIC);
System.out.println("physic Line: "+re.PHYSIC);
}/**
* @author BlueDance
* @param s
* @deprecated count
*/
public void regCount(String s){
String url=null;
try {
url=URLDecoder.decode(this.getClass().getResource(s).getPath(),"UTF-8");
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
try {
BufferedReader br=new BufferedReader(new FileReader(new File(url)));
String s1=null;
while((s1=br.readLine())!=null){
PHYSIC++;
if(CheckChar(s1)==1){
REMARK++;
System.out.println("純注釋行:"+s1);
}
if(CheckChar(s1)==2){
LOGIC++;
REMARK++;
System.out.println("非純注釋行:"+s1);
}
if(CheckChar(s1)==3)
LOGIC++;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
/**
*
* @param s
* @return int
* @version check s
*/
public int CheckChar(String s){
String s1=null;
if(s!=null)
s1=s.trim();
//System.out.println(regCheck(s1,re));
if(regCheck(s1,"(//.*)")) //判斷//開頭的為純注釋行
return 1;
if(regCheck(s1,"(.*[;{})] *//.*)")) //判斷不是//開頭的非純注釋行
return 2;
if(regCheck(s1,"(//*.*)")){ //判斷/*開頭的純注釋行
start=true;
return 1;
}
if(regCheck(s1,"(.*[;{})]//*.*)")){ //判斷不是/*開頭的非純注釋行
start=true;
return 2;
}
if(regCheck(s1,"(.* */*/)")){ //判斷*/結尾的純注釋行
start=false;
return 1;
}
if(regCheck(s1,"(.* */*/.*)")&&!strCheck(s1)){ //判斷不是*/結尾的非純注釋行
if(strCheck(s1)){
start=false;
return 2;
}
}
if(start==true) //狀態代碼,start即/*開始時start=true*/結束時為false
return 1;
return 3;//ssssllll
}//aeee
/**
*
* @param s
* @param re
* @return boolean
*/
public boolean regCheck(String s,String re){ //正則表達試判斷方法
return Pattern.matches(re,s);
}
public boolean strCheck(String s){ //中間有*/的字元判斷 此方法最關鍵
if(s.indexOf("*/")>0){
int count=0;
String y[]=s.split("/*/");
boolean boo[]=new boolean[y.length];
for (int i = 0; i < y.length-1; i++) {
char c[]=y[i].toCharArray();
for (int j = 0; j < c.length; j++) {
if(c[j]=='\\'&&c[j+1]=='"'){
count++;
}
}
if(count%2==0){
if(countNumber("\"",y[i])%2!=0){
boo[i]=true;
}else{
boo[i]=false;
}
}else{
if(countNumber("\"",y[i])%2==0){
boo[i]=true;
}else{
boo[i]=false;
}
}
}
for(int i=0;i<boo.length;i++){
if(!boo[i])
return false;
}
return true;
}
return false;
}
public int countNumber(String s,String y){ //此方法為我前面寫的字元串出現次數統計方法,不懂的可以看我前面的文章
int count=0;
String [] k=y.split(s);
if(y.lastIndexOf(s)==(y.length()-s.length()))
count=k.length;
else
count=k.length-1;
if(count==0)
System.out.println ("字元串\""+s+"\"在字元串\""+y+"\"沒有出現過");
else
return count;
return -1;
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GoodLucky extends JFrame implements ActionListener{
JTextField tf = new JTextField(); //實例化一個文本域
//設置兩個按鈕
JButton b1 = new JButton("開始");
JButton b2 = new JButton("停止");
boolean isGo = false;
//構造函數
public GoodLucky(){
b1.setActionCommand("start");//在開始按鈕上設置一個動作監聽 start
JPanel p = new JPanel(); //實例化一個可視化容器
//將兩個按鈕添加到可視化容器上面,用add方法
p.add(b1);
p.add(b2);
//在兩個按鈕上增加監聽的屬性,自動調用下面的監聽處理方法actionPerformed(ActionEvent e),如果要代碼有更好的可讀性,可用內部類實現動作
//監聽處理。
b1.addActionListener(this);
b2.addActionListener(this);
//將停止按鈕設置為不可編輯(即不可按的狀態)
b2.setEnabled(false);
this.getContentPane().add(tf,"North"); //將上面的文本域放在面板的北方,也就是上面(上北下南左西右東)
this.getContentPane().add(p,"South"); //將可視化容器pannel放在南邊,也就是下面
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //設置用戶在此窗體上發起 "close" 時默認執行的操作,參數EXIT_ON_CLOSE是使用 System exit 方法退出應用程序。僅在應用程序中使用
this.setSize(300,200); //設置面板大小,寬和高
this.setLocation(300,300); //設置面板剛開始的出現的位置
Cursor cu = new Cursor(Cursor.HAND_CURSOR); //用指定名稱創建一個新的定製游標對象,參數表示手狀游標類型
this.setCursor(cu); //為指定的游標設置游標圖像,即設置游標圖像為上面所創建的手狀游標類型
this.setVisible(true); //將面板可視化設置為true,即可視,如果為false,即程序運行時面板會隱藏
tf.setText("welcome you! "); //設置面板的標題為歡迎
this.go(); //調用go方法
}
public void go(){
while(true){ //這里是死循環,也就是說用戶不點擊停止按鈕的話他一直循環出現隨機數,直到用戶點擊停止按鈕循環才能推出,具體流程在actionPerformed方法中控制。
if(isGo == true){ //上面所定義的isGo的初始值為false,所以程序第一次到此會跳過
String s = ""; //設置空字元串
for(int j = 1; j <= 7;j++){ //產生7個隨機數
int i = (int)(Math.random() * 36) + 1;//每個隨機數產生方式,這里定義靈活,可以自由定義隨機數產生的方式
if(i < 10){
s = s + " 0" + i; //如果產生的隨機數小於10的話做處理:這里就牽扯到一個重要的概念,簡單敘述一下:
/*
當一個字元串與一個整型數項相加的意思是連接,上面的s = s + " 0" + i的意思是字元串s鏈接0再連接整型i值,而不會導致0和整型的i相加,
產生的效果為s0i,由於s為空字元串(上面定義過的),所以當i小於零時,在個位數前面加上0,比如產生的隨機數i為7的話,顯示效果為 07.
*/
}else{
s = s + " " + i; //如果產生的隨機數比10打的話,那麼加上空格顯示,即數字和數字之間有個空格
}
//以上循環循環七次,以保證能出現7個隨機數
}
tf.setText(s); //將產生的隨機數全部顯示在文本域上,用文本域對象tf調用它的設置文本的方法setText(String)實現。
}
//以下為線程延遲
try{
Thread.sleep(10); //線程類同步方法sleep,睡眠方法,括弧里的單位為ms。
}catch(java.lang.InterruptedException e){
e.printStackTrace(); //異常捕獲,不用多說。
}
}
}
//以下是上面設置的事件監聽的具體處理辦法,即監聽時間處理方法,自動調用
public void actionPerformed(ActionEvent e){ //傳入一個動作事件的參數e
String s = e.getActionCommand(); //設置字元串s來存儲獲得動作監聽,上面的start
/*
以下這個條件語句塊的作用為:用戶點擊開始後(捕獲start,用方法getActionCommand()),將命令觸發設置為true,從而執行上面的go方法中的循環體(因為循環體中要求isGo參數為true,而初始為false)。
執行循環快產生隨機數,並將開始按鈕不可編輯化,而用戶只可以使用停止按鈕去停止。如果用戶按下停止時,也就是沒有傳入參數「start」的時候,
執行else語句塊中的語句,isGo設置為false,將不執行上面go中的循環語句塊,從而停止產生隨機數,並顯示,並且把開始按鈕設置為可用,而把
停止按鈕設置為不可用,等待用戶按下開始再去開始新一輪循環產生隨機數。
*/
if(s.equals("start")){ //如果捕獲到start,也就是用戶觸發了動作監聽器,那麼下面處理
isGo = true; //設置isGo為true
b1.setEnabled(false); //將開始按鈕設置為不可用
b2.setEnabled(true); //將停止按鈕設置為可用
}else{
isGo = false; //將isGo設置為false,isGo為循環標志位
b2.setEnabled(false); //設置停止按鈕為不可用(注意看是b2,b2是停止按鈕)
b1.setEnabled(true); //設置開始按鈕為可用
}
}
public static void main(String[] args){
new GoodLucky(); //產生類的實例,執行方法
}
}
③ 求一套完整的javaweb項目的源代碼
問津也許可以幫到你,網路搜索「問津」,平台上有很多專業的專家或許可以解答你的問題,個人認為,專業的事請專業的人完成,是為雙贏~
④ 求一套完整的JAVA WEB項目的網路購物網站源代碼
雖然源碼便宜到十塊錢能買一套或者n套了吧,不過10分就想買還是有點too young too sample
⑤ 求一套完整的javaweb項目的購物網站源代碼!謝謝大神!!
基於J2EE實戰竭誠網上商城B2C購物系統開發配Android版購物客戶端(JFreeChart3D)
1000元。
視頻教材+源碼。
⑥ 求一套java開發PC端直播平台網站的源碼
https://github.com/daniulive/SmarterStreaming
國內外為數不多不依賴開源框
架、不依賴CDN實現秒開、公網毫秒級延遲、跨平台(windows/android/iOS)rtmp推流、rtmp/rtsp直播播放利
器"SmarterStreaming",系daniulive(大牛直播)出品的跨平台視頻採集、直播SDK(支持rtmp推流/rtmp播放
/rtsp播放,如windows推流(windows pusher)/android推流(android pusher)/iOS推流(iOS
pusher)/windows播放器(windows player)/android播放器(android player)/iOS播放器(iOS
player)),也許是最靠譜的視頻直播推流、播放SDK之一,助您輕松實現類似於花椒、映客、斗魚手機直播推送與播放。
⑦ 哪裡有免費java源代碼下
java 開源社區有,google或網路吧
⑧ 拿過一套java的源碼怎麼在本地電腦運行起來能詳細的說一下嗎一步一步,菜鳥
你可以根據java的源碼,配置環境,源碼要求不同,環境不同,有些配置參數沒有配置,不一定能運行起來,你可以先用編輯工具看看,當然你自己代碼能力得可以,有其他不會的或者要具體給你看的話也可以直接找額代解決,謝謝
⑨ 求幾個JAVA小項目源代碼,供自己學習參考
package com.test01;
import java.util.Scanner;
public class oop5 { public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// int x = 9;
// int y = 1;
int x = sc.nextInt();
int y = sc.nextInt();
int z;
z = add(x, y);
System.out.println("x的值為:" + x);
System.out.println("y的值為:" + y);
System.out.println("二者之和為:" + z);
}
/** 四種小演算法 */
// 加法運算
public static int add(int a, int b) {
int c;
c = a + b;
return c;
}
// 減法運算
public static int jian(int d, int v) {
int m;
m = d - v;
return m;
}
// 乘積運算
public static int addAdd(int q, int w) {
int e;
e = q * w;
return e;
}
// 除法運算
public static int chu(int p, int k) {
int f;
f = p / k;
return f;
}
}
⑩ 高分求兩個簡單的JAVA設計源代碼
上面 wukun12同學寫的不錯,但我想還不能運行,並且還不太完善。我給個能運行的:(注意:文件名為:Test.java)
//要實現對象間的比較,就必須實現Comparable介面,它裡面有個compareTo方法
//Comparable最好使用泛型,這樣,無論是速度還是代碼量都會減少
@SuppressWarnings("unchecked")
class Student implements Comparable<Student>{
private String studentNo; //學號
private String studentName; //姓名
private double englishScore; //英語成績
private double computerScore; //計算機成績
private double mathScore; //數學成績
private double totalScore; //總成績
//空構造函數
public Student() {}
//構造函數
public Student(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
this.studentNo = studentNo;
this.studentName = studentName;
this.englishScore = englishSocre;
this.computerScore = computerScore;
this.mathScore = mathScore;
}
//計算總成績
public double sum() {
this.totalScore = englishScore+computerScore+mathScore;
return totalScore;
}
//計算評測成績
public double testScore() {
return sum()/3;
}
//實現compareTO方法
@Override
public int compareTo(Student student) {
double studentTotal = student.getTotalScore();
return totalScore==studentTotal?0:(totalScore>studentTotal?1:-1);
}
//重寫toString方法
public String toString(){
return "學號:"+this.getStudentNo()+" 姓名:"+this.getStudentName()+" 英語成績:"+this.getEnglishScore()+" 數學成績:"+this.getMathScore()+" 計算機成績:"+this.getComputerScore()+" 總成績:"+this.getTotalScore();
}
//重寫equals方法
public boolean equals(Object obj) {
if(obj == null){
return false;
}
if(!(obj instanceof Student)){
return false;
}
Student student = (Student)obj;
if(this.studentNo.equals(student.getStudentName())) { //照現實來說,比較是不是同一個學生,應該只是看他的學號是不是相同
return true;
} else {
return false;
}
}
/*以下為get和set方法,我個人認為,totalScore的set的方法沒必要要,因為它是由其它成績計算出來的
在set方法中,沒設置一次值,調用一次sum方法,即重新計算總成績
*/
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
sum();
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
sum();
}
public double getEnglishScore() {
return englishScore;
}
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
sum();
}
public double getComputerScore() {
return computerScore;
}
public void setComputerScore(double computerScore) {
this.computerScore = computerScore;
sum();
}
public double getMathScore() {
return mathScore;
}
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
sum();
}
public double getTotalScore() {
return totalScore;
}
}
//Student子類學習委員類的實現
class StudentXW extends Student {
//重寫父類Student的testScore()方法
@Override
public double testScore() {
return sum()/3+3;
}
public StudentXW() {}
//StudentXW的構造函數
public StudentXW(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}
//Student子類班長類的實現
class StudentBZ extends Student {
//重寫父類Student的testScore()方法
@Override
public double testScore() {
return sum()/3+5;
}
public StudentBZ() {}
//StudentXW的構造函數
public StudentBZ(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}
//測試類
public class Test {
public static void main(String[] args) {
//生成若干個student類、StudentXW類、StudentBZ類
Student student1 = new Student("s001","張三",70.5,50,88.5);
Student student2 = new Student("s002","李四",88,65,88.5);
Student student3 = new Student("s003","王五",67,77,90);
StudentXW student4 = new StudentXW("s004","李六",99,88,99.5);
StudentBZ student5 = new StudentBZ("s005","朱漆",56,65.6,43.5);
Student[] students = {student1,student2,student3,student4,student5};
for(int i = 0 ; i<students.length; i++){
double avgScore = students[i].testScore();
System.out.println(students[i].getStudentName()+"學生的評測成績為:"+ avgScore+"分");
}
}
}
運行結果為:
張三學生的評測成績為:69.66666666666667分
李四學生的評測成績為:80.5分
王五學生的評測成績為:78.0分
李六學生的評測成績為:98.5分
朱漆學生的評測成績為:60.03333333333333分