Java主人
‘壹’ 一个java游戏。主人在梦游。机器人在家捣乱。什么游戏
好像叫个少女噩梦还是啥的,记着原来在360是上下载过
‘贰’ 一个JAVA游戏。主人在梦游。机器人在家捣乱。什么游戏
是机械交换,希望能帮助到你
‘叁’ java程序 一个主人有两只宠物,一条狗一只猫,狗叫旺财,猫叫小花,分别给宠物喂食
publicclassPerson{
publicstaticvoidmain(Stringargs[]){
Animala1=newAnimal("猫","小花","鱼");
Animala2=newAnimal("狗","旺财","骨头");
a1.eat();a2.ert();
}
}
classAnimal{
Stringspecies;
StringanimalName;
StringfoodName;
Animal(Stringspecies,StringanimalName,StringfoodName){
this.species=species;
this.animalName=animalName;
this.foodName=foodName;
}
publicvoideat(){
System.out.print("我的"+species+","+animalName+"吃了:"+foodName);
}
}
//我也才学java不到一个月,我就能理解这么多
//还可以写继承的。亦可以写成多线程的。
//继承就是把Animal类当父类,再写两个类继承它。这里又可以复习多态,哈哈。
//多线程就是同事喂这俩动物。
‘肆’ 程序设计: 猫大叫一声,所有的老鼠都开始逃跑,主人被惊醒(java编写)
1:
public interface Number {
public int nextInt();
}
2:
import java.util.Random;
public class Cat implements Number{
private String name;
private char sex;
public Cat() {
}
public Cat(String aNmae, char aSex) {
this.name = aNmae;
this.sex = aSex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int nextInt() {
int aInt;
aInt = new Random().nextInt(3);
return aInt;
}
}
3:
import java.util.Random;
public class Mouse implements Number{
private String name;
private char sex;
public Mouse() {
}
public Mouse(String aNmae, char aSex) {
this.name = aNmae;
this.sex = aSex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int nextInt() {
int aInt;
aInt = new Random().nextInt(3);
return aInt;
}
}
4:
public class Stage {
public static void main(String[] args) {
Cat cat = new Cat("Tom" , 'M');
Mouse mouse = new Mouse("Jerry", 'M');
int tint;
int mint;
tint = cat.nextInt();
mint = mouse.nextInt();
String result = ((tint > mint)? "抓到" : "跑了");
System.out.println("结果为 : " + result);
}
}
‘伍’ 用Java程序完成以下场景(用继承多态):有一个主人(Master类),他养了两只宠物(Pet类)
publicclassRun{
publicstaticvoidmain(String[]args){
Mastermaster=newMaster();
master.feedDog("鸡骨头");
master.feedCat("鸡骨头");
}
}
classMaster{
privatePetmPet;
privateFoodmFood;
publicvoidfeedCat(Stringfood){
mPet=newCat();
mFood=newFood(food);
mPet.eat(mFood);
}
publicvoidfeedDog(Stringfood){
mPet=newDog();
mFood=newFood(food);
mPet.eat(mFood);
}
}
classDogextendsPet{
@Override
publicvoideat(Foodfood){
System.out.println("正在喂小狗吃"+food.getFood());
if(food.getFood().matches(Food.BONE)){
System.out.println("小狗正在吃"+food.getFood()+"!");
}else{
System.out.println("但是小狗不喜欢吃"+food.getFood()+"!");
}
}
}
classCatextendsPet{
@Override
publicvoideat(Foodfood){
System.out.println("正在喂小猫吃"+food.getFood());
if(food.getFood().matches(Food.FISH)){
System.out.println("小猫正在吃"+food.getFood()+"!");
}else{
System.out.println("但是小猫不喜欢吃"+food.getFood()+"!");
}
}
}
classFood{
publicfinalstaticStringBONE=".*骨.*";
publicfinalstaticStringFISH=".*鱼.*";
privateStringfood;
publicStringgetFood(){
returnfood;
}
publicvoidsetFood(Stringfood){
this.food=food;
}
publicFood(Stringfood){
this.food=food;
}
}
classPet{
publicvoideat(Foodfood){
}
}
‘陆’ 有一款java手机游戏主角是一个机器人然后用主人家里的各种东西来捣主人正在梦游 是什么游戏 不是机械交换
TroubleMaker (MTV FEX'D)
‘柒’ JAVA中的对象和方法有什么区别
对象是主人,方法是主人的枪主人要打猎,就要用枪SO,非静态方法都是从属于对象的必须用对象来调用而对象必须通过类来new
‘捌’ 10分提问 哪位JAVA高手帮我看看这段代码什么意思
公开类设置{
private静态设置c =新的设置();
/**
* 取得系统安装的WEB根目录。
* @return 安装的WEB根目录,如 G:\HighCOM _PRJ \ yichun \产品\ webapp \默认耳朵\默认战争
*/
public静态串findHomeDir () {
String home_path = "";
if (c ==零位) {
c =新的设置();
}
try {
String s = c.getClass () .getResource (“设置” +
" .class ") .toString ();
File f =新的文件;
//取得发布目录的绝对路径,从根到web-inf
while (! f.getName () .toLowerCase () .equals (“网inf”)) {
f = f.getParentFile ();
}
//取得web-inf的上一级目录
home_path = f.getParentFile () .getPath ();
//判断返回路径的头的字符串 jar包发布瓶子:文件: linux class发布文件:
if (home_path.startsWith (“瓶子:文件:")) {
home_path = home_path.substring (9, home_path.length ());
},如果(home_path.startsWith (“文件:")) {
home_path = home_path.substring (5, home_path.length ());
}
}
catch (例外e) {
e.printStackTrace ();
}
//提换windows操作系统的第一个字符
if (home_path.startsWith (“\ \ ")) {
home_path = home_path.substring (1, home_path.length ());
}
//linux操作系统的第一个字符为/代表根目录
//,如果(home_path.startsWith (“/")) {
//home_path = home_path.substring (1, home_path.length ());
//
//}
try {
//home_path =新的串(home_path.getBytes (“ISO-8859-1”), “gb2312”);
home_path = java.net.UR LDecoder.decode (home_path, “UTF-8”);
//home_path = java.net.UR LEncoder.encode (home_path, “GB2312”);
}抓住(IOException e) {
e.printStackTrace ();
}
return home_path;
}
/**
* 从HTTP请求中取得HTTP请求的协议 (http, https) ,以及服务器的名字、端口号,并组成一个字符串,形为 http://127.0.0.1:8101
* @param请求HTTP请求
* @return 访问本服务器根目录的HTTP地址。
*/
public静态串findRootURL (HttpServletRequest请求) {
String计划= request.getScheme ();
String主人= request.getServerName ();
int口岸= request.getServerPort ();
return计划+ “:“+ java.io.Fi le.separator +主人+” :“+口岸;
}
/**
* 指定索引目录
* @param家串
* @return串
*/
public静态串getIndexHome () {
String dir = findHomeDir () +File.separator+ "索引";
return dir;
}
public静态串getBBSHome () {
String dir = findHomeDir () +File.separator+ " bbs ";
return dir;
}
public主要静止的空隙(串[] args) {
System.out.println (Config.findHomeDir ());
}
}
‘玖’ JAVA代码主人喂宠物吃东西狗只吃骨头猫只吃鱼求代码用多态
/*
animal是个抽象方法,Cat和Dogextends这个就是用的多态
*/
packageTest;
publicclassTest{
publicstaticvoidmain(String[]args){
Feederfeeder=newFeeder();
feeder.feedAnimals();
}
}
abstractclassAnimal{
publicabstractvoideat(Strings);
}
classDogextendsAnimal{
privatefinalStringFOOD="bone";
@Override
publicvoideat(Strings){
if(s==FOOD)
System.out.println("Dogiseatingbones");
else
System.out.println("Not"+this.FOOD+",Dogdon'twanttoeat");
}
}
classCatextendsAnimal{
privatefinalStringFOOD="fish";
@Override
publicvoideat(Strings){
if(s==FOOD)
System.out.println("Catiseatingfishes");
else
System.out.println("Not"+this.FOOD+",Catdon'twanttoeat");
}
}
classFeeder{
privatefinalString[]FOODS={"fish","bone","shit"};
privateAnimalcat;
privateAnimaldog;
Feeder(){
dog=newDog();
cat=newCat();
}
publicvoidfeedAnimals(){
System.out.println("Feedinganimals...");
Stringfood;
for(inti=0;i<FOODS.length;i++){
food=FOODS[i];
if(food=="fish")
this.cat.eat(food);
elseif(food=="bone")
this.dog.eat(food);
else{
System.out.println("NotFishesorBones,is"+food);
}
}
System.out.println("Done!");
}
}
‘拾’ JAVA宠物商店的源代码 系统启动和宠物主人登录的接口具体代码是什么
publicinterface接口A{
publicvoidget();
}
//**************
publicclass接口A的实现类implements接口A{
@Override
publicvoidget(){
System.out.println(1);
}
}
//**************
publicclassTest{
接口Ad=new接口A的实现类();
publicTest(){
d.get();
}
}
虽然可以,但不提倡,因为接口有其自己的存在意义,接口定义行为,一般的都是接口定义,然后用一个类实现。
如果您必须要在接口中实现方法:
publicinterface接口A{
publicvoidget();
publicdefaultvoidset(){
//实现
}
}