开始Java编程

开始Java编程,java,Java,好的,我正在为我的Java编程类做一个作业。作业如下(代码将在末尾): 假设一所大学今年的学费是10000美元,每年增加5%。编写一个程序,计算十年内的学费和十年内四年学费的总成本。金额应精确到小数点后两位。我不知道哪里出了问题,怎么解决。当我尝试运行它时,什么都没有发生,什么都没有显示(这是我的密码: public class FutureTuitionPrice { public static void main(String[] args) { // TODO A

好的,我正在为我的Java编程类做一个作业。作业如下(代码将在末尾): 假设一所大学今年的学费是10000美元,每年增加5%。编写一个程序,计算十年内的学费和十年内四年学费的总成本。金额应精确到小数点后两位。我不知道哪里出了问题,怎么解决。当我尝试运行它时,什么都没有发生,什么都没有显示(这是我的密码:

public class FutureTuitionPrice {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double tuition = 10000;
        double count = 0;
        double increase = 1.05;
        double increasedTuition = 0;

        do {
            increasedTuition = tuition * increase;

        } while(count <=10);
        count++;

        if (count ==10);
        System.out.print("Tuition in ten years is $ \n" + increasedTuition);        
        do {
            increasedTuition = tuition * increase;
        }while (count==10 && count < 14);
        count ++;
         if (count ==14);
         System.out.print("The four-year tuitiuon in ten years is $ " + increasedTuition);
        }

    }
公共类未来教育价格{
公共静态void main(字符串[]args){
//TODO自动生成的方法存根
双倍学费=10000;
重复计数=0;
双倍增长=1.05;
双增量单位=0;
做{
增加学费=学费*增加;
}而(计数<代码>双重计数=0;
做{
增加学费=学费*增加;

}而(count您的程序处于无止境的循环中

     do {

          increasedTuition = tuition * increase;
          ++count;//incrementing count each cycle

     } while(count <=10);
do{
增加学费=学费*增加;
++计数;//每个周期递增计数
}而(计数试试这个

    double tuition = 10000;
    double count = 1;
    double percentageIncrease = 1.05;
    double increasedTuition;
    double sumOfTuitionAfterFourYears = 0;
    double increasedTuitionTwo;

    do {
        //This is the correct incremental formular
        tuition = tuition * percentageIncrease;
        //increasedTuition = increasedTuition * percentageIncrease;
        count++;

        //Formatting the number of digits after the decimal point
        increasedTuition = (int)(tuition * 100) / 100.0;

        //This if statement must be inside the loop body
        if (count > 10) //Note, do not put a semi-colon here
        System.out.println("Tuition in ten years is " + increasedTuition);

    } while (count <= 10); //End of first loop

    do {
        increasedTuition = increasedTuition * percentageIncrease;

            //Formatting the number of digits after the decimal point
            increasedTuitionTwo = (int)(increasedTuition * 100) / 100.0;

            //Adding the result above on each iteration pass
            sumOfTuitionAfterFourYears += increasedTuitionTwo;

            if (count == 14) 
            System.out.println("The sum of four years tuition starting from 10 years is " + sumOfTuitionAfterFourYears);

        //Increments the count from 10 since our base tuition is the last tuition in the last loop
        //You can also write your continuation-condition like this: (count >= 10 && count <= 14). 
        //You will get the same result without changing the base tuition
        count++; 

    } while (count <= 14); //End of second loop
双倍学费=10000;
重复计数=1;
双百分比增长=1.05;
双倍递增单位;
四年后的两倍租金=0;
双倍递增倍数2;
做{
//这是正确的增量公式
学费=学费*增加百分比;
//IncreasedUITION=IncreasedUITION*百分比增加;
计数++;
//格式化小数点后的位数
增量单位=(整数)(学费*100)/100.0;
//此if语句必须位于循环体内部
如果(计数>10)//注意,不要在这里放分号
System.out.println(“十年学费是”+增加的学费);

}当(count=10&&count在纸上执行do/while循环,并在每次迭代时记下count变量的值。你的循环是永无止境的。调试代码。将来也会有所帮助。对于程序员来说,最重要的技能是。如果你坐下来使用eclipse调试器并学习如何使用它,你会发现自己有一个更好的pr现在和将来很多事情都会变得更容易。调试器在哪里?它将捕获代码中没有立即显示的问题?谢谢!我现在就去试试!那么,我在下一个循环中做得对吗(从计数10到14计算4年的学费?)那么你为什么不把它写对而不是建议?@mikeTheLiar好的,老板:)好的,我确实改变了这一点,程序现在运行了,但它只进行了一次迭代,所以显示的两个数字的结果都是一样的。@塔米,你应该试着回答关于这个问题的评论,而不是让别人帮你修改代码并指出每一个小错误。否则,你会发现自己处于相同的情况n在每一个即将到来的家庭作业中。你应该检查语法。不要将
do while
循环与
while
循环混合。是的,谢谢,我不知道我的心思在哪里,修复了代码片段,问题仍然是他从未增加过计数。
    double tuition = 10000;
    double count = 1;
    double percentageIncrease = 1.05;
    double increasedTuition;
    double sumOfTuitionAfterFourYears = 0;
    double increasedTuitionTwo;

    do {
        //This is the correct incremental formular
        tuition = tuition * percentageIncrease;
        //increasedTuition = increasedTuition * percentageIncrease;
        count++;

        //Formatting the number of digits after the decimal point
        increasedTuition = (int)(tuition * 100) / 100.0;

        //This if statement must be inside the loop body
        if (count > 10) //Note, do not put a semi-colon here
        System.out.println("Tuition in ten years is " + increasedTuition);

    } while (count <= 10); //End of first loop

    do {
        increasedTuition = increasedTuition * percentageIncrease;

            //Formatting the number of digits after the decimal point
            increasedTuitionTwo = (int)(increasedTuition * 100) / 100.0;

            //Adding the result above on each iteration pass
            sumOfTuitionAfterFourYears += increasedTuitionTwo;

            if (count == 14) 
            System.out.println("The sum of four years tuition starting from 10 years is " + sumOfTuitionAfterFourYears);

        //Increments the count from 10 since our base tuition is the last tuition in the last loop
        //You can also write your continuation-condition like this: (count >= 10 && count <= 14). 
        //You will get the same result without changing the base tuition
        count++; 

    } while (count <= 14); //End of second loop