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%
答案 0 :(得分:0)
我无法解决您的程序错误,但我能够为它制作我自己的版本。
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);
}
}
希望这有帮助。