Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 货币格式化程序无法使用System.out.format_Java_String.format_Currency Formatting - Fatal编程技术网

Java 货币格式化程序无法使用System.out.format

Java 货币格式化程序无法使用System.out.format,java,string.format,currency-formatting,Java,String.format,Currency Formatting,我知道我做错了什么,我只是不知道是什么。 我需要所有的美元价值是在美国货币的格式。 据我所知,在货币格式化程序中使用System.out.format有问题。 我在java方面没有太多经验,可能有更好的方法来实现这一点 输出应该是这样的 import java.util.*; 导入java.lang.*; 导入java.text.*; 公共类项目J2 { 公共静态void main(字符串[]args) { 扫描仪s=新的扫描仪(System.in); NumberFormat curren

我知道我做错了什么,我只是不知道是什么。 我需要所有的美元价值是在美国货币的格式。 据我所知,在货币格式化程序中使用System.out.format有问题。 我在java方面没有太多经验,可能有更好的方法来实现这一点

输出应该是这样的

import java.util.*;
导入java.lang.*;
导入java.text.*;
公共类项目J2
{  
公共静态void main(字符串[]args)
{
扫描仪s=新的扫描仪(System.in);
NumberFormat currency=NumberFormat.getCurrencyInstance();
字符串输入=”;
整数度=0;
整年=0;
int年龄=0;
int=0;
最终int博士学位=84396;
最终int masters=69732;
最终国际文凭=59124;
高中毕业=35256;
最终int节点度=25636;
系统输出打印(“1=无学位”);
系统输出打印(“\n”);
系统输出打印(“2=高中学位”);
系统输出打印(“\n”);
系统输出打印(“3=学士学位”);
系统输出打印(“\n”);
系统输出打印(“4=硕士学位”);
系统输出打印(“\n”);
系统输出打印(“5=博士学位”);
系统输出打印(“\n”);
系统输出打印(“\n”);
System.out.print(“输入与学位对应的数字:”);
输入=s.nextLine();
度=整数.parseInt(输入);
如果(度<1 | |度>5)
{
System.out.print(“您输入的菜单选项无效”);
System.out.print(“请重新运行程序并输入有效选项”);
系统出口(0);
}
系统输出打印(“\n”);
系统输出打印(“输入本年度:”);
输入=s.nextLine();
年份=整数.parseInt(输入);
系统输出打印(“输入您当前的年龄:”;
输入=s.nextLine();
年龄=整数.parseInt(输入);
系统输出打印(“输入计划退休年龄D:”);
输入=s.nextLine();
退休=整数.parseInt(输入);
系统输出打印(“\n”);
系统输出打印(“\n”);
如果(度==1)
{
系统输出打印(“基于当前统计数据,无学位:”);
系统输出打印(“\n”);
系统输出打印(“您的年薪将为”+货币格式(noDegree));
系统输出打印(“\n”);
System.out.format(“在%d年退休,在%d年您将获得%d”,退休,(年+(退休年龄)),货币.format(noDegree*(退休年龄));
系统输出打印(“\n”);
System.out.format(“有了高中学位,你可以比没有学位多挣%d。”,currency.format(高中*(退休年龄));
系统输出打印(“\n”);
System.out.format(“拥有学士学位,你可以比没有学位赚%d。”,currency.format(学士*(退休年龄));
系统输出打印(“\n”);
System.out.format(“拥有硕士学位,你可以比没有学位的人多挣%d。”,currency.format(硕士*(退休年龄));
系统输出打印(“\n”);
System.out.format(“拥有博士学位,你可以比没有学位多挣%d。”,currency.format(博士学位*(退休年龄));
系统输出打印(“\n”);
}
否则如果(度==2)
{
系统输出打印(“基于当前统计数据和高中学位:”);
系统输出打印(“\n”);
System.out.print(“您的年薪将为”+currency.format(高中));
系统输出打印(“\n”);
System.out.format(“在%d年退休,在%d年,您将获得%d”,退休,(年+(退休年龄)),currency.format(高中*(退休年龄));
系统输出打印(“\n”);
System.out.format(“这比你没有学位时多了%d)”,currency.format((高中*(退休年龄))-(noDegree*(退休年龄));
系统输出打印(“\n”);
System.out.format(“拥有学士学位,你可以比刚获得高中学位多挣%d。”,currency.format(学士*(退休年龄));
系统输出打印(“\n”);
System.out.format(“拥有硕士学位,你可以比刚获得高中学位多挣%d。”,currency.format((硕士*(退休年龄))-(高中*(退休年龄));
系统输出打印(“\n”);
System.out.format(“拥有博士学位,你可以比刚获得高中学位多挣%d。”,currency.format((硕士*(退休年龄))-(高中*(退休年龄));
系统输出打印(“\n”);
}
否则如果(度==3)
{
系统输出打印(“基于当前统计数据和学士学位:”);
系统输出打印(“\n”);
系统输出打印(“您的年薪将为”+货币格式(学士));
系统输出打印(“\n”);
System.out.format(“在%d年退休,在%d年,您将获得%d”,退休,(年+(退休年龄)),货币(学士*(退休年龄));
系统输出打印(“\n”);
System.out.format(“这比你没有学位时多了%d。”,currency.format((学士*(退休年龄))-(noDegree*(退休年龄));
系统输出打印(“\n”);
System.out.format(“这比高中学历多%d。”,currency.format((学士*(退休年龄))-(高中*(退休年龄));
系统输出打印(“\n”);
System.out.format(“有了硕士学位,你可以比刚拿到高中学位多挣%d。”,currency.format((硕士*)(退休
import java.util.*;
import java.lang.*;
import java.text.*;

public class Proj2
{  
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        NumberFormat currency = NumberFormat.getCurrencyInstance();

        String input = "";
        int degree = 0;
        int year = 0;
        int age = 0;
        int retirement = 0;
        final int doctorate = 84396;
        final int masters = 69732;
        final int bachelor = 59124;
        final int highSchool = 35256;
        final int noDegree = 25636;



        System.out.print("1 = No Degree");
        System.out.print("\n");
        System.out.print("2 = High school Degree");
        System.out.print("\n");
        System.out.print("3 = Bachelor's Degree");
        System.out.print("\n");
        System.out.print("4 = Masters Degree");
        System.out.print("\n");
        System.out.print("5 = Doctorate Degree");
        System.out.print("\n");

        System.out.print("\n");
        System.out.print("Enter the number that corresponds to your degree: ");
        input = s.nextLine();
        degree = Integer.parseInt(input);

        if (degree < 1 || degree > 5)
        {
            System.out.print("You entered an invalid menu choice.");
            System.out.print("Please re-run the program and enter in a valid choice.");
            System.exit(0);
        }

        System.out.print("\n");
        System.out.print("Enter the current year: ");
        input = s.nextLine();
        year = Integer.parseInt(input);

        System.out.print("Enter your current age: ");
        input = s.nextLine();
        age = Integer.parseInt(input);

        System.out.print("Enter planned age of retirementd: ");
        input = s.nextLine();
        retirement = Integer.parseInt(input);
        System.out.print("\n");

        System.out.print("\n");

        if (degree == 1)
        {
            System.out.print("Based on current statistics and no degree:");
            System.out.print("\n");
            System.out.print("Your annual salary will be " +currency.format(noDegree));
            System.out.print("\n");
            System.out.format("Retiring at age %d in %d you will make a total of %d", retirement, (year + (retirement - age)), currency.format(noDegree * (retirement - age)));
            System.out.print("\n");
            System.out.format("With a HighSchool degree, you can earn %d more than if you had no Degree.", currency.format(highSchool * (retirement - age)));
            System.out.print("\n");
            System.out.format("With a Bachelor's degree, you can earn %d more than if you had no Degree.", currency.format(bachelor * (retirement - age)));
            System.out.print("\n");
            System.out.format("With a Masters degree, you can earn %d more than if you had a no Degree.", currency.format(masters * (retirement - age)));
            System.out.print("\n");
            System.out.format("With a Doctarites degree, you can earn %d more than if you had a no Degree.", currency.format(doctorate * (retirement - age)));
            System.out.print("\n");
        }
        else if (degree == 2)
        {
            System.out.print("Based on current statistics and High School degree:");
            System.out.print("\n");
            System.out.print("Your annual salary will be " +currency.format(highSchool));
            System.out.print("\n");
            System.out.format("Retiring at age %d in %d you will make a total of %d", retirement, (year + (retirement - age)), currency.format(highSchool * (retirement - age)));
            System.out.print("\n");
            System.out.format("That is %d more than if you had no Degree.", currency.format((highSchool * (retirement - age)) - (noDegree * (retirement - age))));
            System.out.print("\n");
            System.out.format("With a Bachelor's degree, you can earn %d more than if you just had a High School degree.", currency.format(bachelor * (retirement - age)));
            System.out.print("\n");
            System.out.format("With a Masters degree, you can earn %d more than if you just had a High School degree.", currency.format((masters * (retirement - age)) - (highSchool * (retirement - age))));
            System.out.print("\n");
            System.out.format("With a Doctarites degree, you can earn %d more than if you just had a High School degree.", currency.format((masters * (retirement - age)) - (highSchool * (retirement - age))));
            System.out.print("\n");
        }
        else if (degree == 3)
        {
            System.out.print("Based on current statistics and Bachelor's degree:");
            System.out.print("\n");
            System.out.print("Your annual salary will be " +currency.format(bachelor));
            System.out.print("\n");
            System.out.format("Retiring at age %d in %d you will make a total of %d", retirement, (year + (retirement - age)), currency(bachelor * (retirement - age)));
            System.out.print("\n");
            System.out.format("That is %d more than if you had no Degree.", currency.format((bachelor * (retirement - age)) - (noDegree * (retirement - age))));
            System.out.print("\n");
            System.out.format("That is %d more than if you had a High School degree.", currency.format((bachelor * (retirement - age)) - (highSchool * (retirement - age))));
            System.out.print("\n");
            System.out.format("With a Masters degree, you can earn %d more than if you just had a High School degree.", currency.format((masters * (retirement - age)) - (bachelor * (retirement - age))));
            System.out.print("\n");
            System.out.format("With a Doctarites degree, you can earn %d more than if you just had a High School degree.", currency.format((masters * (retirement - age)) - (bachelor * (retirement - age))));
            System.out.print("\n");
        }
        else if (degree == 4)
        {
            System.out.print("Based on current statistics and Masters degree:");
            System.out.print("\n");
            System.out.print("Your annual salary will be " +currency.format(masters));
            System.out.print("\n");
            System.out.format("Retiring at age %d in %d you will make a total of %d", retirement, (year + (retirement - age)), currency.format(masters * (retirement - age)));
            System.out.print("\n");
            System.out.format("That is %d more than if you had no Degree.", currency.format((masters * (retirement - age)) - (noDegree * (retirement - age))));
            System.out.print("\n");
            System.out.format("That is %d more than if you had a High School degree.", currency.format((masters * (retirement - age)) - (highSchool * (retirement - age))));
            System.out.print("\n");
            System.out.format("That is %d more than if you had a Bachelor's degree.", currency.format((masters * (retirement - age)) - (bachelor * (retirement - age))));
            System.out.print("\n");
            System.out.format("With a Doctarites degree, you can earn %d more than if you just had a High School degree.", currency.format((masters * (retirement - age)) - (bachelor * (retirement - age))));
            System.out.print("\n");
        }
        else if (degree == 5)
        {
            System.out.print("Based on current statistics and Doctarates degree:");
            System.out.print("\n");
            System.out.print("Your annual salary will be " +currency.format(doctorate));
            System.out.print("\n");
            System.out.format("Retiring at age %d in %d you will make a total of %d", retirement, (year + (retirement - age)), currency.format(doctorate * (retirement - age)));
            System.out.print("\n");
            System.out.format("That is %d more than if you had no Degree.", currency.format((doctorate * (retirement - age)) - (noDegree * (retirement - age))));
            System.out.print("\n");
            System.out.format("That is %d more than if you had a High School degree.", currency.format((doctorate * (retirement - age)) - (highSchool * (retirement - age))));
            System.out.print("\n");
            System.out.format("That is %d more than if you had a Bachelor's degree.", currency.format((doctorate * (retirement - age)) - (bachelor * (retirement - age))));
            System.out.print("\n");
            System.out.format("That is %d more than if you had a Bachelor's degree.", currency.format((doctorate * (retirement - age)) - (masters * (retirement - age))));
            System.out.print("\n");
        }
    }
}