跪求高手帮忙写个java程序 跪求java高手帮忙写下这个程序,写好我追加20分

作者&投稿:枕鸿 (若有异议请与网页底部的电邮联系)
有意思,我就给你设计下
import java.util.*;
import java.io.*;

class Poker{
private String color;
private String value;
private int inner;
/*inner值是:2-14*/
public Poker(String color,int inner){
this.color=color;
this.inner=inner;
if(inner==11) value="J";
else if(inner==12) value="Q";
else if(inner==13) value="K";
else if(inner==14) value="A";
else value=String.valueOf(inner+1);
this.value=value;
}
public String getColor(){
return this.color;
}
public String getValue(){
return this.value;
}
public int getInner(){
return this.inner;
}
public String getPoker(){
return this.color+this.value;
}
}
class Game{
private Poker[] pokers=new Poker[52];
private Poker[] random;
private String type;
private int level;
public Game(){
for(int i=0;i<pokers.length;i++){
if(i/13==0) {
pokers[i]=new Poker("红桃",i%13+2);
}
if(i/13==1) {
pokers[i]=new Poker("黑桃",i%13+2);
}
if(i/13==2) {
pokers[i]=new Poker("方片",i%13+2);

}
if(i/13==3) {
pokers[i]=new Poker("樱花",i%13+2);

}
}
}
public void print(){
for(int i=0;i<pokers.length;i++){
System.out.println(pokers[i].getPoker());
}
}
public void printSelect(){
System.out.println("-------"+type+"--------");
for(int i=0;i<random.length;i++){
System.out.println(random[i].getPoker());
}
System.out.println("-------------------------------");
}
public void randomSelect(int num,boolean ai){
Set<Integer> set=new HashSet<Integer>();
if(!ai){

Scanner s=new Scanner(System.in);
for(int i=0;i<num;i++){
System.out.println("请输入牌序号(1-52)[当前第"+(i+1)+"张,共"+num+"张]:");
int tmp=s.nextInt();
if(tmp>52 || tmp<1){
System.out.println("错误的序列!");
i--;
continue;
}
if(set.contains(tmp)){
System.out.println("该扑克牌已选取!");
i--;
continue;
}
set.add(i-1);
}
s.close();
}
else{
for(int i=0;i<num;i++){
int tmp=(int)(Math.random()*52);
if(set.contains(tmp)){
i--;
continue;
}
else set.add(i);
}
}
random=new Poker[num];
int m=0;
for(int option:set){
random[m++]=pokers[option];
}
}
public void ruffle(){
for(int i=0;i<52;i++){
int a=(int)(Math.random()*52);
int b=(int)(Math.random()*52);
Poker temp;
temp=pokers[a];
pokers[a]=pokers[b];
pokers[b]=temp;
}
}
//检查是否同花
public boolean isSameColor(){
Set<String> set=new HashSet<String>();
for(int i=0;i<random.length;i++)
set.add(random[i].getColor());
if(set.size()==1) return true;
else return false;
}
//检查是否顺子
public boolean isStraight(){
int[] list=new int[random.length];
for(int i=0;i<random.length;i++)
list[i]=random[i].getInner();
Arrays.sort(list);
for(int i=1;i<random.length;i++)
if(list[i-1]!=list[i]-1) return false;
return true;
}
//检查同花顺
public boolean isSameColorAndStraight(){
if(isSameColor() && isStraight()) return true;
else return false;
}
//最大同花顺A K Q J 10
public boolean isMax(){
if(isSameColorAndStraight()){
int[] list=new int[random.length];
for(int i=0;i<random.length;i++)
list[i]=random[i].getInner();
Arrays.sort(list);
if(list[0]==10 && list[4]==14) return true;
else return false;
}
return false;
}
//检查是否4个一样的
public boolean isBomb(){
Map<Integer,Integer> map=new HashMap<Integer,Integer>();
for(int i=0;i<random.length;i++)
if(map.containsKey(random[i].getInner())) map.put(random[i].getInner(),map.get(random[i].getInner())+1);
else map.put(random[i].getInner(),1);
for(int value:map.keySet()){
if(map.get(value)==4) return true;
}
return false;
}
//检查是否3+2
public boolean isThreeAndTwo(){
Map<Integer,Integer> map=new HashMap<Integer,Integer>();
for(int i=0;i<random.length;i++)
if(map.containsKey(random[i].getInner())) map.put(random[i].getInner(),map.get(random[i].getInner())+1);
else map.put(random[i].getInner(),1);
if(map.size()!=2) return false;
else{
for(int value:map.keySet()){
if(map.get(value)==2 || map.get(value)==3) return true;
else return false;
}
return false;
}
}
//检查有3个一样的
public boolean isThree(){
Map<Integer,Integer> map=new HashMap<Integer,Integer>();
for(int i=0;i<random.length;i++)
if(map.containsKey(random[i].getInner())) map.put(random[i].getInner(),map.get(random[i].getInner())+1);
else map.put(random[i].getInner(),1);
for(int value:map.keySet()){
if(map.get(value)==3) return true;
}
return false;
}
//检查有2个一样的(单对)
public boolean isTwoByOdd(){
Map<Integer,Integer> map=new HashMap<Integer,Integer>();
for(int i=0;i<random.length;i++)
if(map.containsKey(random[i].getInner())) map.put(random[i].getInner(),map.get(random[i].getInner())+1);
else map.put(random[i].getInner(),1);
for(int value:map.keySet()){
if(map.get(value)==2) return true;
}
return false;
}
//检查有2个一样的(双对)
public boolean isTwoByDouble(){
Map<Integer,Integer> map=new HashMap<Integer,Integer>();
int number=0;
for(int i=0;i<random.length;i++)
if(map.containsKey(random[i].getInner())) map.put(random[i].getInner(),map.get(random[i].getInner())+1);
else map.put(random[i].getInner(),1);
for(int value:map.keySet()){
if(map.get(value)==2) number++;
}
if(number==2) return true;
else return false;
}
public void check(){
if(isTwoByOdd()) {type="你手中的牌是单对子";level=1;}
else if(isTwoByOdd()) {type="你手中的牌是双对子";level=2;}
else if(isThree()) {type="你手中的牌是小炸弹";level=3;}
else if(isThreeAndTwo()) {type="你手中的牌是小炸弹加单对子";level=4;}
else if(isBomb()) {type="你手中的牌是核弹";level=7;}
else if(isMax()) {type="恭喜你,你手中的牌是同花大顺";level=9;}
else if(isSameColorAndStraight()) {type="恭喜你,你手中的牌是同花顺";level=8;}
else if(isStraight()) {type="你手中的牌是顺子";level=5;}
else if(isSameColor()) {type="你手中的牌是同花";level=6;}
else {type="你手中的牌比较小";level=0;}
}
public String getType(){
return this.type;
}
public int getLevel(){
return this.level;
}
public void clear(){
random=new Poker[5];
type="";
level=0;
}
public static void main(String[] str){
Game game=new Game();
game.ruffle();
for(int i=0;i<5000;i++){
game.clear();
game.ruffle();
game.randomSelect(5,true);
game.check();
//选择5000次,看看有多少顺子
if(game.getLevel()==5) game.printSelect();
}
}
}

