圈小猫Java代码 圈小猫在线玩

求编写java程序题目一道!!//Main.java 测试类
public class Main {
public static void main(String[] args) {
Dog dog = new Dog();
Cat cat = new Cat();
dog.cry();
cat.cry();
}
}
//抽象类
abstract class Animal {
public abstract void cry();
//如果不马上实现cry()方法,请标记abstract
}
class Cat extends Animal{
@Override
public void cry() {
System.out.println("小猫喵喵叫");
}
}
class Dog extends Animal{
@Override
public void cry() {
System.out.println("小狗汪汪叫");
}
}
一道java的题目,不会写,请帮下忙根据给的信息做了个最简单的,若要连接数据库,图形界面我再帮你做
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class SelectCat {
public static void main(String[] args) {
String s;
System.out.print("请输入猫的名字:");
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
s=in.readLine();
if(s.equals("小白")){
System.out.print("名字:小白\n年龄:3岁\n颜色:白色");
}else if(s.equals("小花")){
System.out.print("名字:小花\n年龄:10岁\n颜色:花色");
}else{
System.out.print("您输入的小猫名错误!");
}
}catch(Exception e){
e.printStackTrace();
}
}
}
一道java编程题 , 请各位大神前来解答代码如下:
abstract class Animal {
private String name;
public Animal(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public abstract void enjoy();
}
class Cat extends Animal {
private String eyesColor;
public Cat(String name) {
super(name);
}
public String getEyesColor() {
return eyesColor;
}
public void setEyesColor(String eyesColor) {
this.eyesColor = eyesColor;
}
@Override
public void enjoy() {
System.out.println("小猫" + getName() + "高兴的喵喵叫 。");
}
}
class Dog extends Animal {
private String furColor;
public Dog(String name) {
super(name);
}
public String getFurColor() {
return furColor;
}
public void setFurColor(String furColor) {
this.furColor = furColor;
}
@Override
public void enjoy() {
System.out.println("狗狗" + getName() + "高兴的摇起了尾巴 。");
}
}
class Lady {
private String name;
private Animal pet;
public Lady(String name, Animal pet) {
this.name = name;
this.pet = pet;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Animal getPet() {
return pet;
}
public void setPet(Animal pet) {
this.pet = pet;
}
public void myPetEnjoy() {
pet.enjoy();
}
}
public class App {
public static void main(String[] args) {
Cat cat = new Cat("Jerry");
cat.setEyesColor("蓝色");
Lady lady1 = new Lady("张女士", cat);
lady1.myPetEnjoy();
Dog dog = new Dog("旺财");
dog.setFurColor("黄色");
Lady lady2 = new Lady("王女士", dog);
lady2.myPetEnjoy();
}
}
用java多线程写一个猫叫和狗叫混合的程序 求各位大神指点 本人是it菜鸟级别的一写就写多了,不过包含的东西比较多 , java的重要知识点里面也有
这个结构是简单的处理的,有兴趣的话你可以想象下写成一个小的文字游戏
public class D {

推荐阅读