这个课程的参考视频和图片来自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. golang - interface的作用

    多态.struct 可以赋值给 interface.interface 可以转换成子接口,或者 struct. 请看go中的一段的源代码: listener, _ := net.Listen(&quo ...

  2. Linux 查看进程运行的完整路径方法

    通过ps及top命令查看进程信息时,只能查到相对路径,查不到的进程的详细信息,如绝对路径等. 这时,我们需要通过以下的方法来查看进程的详细信息: Linux在启动一个进程时,系统会在/proc下创建一 ...

  3. Entity Framework DbSet<T>之Include方法与IQueryable<T>扩展方法Include的使用

    Entity Framework使用Code First方式时,实体之间已经配置好关系,根据实际情况某些情况下需要同时获取导航属性,比如获取商品的同时需要获取分类属性(导航属性),或者基于优化方面考虑 ...

  4. [No0000177]详解/etc/profile、/etc/bash.bahsrc、~/.profile、~/.bashrc的用途

    之前安装Linux的一些软件时,总要修改Linux的配置文件.当时也是一知半解.而且,网上有些安装教程,会说,修改配置文件后要重启Linux.但事实上是不需要重启的. Linux安装时可能要修改的配置 ...

  5. [No0000169]Potplayer倍速播放快捷键修改速率步长

    右键-播放-播放设置-速度调整单位改成0.5,即可一次加速到1.5

  6. [No0000161]IDEA初步接触

    安装 参考https://blog.csdn.net/qq_35246620/article/details/61191375 安装过程全程默认(路径和快捷方式自定义,不需要下载jre): 启动后全程 ...

  7. [No000011A]Office Excel设置显示日期与星期

    设置excel日期格式,自定义,yyyy-mm-dd 上午/下午 hh:mm:ss AM/PM dddd aaaa

  8. 自动化运维工具-mussh工具安装配置及简单使用讲解

    1.先决条件: 安装pssh工具的主机针对远程主机需要配置免秘钥认证: ssh-keygen -t rsa ssh-copy-id [remotehost] 2.下载mussh工具安装介质: http ...

  9. ArcEngine二次开发,TOCControl控件上使用contextMenuStrip

    右键菜单,在二次开发中很实用,以前没用过,最近通过一本书了解到,一直想找这么一个控件来用. 一般的控件,将contextMenuStrip控件拖到所依托的控件上,然后输入自己想要的几个功能.  在所依 ...

  10. HBase实战 | 知乎实时数仓架构演进

    https://mp.weixin.qq.com/s/hx-q13QteNvtXRpNsE5Y0A 作者 | 知乎数据工程团队编辑 | VincentAI 前线导读:“数据智能” (Data Inte ...