Get reliable answers to your questions at Westonci.ca, where our knowledgeable community is always ready to help. Discover solutions to your questions from experienced professionals across multiple fields on our comprehensive Q&A platform. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.

Code a complete Java program to load and process a 1-dimensional array.

Create clear comments as you code to tell me what you are doing.
Import the Java libraries that you will need.
Create a single dimensional array that will hold 15 wages.
In the main, load an array with all of the records from a .txt file named Salary txt. The file has 15 records in it.
Sort the array in ascending order.
Write a method named increaseWages(). This method will add $500 to each of the 15 wages. In other words, you are giving each person a raise of $500.
Pass the array to the method from the main().
Increase the wage amounts in the array (as described above), in the method. In other words, in the end the array should hold the NEW, higher wages.
Output each new wage (use the console for this)
Calculate a total of the new wages in the method
Output the total of the new wages in the method (use a dialog box for this)
Return the array with the new wages to the main().
There is NO user interaction in this program.

Sagot :

Answer:

Here you go.Consider giving brainliest if it helped.

Explanation:

import java.io.*;//include this header for the file operation

import java.util.*;//to perform java utilities

import javax.swing.JOptionPane;//needed fro dialog box

class Driver{

  public static void main(String args[]){

      int wages[]=new int[15];//array to hold the wages

      int index=0;

      try{

          //use try catch for the file operation

          File file=new File("wages.txt");

          Scanner sc=new Scanner(file);//pass the file object to the scanner to ready values

          while(sc.hasNext()){

              String data=sc.nextLine();//reads a wage as a string

              String w=data.substring(1);//remove the dollar from the string data

              wages[index++]=Integer.parseInt(w);//convert the wage to int and store it in the array

          }

          sc.close();//close the scanner

      }catch(FileNotFoundException e){

          System.out.println("Error Occurrred While Reading File");

      }

     

      //sort the array using in built sort function

      Arrays.sort(wages);

      //print the wages

      System.out.println("Wages of 15 person in ascending order:");

      for(int i=0;i<wages.length;i++){

          System.out.print("$"+wages[i]+" ");

      }

      //call the increases wages method

      wages=increaseWages(wages);//this method return the updated wages array

     

  }

 

  //since we can call only static methods from main hence increaseWages is also static

  public static int[] increaseWages(int wages[]){

      //increase the wages

      for(int i=0;i<wages.length;i++){

          wages[i]+=500;

      }

     

      //print the new wages

      int sum=0;

      System.out.println("\n\nNew wages of 15 person in ascending order:");

      for(int i=0;i<wages.length;i++){

          sum+=wages[i];//sums up the new wages

          System.out.print("$"+wages[i]+" ");

      }

     

      //display the summation of the new wages in a dialog box

      JOptionPane.showMessageDialog(null,"Total of new wages: "+sum);

      return wages;

  }

}

Thank you for trusting us with your questions. We're here to help you find accurate answers quickly and efficiently. Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.