文章目录
- 前言
- 准备造妹子
- 属性(暂定)
- 行为(暂定)
- 行动
- 造属性
- 造set,get方法
- 造方法
- 实例化对象,并设置属性
- 具体应用
前言
应他们要求,就先把妹子造出来吧,就当多个小练习
准备造妹子
要先确定,妹子都有哪些属性,方法,还有,最重要的是,我们要自定义我们的妹子
属性(暂定)
有想出来的可以私信我说出来,我加上去,集思广益嘛,顺便实现你内心的想法(笑)
可由我们自己定义的:外貌,气质,性格,穿衣,发型,年龄,名字,身高,体重
不能由我们定义的:两个胳膊,两条腿,一个头,两个眼睛,一个躯干,红细胞,白细胞(手动狗头)等。。
行为(暂定)
有想出来的可以私信我说出来,我加上去,集思广益嘛
不可定义!不可定义!不可定义!
重要的事情说三遍!这个没法定义,这个定义指的是通过实例化对象后无法定义,但是可以通过代码修改。
说话,跳舞,打游戏,撒娇,卖萌
行动
造属性
先造属性,根据我们上一篇的标准,要求属性都是private修饰
class Girl{private int age; //这个是年龄属性private String name; //这个是姓名属性private String look; //这个是外貌属性private String ethos; //这个是气质属性private String character; //这个是性格属性private String dress; //这个是穿衣属性private double height; //这个是身高属性private double weight; //这个是体重属性private String hairdo; //这个是发型属性}
造set,get方法
根据上篇学的,我们要对属性值进行set和get属性,用于设置和获取属性值
public void setName(String name){/*设置名字*/this.name = name;}String getName(){/*获取名字*/return name;}public void setAge(int age){/*设置年龄*/this.age = age;}public int getAge(){/*获取年龄*/return age;}public void setLook(String look){/*设置外貌*/this.look = look;}public String getLook(String look){/*获取外貌*/return look;}public void setEthos(String ethos){/*设置气质*/this.ethos = ethos;}public String getEthos(String ethos){/*获取气质*/return ethos;}public void setCharacter(String character){/*设置性格*/this.character = character;}public String getCharacter(String character){/*获取性格*/return character;}public void setDress(String dress){/*设置穿衣风格*/this.dress = dress;}public String getDress(String dress){/*获取穿衣风格*/return dress;}public void setHeight(double height){/*设置身高*/this.height = height;}public double getHeight(double height){/*获取身高*/return height;}public void setWeight(double weight){/*设置体重*/this.weight = weight;}public double getWeight(double weight){/*获取体重*/return weight;}public void setHairdo(String hairdo){/*设置发型*/this.hairdo = hairdo;}public String getHairdo(String hairdo){/*获取发型*/return hairdo;}
造方法
把说话,跳舞,打游戏,撒娇,卖萌简单的写出来
public void playGame(){/*打游戏*/System.out.printf("%s打游戏很厉害", name);}public void coqutry(){/*撒娇*/System.out.println("哥哥不要这样啦,人家害怕啦~~~");}public void speak(){/*说话*/System.out.println("今天的你,仍旧迷人,使人心中好似小鹿乱撞");}public void dance() {/*跳舞*/System.out.println("曼妙的舞姿~~具体什么舞蹈,自己想");}public void cute(){/*卖萌*/System.out.println("未来是多变的,所以我不期待,我只做好现在,充实现在。");}
实例化对象,并设置属性
实例化对象并设置属性
Scanner sc = new Scanner(System.in);String name, look, ethos, character, dress, hairdo;double height, weight;int age;Girl girl = new Girl();girl.setName("西施");name = girl.getName();girl.setLook("美若天仙");look = girl.getLook();girl.setEthos("高冷");ethos = girl.getEthos();girl.setCharacter("高傲");character = girl.getCharacter();girl.setDress("休闲");dress = girl.getDress();girl.setHeight(1.68);height = girl.getHeight();girl.setWeight(83.2);weight = girl.getWeight();girl.setHairdo("黑长直");hairdo = girl.getHairdo();
具体应用
import java.util.Scanner;public class Ec4_19 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String name, look, ethos, character, dress, hairdo;double height, weight;int age;Girl girl = new Girl();girl.setName("西施");name = girl.getName();girl.setLook("美若天仙");look = girl.getLook();girl.setEthos("高冷");ethos = girl.getEthos();girl.setCharacter("高傲");character = girl.getCharacter();girl.setDress("休闲");dress = girl.getDress();girl.setHeight(1.68);height = girl.getHeight();girl.setWeight(83.2);weight = girl.getWeight();girl.setHairdo("黑长直");hairdo = girl.getHairdo();System.out.println("输入指令,0退出");System.out.printf("%s 是一个%s 的,喜欢穿 %s 的 %s 的女孩", name, look, dress, character);System.out.println("");System.out.printf("身高%f ,体重%f ,有点 %s ", height, weight, ethos);//定义一个死循环,循环获取输入的数据(???这不是聊天机器人¿),哈哈差不多label:while (true){String a = sc.next();switch (a) {case "打游戏":girl.playGame();break;case "撒娇":girl.coqutry();break;case "说好听的":girl.speak();break;case "卖萌":girl.cute();break;case "跳舞":girl.dance();break;case "0":System.out.println("再见了,宝贝");break label;}}}}class Girl{private int age; //这个是年龄属性private String name; //这个是姓名属性private String look; //这个是外貌属性private String ethos; //这个是气质属性private String character; //这个是性格属性private String dress; //这个是穿衣属性private double height; //这个是身高属性private double weight; //这个是体重属性private String hairdo; //这个是发型属性public void setName(String name){/*设置名字参数:name 名字*/this.name = name;}String getName(){/*获取名字*/return name;}public void setAge(int age){/*设置年龄*/this.age = age;}public int getAge(){/*获取年龄*/return age;}public void setLook(String look){/*设置外貌*/this.look = look;}public String getLook(){/*获取外貌*/return look;}public void setEthos(String ethos){/*设置气质*/this.ethos = ethos;}public String getEthos(){/*获取气质*/return ethos;}public void setCharacter(String character){/*设置性格*/this.character = character;}public String getCharacter(){/*获取性格*/return character;}public void setDress(String dress){/*设置穿衣风格*/this.dress = dress;}public String getDress(){/*获取穿衣风格*/return dress;}public void setHeight(double height){/*设置身高*/this.height = height;}public double getHeight(){/*获取身高*/return height;}public void setWeight(double weight){/*设置体重*/this.weight = weight;}public double getWeight(){/*获取体重*/return weight;}public void setHairdo(String hairdo){/*设置发型*/this.hairdo = hairdo;}public String getHairdo(){/*获取发型*/return hairdo;}public void playGame(){/*打游戏*/System.out.printf("%s打游戏很厉害", name);}public void coqutry(){/*撒娇*/System.out.println("哥哥不要这样啦,人家害怕啦~~~");}public void speak(){/*说话*/System.out.println("今天的你,仍旧迷人,使人心中好似小鹿乱撞");}public void dance() {/*跳舞*/System.out.println("曼妙的舞姿~~具体什么舞蹈,自己想");}public void cute(){/*卖萌*/System.out.println("未来是多变的,所以我不期待,我只做好现在,充实现在。");}}/*输入指令,0退出西施 是一个美若天仙 的,喜欢穿 休闲 的 高傲 的19女孩身高1.68 ,体重83.20 ,有点 高冷,是 黑长直现在,她是你的女朋友,请好好善待她!打游戏西施打游戏很厉害撒娇哥哥不要这样啦,人家害怕啦~~~说好听的今天的你,仍旧迷人,使人心中好似小鹿乱撞卖萌未来是多变的,所以我不期待,我只做好现在,充实现在。跳舞曼妙的舞姿~~具体什么舞蹈,自己想0再见了宝贝*/
补充
有什么想法可以私信或者评论,我都会说的哦
结语
呐,你们要的妹子,有什么需要补充的尽管告诉我!
xdm冲冲冲,我先溜了