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.
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.