eading record 5: j31l b2ll5 Reading record 6: br3wn ch0rl21 Reading record 7: br0v3 j3hnn5 Reading record 8: b2rd tw11ty Reading record 9: h1dg1h3g s3n2c Reading record 10: j1ts3n g13rg1 Reading record 11: m0rt20n m0rv2n Modified records: Record 0: mouse mickey Record 1: flintstone fred Record 2: simpson homer Record 3: doe john Record 4: lightyear bu
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
Can you help with my code? I am attaching the errors I am receiving.
But this is what the expected output for the program should be:
Reading record 0: m3us1 m2ck15
Reading record 1: fl2ntst3n1 fr1d
Reading record 2: s2mps3n h3m1r
Reading record 3: d31 j3hn
Reading record 4: l2ghty10r b4zz
Reading record 5: j31l b2ll5
Reading record 6: br3wn ch0rl21
Reading record 7: br0v3 j3hnn5
Reading record 8: b2rd tw11ty
Reading record 9: h1dg1h3g s3n2c
Reading record 10: j1ts3n g13rg1
Reading record 11: m0rt20n m0rv2n
Modified records:
Record 0: mouse mickey
Record 1: flintstone fred
Record 2: simpson homer
Record 3: doe john
Record 4: lightyear buzz
Record 5: joel billy
Record 6: brown charlie
Record 7: bravo johnny
Record 8: bird tweety
Record 9: hedgehog sonic
Record 10: jetson george
Record 11: martian marvin
JAVA CODE:
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Random;
import java.util.Scanner;
public class PA3 {
String newName;
static String modifyName = "";
static String bigRecord;
static String[] bigRecordArray = new String[20];
static int index = 0;
static int aNumber;
public static void main(String[] args) {
Random rand = new Random();
List<String> list = new LinkedList<String>();
Path file = Paths.get("info2.txt");
Scanner sc = null;
try {
sc = new Scanner(new File(file.getFileName().toString()));
System.out.println("Information Read form file:");
while (sc.hasNext()) {
bigRecord = sc.nextLine();
System.out.println("Reading Record " + index + ": " + bigRecord);
bigRecordArray[index++] = modifyVowels(bigRecord, modifyName);
}
sc.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("Modified Records:");
printRecords(bigRecordArray, index - 1);
bubbleSort(bigRecordArray, index - 1);
createLinkedList(list, bigRecordArray, index);
printList(list);
aNumber = rand.nextInt(index);
System.out.println("\nWill be removing record number: " + aNumber);
list.remove(aNumber);
printList(list);
aNumber = rand.nextInt(index);
System.out.println("\nWill be removing record number: " + aNumber);
list.remove(aNumber);
printList(list);
}
public static String modifyVowels(String fullName, String modifyName) {
if (fullName.length() == 0)
return modifyName;
else {
if (fullName.charAt(0) == '0')
modifyName = modifyName + "a";
else if (fullName.charAt(0) == '1')
modifyName = modifyName + "e";
else if (fullName.charAt(0) == '2')
modifyName = modifyName + "i";
else if (fullName.charAt(0) == '3')
modifyName = modifyName + "o";
else if (fullName.charAt(0) == '4')
modifyName = modifyName + "u";
else if (fullName.charAt(0) == '5')
modifyName = modifyName + "y";
else
modifyName = modifyName + fullName.charAt(0);
return modifyVowels(fullName.substring(1), modifyName);
}
}
public static void printRecords(String[] fullName, int index) {
for (int i = 0; i <= index; i++) {
System.out.println("Record " + i + ": " + fullName[i]);
}
}
static void bubbleSort(String[] arr, int n) {
String temp = "";
for (int j = 0; j < n; j++)
{
for (int i = j + 1; i < n + 1; i++)
{
if (arr[j].compareTo(arr[i]) > 0)
{
temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
System.out.println("After Sorting:");
printRecords(arr, n);
}
static void createLinkedList(List<String> list, String[] fullName, int index) {
for (int i = 0; i < index; i++) {
list.add(fullName[i]);
}
}
static void printList(List<String> list) {
System.out.println("\nLinked list records:");
int i = 0;
ListIterator<String> iterator = list.listIterator();
while (iterator.hasNext())
System.out.println("Record " + i++ + ": " + iterator.next());
}
}
Step by step
Solved in 2 steps