使用贴现率8%和12%分别计算每个项目的净现值(NPV),提交源代码和实验结果截图,编程语言不限 (JAVA实现)
作者:互联网
使用贴现率8%和12%分别计算每个项目的净现值(NPV) JAVA实现
实现代码(JAVA):
package com.zuoye.Three;
import java.math.BigDecimal;
public class TieXianLu {
public static void main(String[] args) throws Exception {
//数据集合
int[] math1 = new int[]{-100000, 10000, 10000, 10000, 20000, 100000};
int[] math2 = new int[]{-1000000, 200000, 200000, 200000, 200000,300000};
int[] math3 = new int[]{-100000, 30000, 30000, 30000, 30000, 30000};
int[] math4 = new int[]{-120000, 30000, 30000, 30000, 30000, 75000};
//贴现率
double [] txl = new double[] {0.08,0.12};
double[][] b=new double[2][6];
//求贴现因子
for (int i=0;i<txl.length;i++){
for (int j=0;j<math1.length;j++) {
b[i][j] = 1 / Math.pow((txl[i] + 1), j);
BigDecimal t = new BigDecimal(b[i][j]);
//保留四位小数
b[i][j] = t.setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue();
}
}
for(int j=0;j<2;j++){
for(int i=0;i<6;i++){
if(j==0){
System.out.println("第"+i+"年"+" 贴现率8%的贴现因子"+b[j][i]);
}else{
System.out.println("第"+i+"年"+" 贴现率12%的贴现因子"+b[j][i]);
}
}
}
int[] project1result1=txz(math1,b);System.out.println("项目1贴现率8%的净现值:"+project1result1[0]+" 贴现率12%的净现值:"+project1result1[1]);
int[] project1result2=txz(math2,b);System.out.println("项目2贴现率8%的净现值:"+project1result2[0]+" 贴现率12%的净现值:"+project1result2[1]);
int[] project1result3=txz(math3,b);System.out.println("项目3贴现率8%的净现值:"+project1result3[0]+" 贴现率12%的净现值:"+project1result3[1]);
int[] project1result4=txz(math4,b);System.out.println("项目4贴现率8%的净现值:"+project1result4[0]+" 贴现率12%的净现值:"+project1result4[1]);
}
static int[] txz(int[] a, double[][] b){
int[] p=new int[2];
for(int j=0;j<2;j++){
int temp=0;
for(int i=0;i<6;i++){
temp=(int)(temp+a[i]*b[j][i]);
// System.out.println(temp+"-----");
}
p[j]=temp;
}
return p;
}
}
运行结果示例:
标签:贴现率,NPV,JAVA,30000,int,现值,8%,new,源代码 来源: https://www.cnblogs.com/cxy0210/p/14533711.html