java: Retirement
/**
* 版权所有 2022 涂聚文有限公司
* 许可信息查看:
* 描述:
* Core Java, Volume I: Fundamentals, Twelfth Edition by Cay S.Horstamnn
* Core Java, Volume II: Advanced Features, Twelfth Edition by Cay S.Horstamnn
* Core Java
* 历史版本: JDK 17.01
* 2022-09-12 创建者 geovindu
* 2022-09-12 添加 Lambda
* 2022-09-12 修改:date
* 接口类
* 2022-09-12 修改者:Geovin Du
* 生成API帮助文档的指令:
*javadoc - -encoding Utf-8 -d apidoc LotteryDrawing.java
* Interface
* Record
* Annotation
* Enum
* */
package CoreJava.twelfth;
import java.util.*;
/**
*
* */
public class LotteryDrawing {
/**
*
* */
public void Draw()
{
Scanner in = new Scanner(System.in);
System.out.print("你需要画多少数字? ");
int k = in.nextInt();
System.out.print("你能画的最高数字是多少? ");
int n = in.nextInt();
// fill an array with numbers 1 2 3 . . . n
int[] numbers = new int[n];
for (int i = 0; i < numbers.length; i++)
numbers[i] = i + 1;
// draw k numbers and put them into a second array
int[] result = new int[k];
for (int i = 0; i < result.length; i++)
{
// make a random index between 0 and n - 1
int r = (int) (Math.random() * n);
// pick the element at the random location
result[i] = numbers[r];
// move the last element into the random location
numbers[r] = numbers[n - 1];
n--;
}
// print the sorted array
Arrays.sort(result);
System.out.println("下注以下组合。它会让你富有!");
for (int r : result)
System.out.println(r);
}
}
/**
* 版权所有 2022 涂聚文有限公司
* 许可信息查看:
* 描述:
* Core Java, Volume I: Fundamentals, Twelfth Edition by Cay S.Horstamnn
* Core Java, Volume II: Advanced Features, Twelfth Edition by Cay S.Horstamnn
* Core Java
* 历史版本: JDK 17.01
* 2022-09-12 创建者 geovindu
* 2022-09-12 添加 Lambda
* 2022-09-12 修改:date
* 接口类
* 2022-09-12 修改者:Geovin Du
* 生成API帮助文档的指令:
*javadoc - -encoding Utf-8 -d apidoc Retirement.java
* Interface
* Record
* Annotation
* Enum
* */
package CoreJava.twelfth;
import java.util.*;
/**
*
*
* */
public class Retirement {
/**
*
*
* */
public void Calculate()
{
Scanner in = new Scanner(System.in);
System.out.print("你每年要捐多少钱? ");
double payment = in.nextDouble();
System.out.print("存款利率 %: ");
double interestRate = in.nextDouble();
double balance = 0;
int year = 0;
String input;
// update account balance while user isn't ready to retire
do
{
// add this year's payment and interest
balance += payment;
double interest = balance * interestRate / 100;
balance += interest;
year++;
// print current balance
System.out.printf("在 %d 年, 你的余额是 %,.2f%n", year, balance);
// ask if ready to retire and get input
System.out.print("准备退休了? (Y/N) ");
input = in.next();
}
while (input.equals("N"));
}
}
调用:
//
LotteryDrawing lotteryDrawing=new LotteryDrawing();
lotteryDrawing.Draw();
///
Retirement retirement=new Retirement();
retirement.Calculate();
输出:
你需要画多少数字? 20 你能画的最高数字是多少? 20 下注以下组合。它会让你富有! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 你每年要捐多少钱? 2000 存款利率 %: 20 在 1 年, 你的余额是 2,400.00 准备退休了? (Y/N) y
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
浙公网安备 33010602011771号