【问题标题】:I need help correcting my code for blueJ我需要帮助更正我的 blueJ 代码
【发布时间】:2018-02-07 15:41:08
【问题描述】:
 import java.util.Scanner;
    /**
     * Write a description of class code here.
     *
     * @author (your name)
     * @version (a version number or a date)
     */
    public class code
    {
        public static void main(String args [])
        {
            {
                docreditcard(); // calls functions
            }
            {
                public static void docreditcard()
            }
            {
                float preb = 0;
                float add = 0;
                float inter = 0;
                float newb = 0;
                float minp = 0;

                preb = getPreviousB();
                add = getAdditional();
                inter = getInterest(preb,add);
                newb = getNewb(preb,add,inter);
                minp = getMinpay(newb);

            }
            public static float getPreviousB()
            {
                Scanner cd = new Scanner(System.in);
                System.out.print("Enter previous balance");
                return cd.nextFloat();
            }
            public static float getAdditional()
            {
                Scanner cd = new Scanner(System.in);
                System.out.print("Enter total new charges");
                return cd.nextFloat();
            }
            public static float getInterest(float preb,float add)
            {
            float interest = 0;
            if(preb == 0)
            {
                interest = 0;
                return interest;
            }
            else
            {
                interest = ( preb + add)*0.020;
                return interest;
            }
        }

        public static float getNewb(float preb,float add,float inter)
        {
            float newbalance = 0;
            newbalance = (preb + add + interest);
            return newbalance;
        }

        public static float getMinpay(float newb)
        {
            float minimal = 0;
            if(newbalance < 50)
            {
                minimal = newbalance;
                return minimal;
            }
            else if( newbalace >= 50 && newbalance <= 300)
            {
                minimal = 50;
                return minimal;
            }
            else
            {
                minimal = (newbalance)*.020;
                return minimal;

            }
        }
        System.out.println("CS International Card  Statement");
        System.out.println("====================\n");
        System.out.println("Previous Balance:\t $%.2f%n",preb);  // prints 
        System.out.println("Additional Charges:\t $%.2f%n",add);  
        System.out.println("Interest:\t\t$%.2f%n",inter);  
        System.out.println("\nNew Balance:\t\t$%.2f%n",newb);  
        System.out.println("Minimum Payment:\t$%.2f%n",minp);  
    }
    }

// 程序应接受用户输入的先前余额和新费用总额。然后应该计算利息,新余额(以前的余额+附加费用+利息)和最低工资。如果先前余额为 0,则利息为 0,否则利息为先前余额的 20% 和额外费用。对于最低工资,如果新余额小于50,则等于最低工资,否则如果在50到300之间,则最低工资为50,如果更高,则最低工资为新余额的20%

【问题讨论】:

    标签: bluej


    【解决方案1】:

    我无法为您的程序解决错误,但我能够为它制作自己的版本。

    import java.util.Scanner;
    

    类代码 {

    public static void main(){
        Scanner sc = new Scanner(System.in);
        System.out.println("enter previous balance and total new charges");
        double pbal = sc.nextDouble();
        double tnc = sc.nextDouble();
        double nbal,interest,mp=0.0;
    
        if(pbal == 0){
            interest = 0.0;
            nbal=pbal+ tnc;
        }
        else{ 
            interest = (pbal+tnc)*0.2;//0.2=20/100
            nbal=pbal + interest + tnc;
        }
        if(nbal<50){
            mp=nbal;
        }
        if(nbal>50 && nbal<300){
            mp=50;
        }
        if(nbal>300){
         mp=nbal *0.2;   //0.2=20/100
        }
        System.out.println("old balance" + pbal + " " + "total new charges" + tnc);
        System.out.println("new balance" + nbal + " " + "interest" + interest + " " + "minimal pay" + mp);
    
    }
    

    }

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-21
      • 1970-01-01
      • 2022-01-04
      • 2017-11-21
      相关资源
      最近更新 更多