I need help writing the following java Java Method below. I just need a method to take a user inputted First or Last Name and return the associated phone number, thank you!
import java.util.*;
import java.io.*;
class PhoneList {
public static void main(String[] args) throws Exception {
boolean loop = true;
File file = new File("PhoneList_Data.txt");
FileWriter fw = new FileWriter(file, true);
fw.write("PhoneList Data");
fw.write("\n" + "Last, First: 6041337567, 2181731566");
// do { } (loop)
fw.close();
}
// Method left needing to be written
void display(String name) {};
// Display: Given a First or Last Name, display every PhoneNumber
associated with that Name
void display(String name)
{
try {
File fileObj = new File("filename.txt");
Scanner fileReader = new Scanner(fileObj);
while (fileReader.hasNextLine()) {
String line = myReader.nextLine();
String[] wordList= line.split(" ");
if (wordList.contains(name))
{
System.out.println(line);
}
}
fileReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
I need help writing the following java Java Method below. I just need a method to...
Java Project
Draw a class diagram for the below class (using UML
notation)
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class myData {
public static void main(String[] args) {
String str;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter text (‘stop’ to quit).");
try (FileWriter fw = new FileWriter("test.txt")) {
do {
System.out.print(": ");
str = br.readLine();
if (str.compareTo("stop") == 0)
break;
str = str + "\r\n"; // add newline
fw.write(str);
} while (str.compareTo("stop") != 0);
} catch (IOException...
I need help with my computer science 2 lab. First I am asked to run the following program and check output? public static void main(String []args) { String filename= "output.txt"; File file = new File(fileName); try{ FileWriter fileWriter = new FileWriter(file, true); fileWriter.write("CS2: we finished the lecuter\n"); fileWriter.close(); }catch (Exception e){ system.out.println("your message"+e); } String inputfileName = "output.text"; File fileToRead = new File (inputfileName); try { Scanner = new Scanner (fileToread); while(Scanner.hasNextLine()){ String line = scanner.nextLine(); system.out.println(line); } }catch(Eception...
I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...
JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out the name of the student with the lowestgpa. In the attached zip file, you will find two files HighestGPA.java and students.dat. Students.dat file contains names of students and their gpa. Check if the code runs correctly in BlueJ or any other IDE by running the code. Modify the data to include few more students and their gpa. import java.util.*; // for the Scanner class...
create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...
Can someone help me to figure that error I have put below. JAVA ----jGRASP exec: javac -g P4Program.java P4Program.java:94: error: package list does not exist Iterator i = new list.iterator(); ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. Note: Below there are two different classes that work together. Each class has it's own fuctions/methods. import java.util.*; import java.io.*; public class P4Program{ public void linkedStackFromFile(){ String content = new String(); int count = 1; File...
I'm working with Java and I have a error message 1 error Error: Could not find or load main class Flowers. This is the problem: Instructions Make sure the source code file named Flowers.java is open. Declare the variables you will need. Write the Java statements that will open the input file, flowers.dat, for reading. Write a while loop to read the input until EOF is reached. In the body of the loop, print the name of each flower and where...
Please give me an explanation from the JAVA code below which
functions is to export data from JTable to database in .txt file
(text form).
String filePath"/Users/maestro Desktop/table.txt"; File file new File (filePath) // create a file object try t I/ Try execute codes that may encounter errors/exceptions FileWriter fw = new FileWriter(file); BufferedWriter bwnew Bufferedwriter (fw) // this loop will read data from the table's rows and columns for(int i = 0; 1くjTable.getRowCount(); 1++){ //for rows for(int j-0;j <...
Modify your program in Lab Assignment 4A to throw an exception if the file does not exist. An error message should result. Use the same file name in your program as 4A, however, use the new input file in 4B assignment dropbox. My code: import java.io.*; import java.util.*; public class Lab4B { public static void main(String[] args) throws IOException { final String input_file = "Lab_4A.txt"; final String output_file = "Lab_4A.txt"; Scanner x = null; FileWriter y = null; try {...
Write a unit test to test the following class. Using Java : //Test only the debit method in the BankAccount. : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; } public String getCustomerName() { return customerName; } public double getBalance() { return balance; } public void setDebit(double amount) throws Exception { if (frozen) { throw...