File Input / Matrix Lab You are given a file called name_grades.txt with the fol
ID: 3833450 • Letter: F
Question
File Input / Matrix Lab
You are given a file called name_grades.txt with the following text:
John 95 92 85 90
Angela 90 83 82 100
Joe 75 85 68 72
You will store the names in a String array of size three and the grades in a matrix of size four x three. You will then pass the matrix into a method called addThreeMatrix which will add three points to each grade and then return the modified grades. Finally you will pass the name array to a method called modifyName which will change each o to a * and each A (lowercase and uppercase) to a @ and then return the modified array. Finally back in main you will print out the modified names and grades as follows:
J*hn 98 95 88 93
@ngel@ 93 86 85 103
J*e 78 88 71 75
Notes:
Here is an example which changes all letter’s L to a !
String name = “Lenny”;
name = name.toLowerCase();
name = name.replace(“l”,”!”);
This should be completed in java oracle and in one class. Thank you!
Explanation / Answer
public class TestClass {
public static void main(String args[]) {
String names[] = {"John", "Angela", "Joe"};
double grades[][] = {{95, 90, 75}, { 92, 83 , 85}, {85, 82, 68}, {90, 100, 72}};
int m = 3;
int n = 4;
System.out.println("student data is : ");
printData(grades, names, m, n);
addThreeMatrix(grades, n, m);
modifyName(names);
System.out.println("Modified student data is : ");
printData(grades, names, m, n);
}
public static void printData(double[][] grades, String names[], int m, int n) {
for (int i=0; i<m; i++) {
System.out.print(names[i] + " ");
for (int j=0; j<n; j++) {
System.out.print(grades[j][i] + " ");
}
System.out.println();
}
System.out.println(" ");
}
public static void addThreeMatrix(double grades[][], int m, int n) {
for (int i=0; i<m; i++) {
for (int j=0; j<n; j++) {
grades[i][j] = grades[i][j] + 3;
}
}
}
public static void modifyName(String names[]) {
for (int i=0; i<names.length; i++) {
names[i] = names[i].replace("A", "@");
names[i] = names[i].replace("a", "@");
names[i] = names[i].replace('o', '*');
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.