创建决策陈述?

时间:2017-10-04 03:02:57

标签: java

该计划应该输出投资的增长收益率。投资金额,持续时间和基本费率将作为用户对程序的输入提供。根据下表每年应用增长率:

Table

到目前为止我所拥有的只是用户输入代码,

import javax.swing.JOptionPane;

public class InvestGrowth {
    public static void main(String[] args) {
        double investment, duration, baserate, growth;

        investment = Double.parseDouble(JOptionPane.showInputDialog("Enter Investment Amount:"));

        duration = Double.parseDouble(JOptionPane.showInputDialog("Enter Duration in years: "));

        baserate = Double.parseDouble(JOptionPane.showInputDialog("Enter BaseRate:"));

        if (investment <- 50000){

        }
    }
}

我只是不确定如何为表创建决策语句......任何帮助?

1 个答案:

答案 0 :(得分:1)

由于您正在学习,我认为在尝试创建完整的图形应用程序之前,您应首先尝试使核心逻辑在控制台中运行。

尝试使用以下代码使其工作:

import java.util.Scanner;

class InvestGrowth {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    System.out.print("Enter Investment ($):");
    double investment = scanner.nextDouble();

    System.out.print("Enter Duration (Years):");
    double duration = scanner.nextDouble();

    System.out.print("Enter Base:" );
    double base  = scanner.nextDouble();

    double growthRate = 0.0;
    double growthYield = 0.0;

    // TODO: Complete actual logic of calculating growthYield
    if (investment <= 50000) {
      if(duration <= 1) { // Investment <= $50000 && Duration <= 1 year

      } else { // Investment <= $50000 && Duration > 1 year

      }
    } else { 
      if (duration <= 1) { // Investment > $50000 && Duration <= 1 year

      } else { // Investment > $50000 && Duration > 1 year

      }
    }

    System.out.println("Your growth yield is: " + growthYield);
  }
}

我遗漏了核心逻辑,因为我认为这是你的作业(所以请问你的老师/讲师/教授/ TA等等。如果你被困住了)但你被困在&#34;决定的部分表格#34; 的陈述是:)