一、昨天的实践:术语随机生成器
//术语生成器
public class PhraseOMatic
{
public static void main(String[] args)
{
//创建三个词库
String[] wordListOne = {"24/7", "multi-Tier","30,000 foot","B-to-B","win-win",
"front-end","web-based","pervasive","smart","six-sigma","critical-path","dynamic"};
String[] wordListTwo = {"empowered","sticky","value-added","oriented","centric","distributed","clustered",
"branded","outside-the-box","positioned","networked","focussed","leveraged","aligned",
"targeted","shared","cooperative","accelerated"};
String[] wordListThree = {"process","tipping-point","solution","architecture","core competency","strategy",
"mindshare","portal","space","vision","paradigm","mission"};
//计算词库长度
int oneLength = wordListOne.length;
int twoLength = wordListTwo.length;
int threeLength = wordListThree.length;
//生成随机数
int rand1 = (int)(Math.random() * oneLength); //Math.random():0~1
int rand2 = (int)(Math.random() * twoLength);
int rand3 = (int)(Math.random() * threeLength);
//生成专家术语
String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " +wordListThree[rand3];
System.out.println("What we want is a " + phrase);
}
}
运行结果:
二、类
概念
- 类(class):像一张蓝图,它定义了要使用什么样的数据以及怎么样使用这些数据。
- 方法(method):定义了一些操作,如何使用数据。
- 继承(inheritance):子类在“继承”后可以使用父类的方法。
- 覆盖(override):子类可以重新定义继承自父类的方法,这个过程叫做覆盖。
使用类的好处
程序变化的时候,只需要修改相关类的相关方法。
类和对象
对象是靠类的模型造出来的。对象包括实例变量(instance variable),它们代表对象的状态;以及方法(methods),它们是对象可以执行的动作。
比如,每个图形都有形状和颜色等特征,但是每个实例不尽相同,有各自的特征。
标签:Java,String,int,random,Day2,length,概述,wordListTwo,Math From: https://blog.csdn.net/weixin_42818989/article/details/137432112目前学习的参考书籍是《Head First Java》