Compare commits
8 Commits
d6ca70bcb8
...
main
Author | SHA1 | Date | |
---|---|---|---|
bd871d68e0 | |||
f9788e9a7d | |||
2eb89779b6 | |||
1e3aa2f3b3 | |||
9accb457d2 | |||
191212ec5d | |||
cf91111056 | |||
38d6fbc00c |
51
Employee.java
Normal file
51
Employee.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.powernode.spring6;
|
||||
|
||||
public class Employee {
|
||||
private int id;
|
||||
private String name;
|
||||
private int level;
|
||||
private Boolean isBoss;
|
||||
|
||||
private Employee(int id, String name, int level, Boolean isBoss) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.level = level;
|
||||
this.isBoss = isBoss;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public Boolean getBoss() {
|
||||
return isBoss;
|
||||
}
|
||||
|
||||
public void setBoss(Boolean boss) {
|
||||
if( boss && level > 25) {
|
||||
isBoss = boss;
|
||||
} else if (!boss && level < 25) {
|
||||
isBoss = boss;
|
||||
} else {
|
||||
System.out.println("boss can only be person who level is higher than 25");
|
||||
}
|
||||
}
|
||||
|
||||
public static Employee staticTest(int id, String name, int level) {
|
||||
return new Employee(id, name, level, level > 25);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Employee employee = Employee.staticTest(1,"Dan",27);
|
||||
System.out.println(employee.isBoss);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello tian!!!");
|
||||
System.out.println("笑笑笑笑笑笑笑笑笑");
|
||||
System.out.println("Hello, World");
|
||||
}
|
||||
}
|
57
LeapYear.java
Normal file
57
LeapYear.java
Normal file
@ -0,0 +1,57 @@
|
||||
/** Class that determines whether or not a year is a leap year.
|
||||
* @author YOUR NAME HERE
|
||||
*/
|
||||
public class LeapYear {
|
||||
|
||||
/** Calls isLeapYear to print correct statement.
|
||||
* @param year to be analyzed
|
||||
*/
|
||||
private static void checkLeapYear(int year) {
|
||||
if (isLeapYear(year)) {
|
||||
System.out.printf("%d is a leap year.\n", year);
|
||||
} else {
|
||||
System.out.printf("%d is not a leap year.\n", year);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method check if year is leap
|
||||
*/
|
||||
public static boolean isLeapYear(int year) {
|
||||
if (year % 400 == 0) {
|
||||
return true;
|
||||
} else if (year % 100 != 0 && year % 4 == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void countDaysInYear(int year) {
|
||||
if (isLeapYear(year)) {
|
||||
System.out.println("366 days");
|
||||
} else {
|
||||
System.out.println("365 days");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Must be provided an integer as a command line argument ARGS. */
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
System.out.println("Please enter command line arguments.");
|
||||
System.out.println("e.g. java Year 2000");
|
||||
System.out.println("aaa 2000 cccc");
|
||||
}
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
try {
|
||||
int year = Integer.parseInt(args[i]);
|
||||
checkLeapYear(year);
|
||||
countDaysInYear(year);
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.printf("%s is not a valid number.\n", args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user