---恢复内容开始---
package juxing; //1,定义一个水果类(fruit),水果类中的有 //【属性】:颜色(color)、价格(price)、重量(weigth), //再定义一个<测试类>, //创建一个苹果(apple)的对象, 颜色是"红色",价格是5.5,重量10g。 //然后再创建一个香蕉(banana)的对象,颜色是"黄色",价格是4.2,重量5g。 //最后输出: //苹果的颜色、价格、重量、 //香蕉的颜色、价格、重量、 public class Fruit { String color; double price; double weigth; public Fruit(String color, double price, double weigth) { super(); this.color = color; this.price = price; this.weigth = weigth; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public double getWeigth() { return weigth; } public void setWeigth(double weigth) { this.weigth = weigth; } public static void main(String[] args) { Fruit apple=new Fruit("红色",5.5,10); System.out.print("苹果的颜色是:"+apple.getColor()+","); System.out.print("价格是"+apple.getPrice()+"元,"); System.out.println("重量是"+apple.getWeigth()+"g。"); Fruit banana=new Fruit("黄色",4.2,5); System.out.print("香蕉的颜色是:"+banana.getColor()+","); System.out.print("价格是"+banana.getPrice()+"元,"); System.out.println("重量是"+banana.getWeigth()+"g。"); } }
package juxing; public class People { // 2、定义一个人类,人类中有以下属性:姓名(name),性别(sex),年龄(age),再定义一个测试类 // 创建一个"张三"的对象 // 姓名:张三 // 性别:男 // 年龄:20 // 创建一个"李四"的对象 // 姓名:李四 // 性别:女 // 年龄:21 // 最后输出张三与李四的信息 static String name; static String sex; static int age; public static String getName() { return name; } public void setName(String name) { this.name = name; } public static String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public static int getAge() { return age; } public void setAge(int age) { this.age = age; } public People(String name, String sex, int age) { super(); this.name = name; this.sex = sex; this.age = age; } public static void main(String[] args) { People nanren=new People("张三","男",20); System.out.println("第一个人叫"+getName()+",性别"+getSex()+",年龄"+getAge()); People nvren=new People("李四","女",21); System.out.println("第二个人叫"+getName()+",性别"+getSex()+",年龄"+getAge()); } }
package juxing; public class Table { // 3、定义一个桌子类,属性有:材料、编号、价格, // 再定义一个测试类,在测试类中分别创建两张桌子, // 分别给他们赋值,最后输出 public static String Cailiao; static int Bianhao; public static double price; public static String getCailiao() { return Cailiao; } public void setCailiao(String cailiao) { Cailiao = cailiao; } public static int getBianhao() { return Bianhao; } public void setBianhao(int bianhao) { Bianhao = bianhao; } public static double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public Table(String cailiao, int bianhao, double price) { super(); Cailiao = cailiao; Bianhao = bianhao; this.price = price; } public static void main(String[] args) { Table one=new Table("木头",1,1.23); System.out.println("第一张桌子编号是"+getBianhao()+",材料是"+getCailiao()+",价格是"+getPrice()); Table two=new Table("铁",2,2.34); System.out.println("第二张桌子编号是"+getBianhao()+",材料是"+getCailiao()+",价格是"+getPrice()); } }
package juxing; public class Pig { // 4,写一个传奇游戏中的猪类,类中有属性:颜色(color)、 // 重量(weight)、攻击力(attack)、准确度(accuracy)。 // 再写一个测试类,生成一个猪的对象,将此猪的颜色值为“白色(white)”, // 重量为5,攻击力为50点,准确度为0.8。 // 要求输出此猪的信息格式为:一只白色的猪,重量5,攻击为50点血,准确度为0.8, // 我好怕怕呀 // // // 可以加上静态,重载 String color; double weight; int attack; double accuracy; public String getColor() { return color; } public void setColor(String color) { this.color = color; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } public int getAttack() { return attack; } public void setAttack(int attack) { this.attack = attack; } public double getAccuracy() { return accuracy; } public void setAccuracy(double accuracy) { this.accuracy = accuracy; } public Pig(String color, double weight, int attack, double accuracy) { super(); this.color = color; this.weight = weight; this.attack = attack; this.accuracy = accuracy; } public static void main(String[] args) { Pig zhu=new Pig("白色",5,50,0.8); System.out.println("一只"+zhu.getColor()+"的猪,重量"+zhu.getWeight()+",攻击为"+zhu.getAttack()+"点血,准确度为"+zhu.accuracy+",我好怕怕呀"); } }
---恢复内容结束---