学习

跪求Java高手帮忙在我的程序上补写画笔程序,急需~

是实现java的鼠标事件吧,就是可以在窗体上画画写字什么的?
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class AppletLine extends Applet implements MouseListener{
int sx,sy,ex,ey;
public void init(){
this.setBackground(Color.black);
}
@Override
public void start() {
// TODO Auto-generated method stub
this.addMouseListener(this);
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
g.setColor(Color.yellow);//鼠标画线的颜色
g.drawLine(sx,sy, ex,ey);
}
@Override
public void update(Graphics g) { //重写update方法画线什么的 在写的时候就不会被清除
// TODO Auto-generated method stub
this.paint(g);
}
@Override
public void stop() {
// TODO Auto-generated method stub
super.stop();
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
this.sx=e.getX();
this.sy=e.getY();
}
public void mouseReleased(MouseEvent e) {
this.ex=e.getX();
this.ey=e.getY();
this.repaint();
}
}

5'3" 这个是什么单位
哦 知道了 5英尺3英寸


package com.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CalcWeight {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("输入性别:男性输入M,女性输入W");
String sex = bf.readLine();
while(!sex.equalsIgnoreCase("M") && !sex.equalsIgnoreCase("W")){
System.out.println("输入有误,请重新输入");
sex = bf.readLine();
}
System.out.println("输入身高(身高必须高于5英尺):例如5英尺3英寸 请输入5'3''");
String height = bf.readLine();
while(!judgeHeight(height)){
height = bf.readLine();
}
System.out.println("输入体重(单位是磅)");
String weight = bf.readLine();
while(!judgeNum(weight)){
System.out.println("请输入数字");
weight = bf.readLine();
}
compute(sex, height, weight);
}

