Java编程高手速度来啊~~帮忙写一程序,搞定了给100分!

作者&投稿:姜彦 (若有异议请与网页底部的电邮联系)
JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!~

其实是很简单的程序,就是无限循环和条件表达式的运用而已。代码如下:
import java.util.Scanner;public class ElectronicDog {private static double timeLeft = 0; // 剩余时间private static int happiness = 1; // 幸福值(初始为1)private static int energy = 2; // 能量值(初始为2)private static Scanner sc;private static double sleepTimeLeft = 10; // 睡眠时间间隔,超过则小狗离开private static double feedTimeLeft = 0; // 饲养时间间隔,小于间隔则无效public static void main(String[] args) {sc = new Scanner(System.in);int days = 0;// 输入天数while(days 0) { // 如果剩余时间小于0则游戏结束showState();if(happiness 0) { // 如果太过频繁喂养,则本次命令无效continue;} else { // 如果喂养有效,则喂养时间重置feedTimeLeft = 3;}}sleepTimeLeft -= ops.timeSpent;}feedTimeLeft -= ops.timeSpent;happiness += ops.happinessGained;energy += ops.energyConsumed;timeLeft -= ops.timeSpent;}if(timeLeft 4) {System.out.print("Choice: ");if(sc.hasNextInt()) {choice = sc.nextInt();}}Command cmd = Command.values()[choice - 1];return cmd;}private static String getTime() {int hour = (int) Math.floor(timeLeft);double min = timeLeft - hour;return String.format("%02d : %02d", hour, (int) (min * 60));}}/** * 对小狗发出的命令 */enum Command {Walk(1, 3, -2), Feed(0.5f, 1, 5), Sleep(8, -8, -4), Play(2, 2, -1);public float timeSpent;public int happinessGained;public int energyConsumed;private Command(float timeSpent, int happinessGained, int energyConsumed) {this.timeSpent = timeSpent;this.happinessGained = happinessGained;this.energyConsumed = energyConsumed;}}部分截图如下


这是用数组做的,对正则表达式不熟。
第一行输入单词串,如work back come deal desk book java tool face
第二行输入数字串,如8665 3325
输出: 8665:tool
3325:deal
不知道是不是这个意思

package ;//添加你的包名
import java.io.*;
import java.util.StringTokenizer;

public class Test {
public static void main(String[] args) throws IOException {
final int MAX = 100; // 假设最多有100个单词
String[] str = new String[MAX];
String[] numStr = new String[MAX];
int j = 0, numberOfWord;
boolean bool = false;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String wordString = br.readLine();
StringTokenizer temp = new StringTokenizer(wordString);

while (temp.hasMoreTokens()) { // 分割字符串并得到单词
str[j++] = temp.nextToken("
\f");
}
Word word = new Word(str, j);// 将得到的单词保存到Word类中

numberOfWord = j;
j = 0;
String numString = br.readLine();
temp = new StringTokenizer(numString);
while (temp.hasMoreTokens()) { // 分割字符串并得到数字串
numStr[j++] = temp.nextToken(" ");
}

// System.out.println(numStr+"_"+word.num[0]);
for (int i = 0; i < j; i++) {
if (isNumber(numStr[i])) { // 若数字串合法
for (int k = 0; k < numberOfWord; k++) {
if (numStr[i].equals(word.num[k])) {
bool = true;
System.out.println(word.num[k] + ":" + word.word[k]);
}
}
}
}

if (!bool)
System.out.println("there is no result");
}

public static boolean isNumber(String numString) { // 判断数字串的合法性
char[] number = numString.toCharArray();
for (int i = 0; i < numString.length(); i++) {
if (number[i] > '9' || number[i] < '2') { // 检查输入合法性
return false;
}
}
return true;
}
}

class Word {
public String[] word;
public String[] num;

public Word(String[] strings, int leng) {
word = new String[leng];
num = new String[leng];
for (int i = 0; i < leng; i++) {
word[i] = strings[i];
num[i] = wordToNum(strings[i]);
}
}

public static String wordToNum(String string) { // 将单词转化为数字串

// "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"
int diff;
String result = "";
String[] number = { "2", "3", "4", "5", "6", "7", "8", "9" };
try {
char[] s = string.toCharArray();
for (int i = 0; i < string.length(); i++) {
diff = s[i] - 'a';
if (diff < 18)
result += number[diff / 3];
else if (diff < 25)
result += number[(diff - 1) / 3];
else {
result += "9";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}

很简单啊?你要写那个?
帮你写个最简单的
第一题:
import java.util.Scanner;

/**
* Created by IntelliJ IDEA.
* User: guangzhi
* Date: 11-10-19
* Time: 下午2:13
* To change this template use File | Settings | File Templates.
*/
public class JiSuan {
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
int score = 0;
for(int i = 0; i < 10 ; i++){
score = score + (new JiSuan().compute(i,cin))*10;
}
System.out.println("Score :"+score);
}
public int compute(int count,Scanner cin){
int numA = (int) (Math.random()*10)+1;
int numB = (int) (Math.random()*10)+1;
int operate = (int)(Math.random()*4);

if(operate == 0){
System.out.println("Question " + count + ":"+ numA + "+" + numB + "=?");
int myAnswer = cin.nextInt();
int result = numA + numB;
if(myAnswer == result){
return 1;
}else{
return 0;
}
}else if(operate == 1){
System.out.println("Question " + count + ":"+ numA + "-" + numB + "=?");
int myAnswer = cin.nextInt();
int result = numA - numB;
if(myAnswer == result){
return 1;
}else{
return 0;
}
}else if(operate == 2){
System.out.println("Question " + count + ":"+ numA + "*" + numB + "=?");
int myAnswer = cin.nextInt();
int result = numA * numB;
if(myAnswer == result){
return 1;
}else{
return 0;
}
}else{
System.out.println("Question " + count + ":"+ numA + "/" + numB + "=?(no radix point)");
int myAnswer = cin.nextInt();
int result = numA / numB;
if(myAnswer == result){
return 1;
}else{
return 0;
}
}
}
}

第二个:
import java.util.Scanner;

/**
* Created by IntelliJ IDEA.
* User: guangzhi
* Date: 11-10-19
* Time: 下午1:47
* To change this template use File | Settings | File Templates.
*/
public class CaiShuZi {
public static void main(String[] args){
int r = (int)(Math.random()*100);
int guessNumber;
int count = 1;

Scanner cin = new Scanner(System.in);
System.out.print("System generate a random number.Please enter your guess number:");
guessNumber = cin.nextInt();

while(true){
if(guessNumber < r){
System.out.println("Your number is less than the random number.Please guess again: ");
count ++;
guessNumber = cin.nextInt();
}else if(guessNumber > r){
System.out.println("Your number is greater than the random number.Please guess again: ");
count ++;
guessNumber = cin.nextInt();
}else{
switch (count){
case 1:
System.out.print("Perfect "+count);
break;
case 2:
System.out.print("Congratulation "+count);
break;
case 3:
System.out.print("Nice "+count);
break;
case 4:
System.out.print("Good "+count);
break;
case 5:
System.out.print("So So "+count);
break;
default:
System.out.print("You can do it better.");
}
break;
}
}

}
}

有几题还是挺简单的,就是题目太多了,难得敲出来

现作的, 有bug的话站内短信我

要处理的文件必须先改成英文名( 只含ASCII的名字 )
fstream不能直接打开中文名文件, 而setlcale和locale::global也会造成不能显示或报错( 网上的方法和我自己尝试都不行 ), 我也不想用c或api来代替, 只能凑合一下了; 或者你自己改下代码, 用其他文件打开方式

#include


CSOL和CF还有AVA哪个好玩,我是上班族
CF不用说了,G,素质不是一般的差,但是金币枪买了是永久的,CSOL金币枪有限制,对于上班族来说买了之后几天不玩就到期,很麻烦的,还有AVA没玩过,求指点,这3个游戏哪个... CF 不用说了,G,素质 不是一般的差,但是金币枪买了是永久的,CSOL金币枪有限制,对于上班族来说买了之后几天不玩就到期,很麻烦的,还有...

如何学好java语言啊?
学习Java的四个阶段:一:Javase基础 二:网页三剑客html+css+js 三:JavaWeb和数据库:四:JavaEE框架:企业级开发,Struts2、Spring框架、Hibernate框架、Maven核心技术、MyBaits框架、高手进阶;如果找不到学习资源,可以点击这里下载。当你学完了Java,应该如何去找工作?一.最重要的还是自身技能,这是...

activex问题
各位高手!!我的IE被我卸载le!!我改用firebox了!但上网就会出现在当前安全设置禁止运行该页中的activex...要将控件装载到Web浏览器时,很可能要通过速度很慢的电话线。现在,控件的大小已经是非常关键的问题。...JavaBeans(基于J ava的组件结构)。ActiveX控件,基本上都是和Windows捆绑在一起、以二进制机器代码发放...

.NET概念清楚的高手请进来,问一些关于.NET概念性的问题
用这个当答案,小心被人笑,所以不要放分哦~~~请高手指正~ 因为到目前,我还没用VB.net做过一个东东.我受不了那个巨大的发行包.回答者:k4me - 进士出身 九级 8-3 23:36 VB是visual.basic的简称 和C是不同的语言 C#,C#.NET,C++,C++.NET都是C的系列 而JAVA则是另种!计算机程序设计语言的...

计算机科学与技术专业以后考研的方向有哪些啊?考哪些学校的计算机研究生...
在这方面人才领域的主要问题是,有经验的高手太少,皮毛了解的人太多。 从事企业计算领域,最重要的技能型技术课程是(1)J2EE架构与程序设计(2)大型数据库...特别是在对速度有极高要求的场合(如DSP处理器的高速图像采集和图像解压缩),目前主要还要靠汇编写程序(我看到过很多公司是这样做的)。当您在一个嵌入式...

谢通门县13023653651: JAVA高手帮忙写3段代码,急……………………
长沙变复方: 第一个问题: 我建议你不要用工具,最好用手写代码,然后javac java 编译运行,你就能清楚了, 第二个,有难度哦,要是你可以,你可以直接重写Object类,(注:是在JDK里面重写Object类,),在Object的构造方法里面用一个静态变量去记录实例化Object的次数. 因为所有类都继承自Object,所以,你就需要监控Object的实例化次数,就OK了, 第三个问题,和第一个问题一样的.

谢通门县13023653651: java一个简单小程序,求高手帮忙编写,万分感谢 -
长沙变复方: class Ball { public void play() { System.out.println("玩球儿..."); } } class Football extends Ball { public void play() { System.out.println("使用足球运动"); } } class Basketball extends Ball { public void play() { System.out.println("...

谢通门县13023653651: JAVA高手请帮帮忙,写出程序!谢谢!考试就靠它了!
长沙变复方: 【程序代码】public class Circle{ //私有变量半径 private int r; //构造方法初始化半径 Circle(int r) { this.r = r; } //获得半径的getR方法 public int getR() { return r; } //计算圆面积方法 public double area(int r) { return 3.14*r*r; } //计算圆周长方法 public...

谢通门县13023653651: 用Java编写程序题,高手来帮忙
长沙变复方: 第一个: public static void main(String[] args){ String s = "sas"; int num = 0; for(int i=0;i<s.length();i++){ if(s.charAt(i)=='c'){ num ++; } } System.out.println("s中c出现的次数为"+num); } 第二个:输入的时候单词之间以1个空格分隔,输入完之后...

谢通门县13023653651: 找java高手帮我写个程序...... -
长沙变复方: /*题目如下:编写一个程序,产生五十道10以内加法算数题, 根据学生输入的答案判断是否正确,第一次答对得2分,第 二次答对得1分.每题最多能回答两次,最后将学生成绩输出,w我这样理解对吗?*/#include"stdio.h" #include"stdlib.h...

谢通门县13023653651: 急!!求大神帮忙编写java代码 -
长沙变复方: import java.util.Arrays;public class Paixu {public static void main(String[] args){int[] array1 = {1, 31,11, 41,21, 51};int[] array2 = {53, 13,33,23, 43, 3};int[] array3 =new int[array1.length+array2.length];//复制array1到array3System.arraycopy(...

谢通门县13023653651: 请学java的高手帮忙编辑一个程序
长沙变复方: public class 点名册{ private String 学生姓名; private int 迟到次数; //TODO 还可以写构造器,方法,按照自己的想法来吧}

谢通门县13023653651: 求编程高手帮我写一个JAVA程序
长沙变复方: package ddd; public class Dish { private String name; private String id; private double unit; private int number; private String text; public Dish(String id,String name,double unit,int number){ this.id=id; this.name=name; this.unit=unit; this.number=...

谢通门县13023653651: 帮忙写个java的代码,感激不尽啊 -
长沙变复方: import java.awt.BorderLayout;import java.awt.Container;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.I

谢通门县13023653651: 跪求高手帮忙编个java程序 编好给加分!
长沙变复方:File file = new File("E:/"); File[] array = file.listFiles(); for (File file2 : array) { if (file2.isFile()) { String name = file2.getName(); String type = name.substring(name.lastIndexOf(".") + 1, name .length()); if ("txt".equals(type)) { System.out.println(...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网