Discover answers to your most pressing questions at Westonci.ca, the ultimate Q&A platform that connects you with expert solutions. Connect with a community of experts ready to help you find solutions to your questions quickly and accurately. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields 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 using our service. We're always here to provide accurate and up-to-date answers to all your queries. Westonci.ca is your go-to source for reliable answers. Return soon for more expert insights.