public static boolean judgeHeight(String height){
boolean rs=false;
if(height.trim().length()!=0){
if(height.indexOf("'")==-1 || height.lastIndexOf("''")==-1){
System.out.println("输入格式有误,请重新输入");
}else{
try {
int feet = Integer.valueOf(height.substring(0,height.indexOf("'")));
int inches = Integer.valueOf(height.substring(height.indexOf("'")+1,height.lastIndexOf("''")));
if(feet<5){
System.out.println("身高必须高于5英尺,请重新输入");
}else{
rs = true;
}
} catch (NumberFormatException e) {
System.out.println("请输入数字");
}
}
}
return rs;
}
public static boolean judgeNum(String num){
boolean rs=false;
try {
Integer.valueOf(num);
rs = true;
} catch (NumberFormatException e) {
}
return rs;
}
public static void compute(String sex,String height,String weight){
int com_weight=0;
int u_weight = Integer.valueOf(weight);
int feet = Integer.valueOf(height.substring(0,height.indexOf("'")));
int inches = Integer.valueOf(height.substring(height.indexOf("'")+1,height.lastIndexOf("''")));
if(sex.equalsIgnoreCase("w")){
com_weight = 100+ ((feet-5)*12 +inches)*5;
}else{
com_weight = 106+ ((feet-5)*12 +inches)*6;
}
System.out.println("身高:"+feet+"英尺"+inches+"英寸");
System.out.println("最佳体重:" + com_weight + "磅");
System.out.println("您的体重:" + u_weight + "磅" );
double rate=0.00;
rate = (double)u_weight/(double)com_weight;
if(rate>=0.85 && rate<=1.15){
System.out.print("您的体重很正常");
}else{
if(rate<0.85){
System.out.println("您可能偏瘦");
}
if(rate>1.15){
System.out.println("您可能偏胖");
}
}
}

}

高手帮忙用Java设计个计算器程序!
答:import java.awt.*;import java.awt.event.*;public class CalcAppDemo extends Frame{ private TextField t_result;private Panel p_main; //主面板 private Panel p_num; //数字面板 private Panel p_oper; //操作符面板 private Panel p_show; //显示面板 private Button b_num[]; //数字...

高手帮忙设计一个java程序 急用 题目如下 定义一抽象类Column,然后派生...
答:import java.lang.StrictMath.*;abstract class Column { static double s_length; //length 是保留字所以没有用它 static double s_width;static double s_height;abstract double getArea();abstract double getVolume();abstract void display();} class Cylinder extends Column //圆柱体 { double...

Java程序设计.在线等,求高手帮忙.
答:新建一个Student.java类,代码如下:public class Student { // 注册号、姓名、数学、外语、计算机课程成绩 private String id;private String name;private Integer maths;private Integer english;private Integer computer;public Student() { } public Student(String id, String name, Integer maths, ...

求助:请高手帮忙用JAVA程序做一个计算器~
答:(1)import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Calculator extends JFrame { private Container container;private GridBagLayout layout;private GridBagConstraints constraints;private JTextField displayField;//计算结果显示区 private String lastCommand;//保存+,-,*,...

求代码:利用Java做一个新的弹出窗口的小程序
答:重点地是窗体弹出类:WindowsCenter.java 文件一父窗文件名Frame3.java package untitled1;import java.awt.BorderLayout;import javax.swing.JFrame;import javax.swing.JButton;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class Frame3 extends J...

!高分跪求帮忙写一个简单小程序的JAVA课程设计报告(内详!!)
答:连连看java源代码 import javax.swing.*;import java.awt.*;import java.awt.event.*;public class lianliankan implements ActionListener { JFrame mainFrame; //主面板 Container thisContainer;JPanel centerPanel,southPanel,northPanel; //子面板 JButton diamondsButton[][] = new JButton[6][5]...

求编写一个关于I/O的Java程序 高分等
答:import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.Scanner;public class Test { public static void main(String[] args) throws IOException { BufferedWriter bw = new...

java一个简单小程序,求高手帮忙编写,万分感谢
答:static void main(String[] args) { TestMain tm = new TestMain();tm.testPlay();} public void testPlay() { Ball ball = new Football();ball.play();ball = new Basketball();ball.play();} } / D:\>javac TestMain.java D:\>java TestMain 使用足球运动 使用篮球运动 / ...

求java程序!!!大一的java课程设计题目,求高手送程序~~~求大家帮忙啊...
答:完整的Java程序:public class Test32 { public static void main(String[] args) { Complex c1 = new Complex(2, -1);Complex c2 = new Complex(3, 4);int m = 3;System.out.println(c1.toString() + "的绝对值:" + c1.abs());System.out.println(c1.toString() + "自增后:...

高手帮忙写或改份JAVA程序(急)
答:j] = result[i][j] + a[i][k] * a[j][n-k-1];cout << result[i][j] << " ";} cout << endl;} system("Pause");return 0;} // 有什么不懂的email: zhbandnegro@163.com // 不好意思,写完了才发现你要的是java的.你自己可以改一下,不会就给我发邮件.QQ328461492 ...