这个课程的参考视频和图片来自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. git提交出现这个界面怎么退出

    默认git使用nano进行编辑提交的页面,退出方法为: Ctrl + X然后输入y再然后回车,就可以退出了 如果你想把默认编辑器换成别的: 在GIT配置中设置 core.editor: git con ...

  2. GDB常用调试命令以及多进程多线程调试

    http://blog.csdn.net/freeelinux/article/details/53700266 一:普通命令   1.list命令 list  linenum      显示程序第l ...

  3. db2 删除过期的日志和备份文件(转)

    DB2 删除过期备份和日志 $ db2 list history archive log all forpayment2    ------列出归档日志 $ db2 list history back ...

  4. css学习_文本有关的样式属性、sublime快捷生成标签

    1.css中color定义文本的颜色 写法:(最常用的是16进制的) 2.行间距    line-height 3.水平对齐方式   text-align left right  center 4.首 ...

  5. [No0000E7]C# 封装 与访问修饰符

    C# 支持的访问修饰符: Public Private Protected Internal Protected internal Public 访问修饰符 Public 访问修饰符允许一个类将其成员 ...

  6. spring boot拦截器WebMvcConfigurerAdapter,以及高版本的替换方案

    Springboot中静态资源和拦截器处理(踩了坑)   背景: 在项目中我使用了自定义的Filter 这时候过滤了很多路径,当然对静态资源我是直接放过去的,但是,还是出现了静态资源没办法访问到spr ...

  7. Flannel配置详解

    1.简介 Flannel是一种基于overlay网络的跨主机容器网络解决方案,也就是将TCP数据包封装在另一种网络包里面进行路由转发和通信, Flannel是CoreOS开发,专门用于docker多机 ...

  8. C语言保证,0永远不是有效的数据地址,因此,返回址0可用来表示发生的异常事件

    C语言保证,0永远不是有效的数据地址,因此,返回址0可用来表示发生的异常事件

  9. 阿里创新自动化测试工具平台--Doom

    摘要: 阿里内部诞生一了个依赖真实流量用于自动回归的自动化测试平台,通过创新的自动mock机制不仅支持读接口的回归验证,同时支持了写接口验证,在内部产生了极大价值,有价值的东西就应该分享,目前该工具已 ...

  10. Java+Selenium 常见问题QA

    一:日期控件二:上传控件三:页面隐藏元素四:弹出窗口的处理五:富文本框编辑器六:元素高亮 一:日期控件selenium不能直接对日期控件操作,可以通过js对日期控件做赋值操作 WebElement i ...