java 中怎么修改txt文件中某一行的内容用临时文件,按行读源文件 , 不修改的行,直接输出到临时文件、要修改的行在修改后,再写到临时文件
Java 修改现有代码 源代码已给,修改要求看图 。研究很久是在做不出来,谢谢谢谢interface Poker{
int ACE = 1;
int JACK = 11;
int QUEEN = 12;
int KING = 13;
int CLUBS = 1; //草花最小
int DIAMONDS = 2; //方块
int HEARTS = 3; //红桃
int SPADES = 4; //黑桃最大
public int rank();
public String toString();
}
class Card implements Poker{
private int value; //value表示牌值:1--13
private int suit; //suit表示花色:1--4
public Card(int v,int s) //构造方法:设置牌值和花色
{ value = https://www.04ip.com/post/v; suit = s; }
public int getValue() //返回牌值
{ return value; }
public int getSuit() //返回花色
{ return suit; }
public int rank() //返回牌的排序
{ return 4*(value-1) +suit; }
public String toString() //将牌值和花色转换成字符串
{ String v;
String s;
if (value =https://www.04ip.com/post/= ACE) v="A";
else if (value =https://www.04ip.com/post/= JACK) v="J";
else if (value =https://www.04ip.com/post/= QUEEN) v="Q";
else if (value =https://www.04ip.com/post/= KING) v="K";
else v=String.valueOf(value);
if (suit == CLUBS) s = "草花";
else if (suit == DIAMONDS)s = "方块";
else if (suit == HEARTS) s = "红桃";
else s = "黑桃";
return s + " "+v;
}
}
class CardDeck {
private Card deck []; //deck[]存放一付牌
private int cards; //cards表示还剩几张牌
public CardDeck() //构造方法:创建52张牌 , 填上牌值和花色,洗牌
{ deck = new Card[52]; //创建52张牌
fill(); //填上牌值和花色
shuffle(); //洗牌
}
public void fill() //填上牌值和花色
{ int i; int j;
for (i =1; i = 13; i++)
for (j = 1; j = 4; j++)
deck[4*(i-1) + j - 1]= new Card(i,j);
// deck[0]=草花A,deck[1]=方块A,deck[2]=红桃A,deck[3]=黑桃A,deck[4]=草花2...
cards = 52; //开始有52张牌
}
public void shuffle() //洗牌
{
int next;
for (next = 0 ; nextcards-1; next++) {
int r=(int) (Math.random()*52);
//随机生成0--51的一个数
Card temp = deck [next]; //两张牌交换位置
deck[next] = deck[r];
deck[r] = temp;
}
}
public Card draw() //发一张牌
{
if (cards == 0) return null;
cards--;
return deck[cards];
}
}
class CardDeck2 extends CardDeck{
public CardDeck2(){
super();
}
public void shuffle(){
for(int i = 0; i10; i ++){
super.shuffle();
}
}
public Card[] draw2(){
Card[] card = new Card[2];
for(int i = 0; i2; i ++){
card[i] = super.draw();
}
return card;
}
public boolean compare(Card[] yours, Card[] mine){
int valuecountyou = 0;
int valuecountmine = 0;
int colorcountyou = 0;
int colorcountmine = 0;
for(int i = 0; iyours.length; i ++){
valuecountyou += yours[i].getValue();
valuecountmine += mine[i].getValue();
colorcountyou += yours[i].getSuit();
colorcountmine += mine[i].getSuit();
}
if(valuecountyouvaluecountmine){
return true;
}else if(valuecountyouvaluecountmine){
return false;
}else{
if(colorcountyoucolorcountmine){
return true;
}else
return false;
}
}
}
public class Test2 {
public static void main(String args[]){
CardDeck2 d = new CardDeck2();
int i;
int wins = 0;//wins表示你赢的次数
int rounds = 10; //rounds表示玩牌次数
推荐阅读
- 直播团单工具,主播团播有什么任务
- php显示修改数据类型 php显示修改数据类型无效
- 怎么躺着看电视最健康英语,躺着看电视英文怎么说
- mysql查询横向显示,mysql查询结果变横表
- 电脑直播间头像咋换不了,直播间头像怎么换
- vb.net代码换行符 vb中的换行语句怎么用
- 包含永嘉县小程序模板注册的词条
- 笔记本怎么把显卡变小一点,笔记本调整显卡
- 如何做大理石材推广挣钱,如何做大理石材推广挣钱呢