testflyweight.java
来自「程序设计模式java入门源码大全」· Java 代码 · 共 30 行
JAVA
30 行
public class TestFlyweight
{
public static void main(String args[])
{
String names[] = {"Ralph", "Alice", "Sam"};
int ids[] = {1001, 1002, 1003};
int scores[] = {45, 55, 65};
double total = 0;
for (int loopIndex = 0; loopIndex < scores.length; loopIndex++){
total += scores[loopIndex];
}
double averageScore = total / scores.length;
Student student = new Student(averageScore);
for (int loopIndex = 0; loopIndex < scores.length; loopIndex++){
student.setName(names[loopIndex]);
student.setId(ids[loopIndex]);
student.setScore(scores[loopIndex]);
System.out.println("Name: " + student.getName());
System.out.println("Standing: " +
Math.round(student.getStanding()));
System.out.println("");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?