阅读背景:

我想在我的文件系统中保存多个数据

来源:互联网 

`

    NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US);


    String employeeName;    
    float hoursWorked;          
    float hourlyRate;           
    float basepay;          
    float netpay;
    float overtime = 0;
    int numberofemp= 0;
    final JPanel panel = new JPanel();

        System.out.println( "Assignement 2\n\n");   
            numberofemp = Integer.parseInt(JOptionPane.showInputDialog("Enter No of Employee"));

     int[] arrayList= new int[numberofemp];
       for (int i = 0; i < arrayList.length; i++)

      {
             employeeName = JOptionPane.showInputDialog("Enter the employee name:");

       do
        {
           hourlyRate = Float.parseFloat(JOptionPane.showInputDialog("Enter the number of Hourly Rate :"));

           if (hourlyRate < 8)
                {   
                JOptionPane.showMessageDialog(panel, "The hourly rate must be 8 an hour", "Error", JOptionPane.ERROR_MESSAGE);
                }
              }
       while ( hourlyRate < 8 ); 

           do
             {
               hoursWorked = Float.parseFloat(JOptionPane.showInputDialog("Enter the number of hours worked:"));

            if (hoursWorked >60)
            {
                    JOptionPane.showMessageDialog(panel, "The number of hours worked must be under 60", "Error", JOptionPane.ERROR_MESSAGE);                     
            }
          }
        while ( hoursWorked >60);


                    if (hoursWorked > 40)
                        {
                        overtime = (float) (  (hoursWorked - 40) *(hourlyRate * 1.5));
                        }

                        else
                        { basepay = hoursWorked * hourlyRate;

                        }
        netpay  =  basepay + overtime;          

        System.out.println( "\n\nEmployee Name: " + employeeName);      
         System.out.println( "Hours Worked: " + hoursWorked );
         System.out.println( "Base Pay: " + currency.format(basepay) );
          System.out.println( "Overtime Pay: " + currency.format(overtime)); 
           System.out.println( "Total Pay: " + currency.format(netpay)); 
            System.out.println( );


 try
  {
     PrintWriter prst;
         prst = new PrintWriter( "C://Users/tushar/Desktop/Workspace/Assignment_2/out.txt" );
              prst.println( "\n\nEmployee Name: " + employeeName);
                prst.println( "\n\nBasePay: " + basepay);
                  prst.println( "\n\nOvertime Pay: " + overtime);
                    prst.println( "\n\nTotal pay: " + netpay);
                       prst.close();

                                     }
 catch (Exception e)
 {
         System.err.println ("Error writing to file");
 }                      



       }
     }  }
    NumberFormat currency = NumberFormat.ge



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: