樓上說的對啊,時間問題,祝你好運啦!
創(chuàng)新互聯(lián)公司長期為上1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為茂名企業(yè)提供專業(yè)的網(wǎng)站設(shè)計制作、做網(wǎng)站,茂名網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
PS:樓主不是我說你,這事早干嘛了~~
感覺上面的答案有點不是為這個題目專門提供的,有很多不是很需要的代碼。
另外用接口編寫,很顯然,所有的學生,教師,裁判都可以用person接口,住宿和吃飯問題就是接口里面的方法。
interface?Person{
public?void?Stay();
public?void?eat();
}
class?Student?implements?Person{
public?void?Stay()?{
System.out.println("住在學生宿舍");
}
public?void?eat()?{
System.out.println("在學生食堂吃飯");
}????
}
class?Teacher?implements?Person{
public?void?Stay()?{
System.out.println("住在教師公寓");
}
public?void?eat()?{
System.out.println("在教師食堂吃飯");
}????
}
class?Judge?implements?Person{
public?void?Stay()?{
System.out.println("住在賓館");
}
public?void?eat()?{
System.out.println("在賓館吃飯");
}????
}
//第一題的答案:
import?java.util.Scanner;
public?class?test?{
public?static?void?main(String[]?args)
{
System.out.println("輸入購買金額:");
Scanner?input=new?Scanner(System.in);
double?a=input.nextDouble();
System.out.println("輸入顧客類型(會員或普通):");
String?b=input.next();
if(b=="會員")
{
if(a=100)
{
a=a*0.8;
System.out.println("需付款:"+a);
}
else
{
System.out.println("需付款:"+a);
}
}
if(b=="普通")
{
if(a=200)
{
a=a*0.75;
System.out.println("需付款:"+a);
}
else
{
System.out.println("需付款:"+a);
}
}
}
}
//下面是第二題答案:
public?class?test?{
public?static?void?main(String[]?args)
{ ???????????
for(int?i?=?0;?i??3;?i++)?
{?
for(int?x?=?i?+?1;?x??3;?x++)?
{?
System.out.print("?");?
}?
for(int?y?=?0;?y??(i?+?1)?*?2?-?1;?y++)?
{?
System.out.print("*");?
}?
System.out.println();?
}?
for(int?i?=?0;?i??4;?i++)?
{?
for(int?x?=?0;?x??i;?x++)?
{?
System.out.print("?");?
}?
for(int?y?=?i;?y??2?*?4?-?i?-?1;?y++)?
{?
System.out.print("*");?
}?
System.out.println();?
}
}
}
按你現(xiàn)在說的這個內(nèi)容,我覺得三個類就能表現(xiàn)出來,我寫了一下,你看看能不能滿足你的要求:
/**
* 運動員信息
* @author songfeng163
*/
public class PlayerState {
private String lx; //運動類型
private String xing; // 姓
private String ming; // 名
public String getLx() {
return lx;
}
public void setLx(String lx) {
this.lx = lx;
}
public String getXing() {
return xing;
}
public void setXing(String xing) {
this.xing = xing;
}
public String getMing() {
return ming;
}
public void setMing(String ming) {
this.ming = ming;
}
//返回姓名信息
@Override
public String toString() {
return xing+ming;
}
}
/**
* 運動員得分信息
* @author songfeng163
*/
public class SoccerPlayerStats {
private PlayerState player; //運動員信息
private double spointsScored; //點球得分
private double assists; //助攻得分
private double penaltyKickRate; //罰球得分概率
public PlayerState getPlayer() {
return player;
}
public void setPlayer(PlayerState player) {
this.player = player;
}
public double getSpointsScored() {
return spointsScored;
}
public void setSpointsScored(double spointsScored) {
this.spointsScored = spointsScored;
}
public double getAssists() {
return assists;
}
public void setAssists(double assists) {
this.assists = assists;
}
public double getPenaltyKickRate() {
return penaltyKickRate;
}
public void setPenaltyKickRate(double penaltyKickRate) {
this.penaltyKickRate = penaltyKickRate;
}
//返回分數(shù)信息
@Override
public String toString() {
return "** PLAYER ADDED **"+ player.toString()+"; Points:"+ spointsScored + "; Assists: "+ assists +"; Penalty Kick %:" + penaltyKickRate;
}
}
這里是主類:
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
/**
* 主類
* @author songfeng163
*/
public class MyMain {
//添加方法
public ListSoccerPlayerStats add(ListSoccerPlayerStats list){
Scanner in=new Scanner(System.in);
PlayerState player=new PlayerState();
SoccerPlayerStats score=new SoccerPlayerStats();
System.out.println("請輸入運動類型:足球,高爾夫,田徑:");
player.setLx(in.next());
System.out.println("請輸入姓:");
player.setXing(in.next());
System.out.println("請輸入名:");
player.setMing(in.next());
System.out.println("請輸入該運動員的點球得分:");
score.setSpointsScored(in.nextDouble());
System.out.println("請輸入該運動員的助攻得分:");
score.setAssists(in.nextDouble());
System.out.println("請輸入該運動員的罰球得分概率:");
score.setPenaltyKickRate(in.nextDouble());
score.setPlayer(player);
System.out.println(score); //顯示新添加的人員
list.add(score);
return list;
}
//刪除方法
public ListSoccerPlayerStats del(ListSoccerPlayerStats list){
Scanner in=new Scanner(System.in);
PlayerState player=new PlayerState();
System.out.println("請輸入要刪除運動員的姓:");
player.setXing(in.next());
System.out.println("請輸入要刪除運動員的名:");
player.setMing(in.next());
for(SoccerPlayerStats score:list){
if(score.getPlayer().getXing().equals(player.getXing())
score.getPlayer().getMing().equals(player.getMing())){
list.remove(score);
break;
}
}
return list;
}
//顯示方法
public void show(ListSoccerPlayerStats list){
System.out.println("當前共有:"+list.size()+"條記錄,內(nèi)容如下:");
for(SoccerPlayerStats score:list){
System.out.println(score);
}
}
//保存方法
public ListSoccerPlayerStats save(ListSoccerPlayerStats list){
System.out.println("請輸入要保存的文件名:");
Scanner in=new Scanner(System.in);
String fileName=in.next();
try{
BufferedWriter bw = new BufferedWriter(new FileWriter("C:/"+fileName));
for(SoccerPlayerStats score:list){
bw.write(score.toString());
bw.newLine();
}
bw.flush();
bw.close();
}catch(Exception ex){
ex.printStackTrace();
}
System.out.println("** 1 RECORD SAVED TO "+fileName+" **");
return list;
}
public static void main(String[] args) {
MyMain myMain=new MyMain();
Scanner in=new Scanner(System.in);
//如果像你說的是數(shù)組的話,數(shù)據(jù)沒有辦法動態(tài)變化,所以我用了list
ListSoccerPlayerStats list=new ArrayListSoccerPlayerStats();
String cz="QUIT"; //默認的操作為退出
System.out.println("下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?");
String czin=in.next(); //輸入數(shù)據(jù)
cz=czin.toUpperCase(); //轉(zhuǎn)換成大寫
while(!cz.equals("QUIT")){ //不是退出
if(cz.equals("ADD")){ //添加數(shù)據(jù)
list = myMain.add(list);
}else if(cz.equals("REMOVE")){ //刪除數(shù)據(jù)
list = myMain.del(list);
}else if(cz.equals("SHOW")){ //顯示數(shù)據(jù)
myMain.show(list);
}else if(cz.equals("SAVE")){ //保存數(shù)據(jù)
myMain.save(list);
}
System.out.println("下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?");
czin=in.next(); //輸入數(shù)據(jù)
cz=czin.toUpperCase(); //轉(zhuǎn)換成大寫
}
System.out.println("** GOODBYE! **");
}
}
運行結(jié)果如下:
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
add
請輸入運動類型:足球,高爾夫,田徑:
足球
請輸入姓:
王
請輸入名:
明
請輸入該運動員的點球得分:
4
請輸入該運動員的助攻得分:
2
請輸入該運動員的罰球得分概率:
0.25
** PLAYER ADDED **王明; Points:4.0; Assists: 2.0; Penalty Kick %:0.25
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
add
請輸入運動類型:足球,高爾夫,田徑:
高爾夫
請輸入姓:
李
請輸入名:
三
請輸入該運動員的點球得分:
2
請輸入該運動員的助攻得分:
2
請輸入該運動員的罰球得分概率:
0.3
** PLAYER ADDED **李三; Points:2.0; Assists: 2.0; Penalty Kick %:0.3
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
show
當前共有:2條記錄,內(nèi)容如下:
** PLAYER ADDED **王明; Points:4.0; Assists: 2.0; Penalty Kick %:0.25
** PLAYER ADDED **李三; Points:2.0; Assists: 2.0; Penalty Kick %:0.3
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
save
請輸入要保存的文件名:
Playerdata.txt
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
remove
請輸入要刪除運動員的姓:
李
請輸入要刪除運動員的名:
三
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
show
當前共有:1條記錄,內(nèi)容如下:
** PLAYER ADDED **王明; Points:4.0; Assists: 2.0; Penalty Kick %:0.25
下面如何操作(ADD, REMOVE, SHOW, SAVE, QUIT)?
quit
** GOODBYE! **