这个课程的参考视频和图片来自youtube

主要学到的知识点有:

1. Nested If-else statement (if-else ladder)

/**
* 90 and above ==> A
* 80 up to 90 ==> B
* 70 up to 80 ==> C
* 60 up to 70 ==> D
* below 60 ==> F
*/ if (grade >= 90)
{
gradeLetter = "A";
}
else if (grade >= 80)
{
gradeLetter = "B";
}
else if (grade >= 70)
{
gradeLetter = "C";
}
else if (grade >= 60)
{
gradeLetter = "D";
}
else
{
gradeLetter = "F";
}

2. Switch

switch (month)
{
case 1:
result = "January";
break;
case 2:
result = "February";
break;
case 3:
result = "March";
break;
default:
result = "Unknown;
break;
}

3. Enumerations

  • An enumeration custom data type  that enables a variable to be a set of predefined constants of specific value
  • Enums are declared like a class

Cannot assign to enum class.      Grade g = 78.0;    is not allowed.

Cannot create an object from  enum class.  Grade g = new Grade(88);      is not allowed.

This is a enum class of grades.

/**
*
* Java enum representation for grades, based on the following scale:
* 90 and above ==> A
* 80 up to 90 ==> B
* 70 up to 80 ==> C
* 60 up to 70 ==> D
* below 60 ==> F
*/
public enum Grade { A (90.0), B(80.0), C(70.0), D(60.0), F(0.0); // here will call the constructor private final double minimumScore; /**
* Write a constructor for grade with minimum score for that grade
* @param minimumScore lowest acceptable score for that grade
*/
Grade (double minimumScore) {
this.minimumScore = minimumScore;
} /**
* Return the minimum score for the letter grade
* @return lowest score fort achieving that grade
*/
public double Min() {
return this.minimumScore;
} }

If we have the enum class above, then we can rewrite the example in No.1 at beginning.

if (grade >= Grade.A.Min())
{
gradeLetter = Grade.A;
}
else if (grade >= Grade.B.Min())
{
gradeLetter = Grade.B;
}
else if (grade >= Grade.C.Min())
{
gradeLetter = Grade.C;
}
else if (grade >= Grade.D.Min())
{
gradeLetter = Grade.D;
}
else
{
gradeLetter = Grade.F;
}

[Java in NetBeans] Lesson 09. Switch / If-Else Ladder的更多相关文章

  1. [Java in NetBeans] Lesson 07. JavaDoc and Unit Tests

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. organize code into packages Create a package if want to make th ...

  2. [Java in NetBeans] Lesson 00. Getting Set-up for Learning Java

    这个课程的参考视频在youtube. 主要学到的知识点有: set up needs Java SE JDK, NetBeans IDE class name should be the same l ...

  3. [Java in NetBeans] Lesson 17. File Input/Output.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...

  4. [Java in NetBeans] Lesson 16. Exceptions.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...

  5. [Java in NetBeans] Lesson 15. Sorting and Searching.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Build in functions in java.util.Collections Need to implement a co ...

  6. [Java in NetBeans] Lesson 06. Custom classes

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Constructors: A special method called when an object of the class ...

  7. [Java in NetBeans] Lesson 05. Method/function

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Define a method:(motivation: write one time, but use it many times ...

  8. [Java in NetBeans] Lesson 04. Class / Objects

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Class: Blueprint for an object. (e.g. dog is a class) Object: cust ...

  9. [Java in NetBeans] Lesson 01. Java Programming Basics

    这个课程的参考视频在youtube. 主要学到的知识点有: Create new project, choose Java Application. one .jar file/ package(.j ...

随机推荐

  1. springMVC 复选框带有选择项记忆功能的处理

    前言:由于jsp管理页面经常会遇到复选框提交到JAVA后台,后台处理逻辑完成后又返回到jsp页面,此时需要记住jsp页面提交时复选框的选择状态,故编写此功能! 一.复选框的初始化 1.1.jsp页面 ...

  2. Tarjan 强连通分量 及 双联通分量(求割点,割边)

    Tarjan 强连通分量 及 双联通分量(求割点,割边) 众所周知,Tarjan的三大算法分别为 (1)         有向图的强联通分量 (2)         无向图的双联通分量(求割点,桥) ...

  3. Ubuntu上pip安装uwsgi失败的原因之一(未联网)

    ubuntu@ubuntu:~$ sudo pip install uwsgi 报错:The directory '/home/ubuntu/.cache/pip/http' or its paren ...

  4. db2 reorg到底需要多少表空间(转)

    脱机reorg需要一定的空间,这个空间与目标所在的数据表空间.索引表空间.以及临时表空间均有关,各空间需求的大小与表和索引所占用的数据页和索引页相关. (1)对表执行reorg操作如:db2 reor ...

  5. 湘潭大学校赛H-统计颜色 线段树

    链接:https://www.nowcoder.com/acm/contest/105/H来源:牛客网 n个桶按顺序排列,我们用1~n给桶标号.有两种操作: 1 l r c 区间[l,r]中的每个桶中 ...

  6. AFNetworking的缓存使用

    + (NSURLCache *)defaultURLCache { // It's been discovered that a crash will occur on certain version ...

  7. 可执行代码(Executable Code)目标代码(object code)

    小结: 1.可执行代码(Executable Code)是指将目标代码(object code)连接后形成的代码,简单来说是机器能够直接执行的代码. https://baike.baidu.com/i ...

  8. php之运算符

    运算符优先级相同,运算符的结合方向决定了该如何运算, 一.运算符优先级 组合方向 运算符 附加信息 无 clone new clone和new 左 [ array 右 ** 算术运算符 右 ++ -- ...

  9. 使用uibesizerpath + Cashaplayer画椭圆

    使用uibesizerpath Cashaplayer画椭圆: + (void)drawOvalAnimSourceView:(UIView *)sourceView { //view是曲线的背景vi ...

  10. 【Linux】Linux 常用命令汇总

    查看软件xxx安装内容:dpkg -L xxx 查找软件库中的软件:apt-cache search 正则表达式 查找软件库中的软件:aptitude search 软件包 查找文件属于哪个包:dpk ...