Need help debugging DebugThirteen1.Java
Debug 13-1
DebugThirteen1.Java
// Program describes two files
// tells you which one is newer and which one is larger
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;
public class DebugThirteen1
{
public static void main(String[] args)
{
Path file1 =
Paths.get("/root/sandbox/DebugDataOne1");
Path file2 =
Paths.get("/root/sandbox/DebugDataOne2.txt");
try
{
BasicFileAttributes attr1 =
Files.readAttributes(file1, BasicFileAttributes.class);
System.out.println("File: " + file1getFileName());
System.out.println("Creation time " + attr1.creationTime());
System.out.println("Last modified time " + attr1lastModifiedTime());
System.out.println("Size " + attr1.size());
BasicFileAttributes attr2 =
Files.readAttributes(file2, BasicFileAttributes.class);
System.out.println("\nFile: " + file2.getFileName);
System.out.println("Creation time " + attr2.creationTime());
System.out.println("Last modified time " + attr2.lastModifiedTime());
System.out.println("Size " + attr2.size());
if(attr1.creationTime().compareto(attr2.creationTime()) > 0)
System.out.println("\n" + file1.getFileName() + " was created earlier");
else
System.out.println("\n" + file1.getFileName() + " was not created earlier");
if(attr1.size() > attr2.size())
System.out.println(file1.getFileName() " is larger ");
else
System.out.println(file1.getFileName() " is not larger");
}
catch(IOException e)
{
System.out.println("IO Exception");
}
}
}
---------------------------------------------------------------------------------------------------------------------
DebugDataOne1.txt
Somewhere over the rainbow.
------------------------------------------------------
DebugDataOne2.txt
There's no place like home.
Are you a good witch or a bad witch?
-------------------------------------------------------
The code fixes have been explained with comments. Please let me know if there is any problem.
Code:
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;
public class DebugThirteen1
{
public static void main(String[] args)
{
// Fix 1: Adding the extension to the file DebugDataone1
Path file1 = Paths.get("/root/sandbox/DebugDataOne1.txt");
Path file2 = Paths.get("/root/sandbox/DebugDataOne2.txt");
try
{
BasicFileAttributes attr1 = Files.readAttributes(file1, BasicFileAttributes.class);
// Fix 2: Calling the method getFileName which belongs to the object file1
System.out.println("File: " + file1.getFileName());
System.out.println("Creation time " + attr1.creationTime());
// Fix 3: Calling the method lastModifiedTime which belongs to the object attr1
System.out.println("Last modified time " + attr1.lastModifiedTime());
System.out.println("Size " + attr1.size());
BasicFileAttributes attr2 = Files.readAttributes(file2, BasicFileAttributes.class);
// Fix 4: The getFileName is a method, so after the method name the parantheses should be present which makes it a valid method call
System.out.println("\nFile: " + file2.getFileName());
System.out.println("Creation time " + attr2.creationTime());
System.out.println("Last modified time " + attr2.lastModifiedTime());
System.out.println("Size " + attr2.size());
// Fix 5: Here the method name is compareTo not compareto
if(attr1.creationTime().compareTo(attr2.creationTime()) > 0)
{
System.out.println("\n" + file1.getFileName() + " was created earlier");
}
else
{
System.out.println("\n" + file1.getFileName() + " was not created earlier");
}
if(attr1.size() > attr2.size())
{
// Fix 6: Here two strings need to be concatenated so a + sign should exist between the two strings
System.out.println(file1.getFileName() + " is larger ");
}
else
{
// Fix 7: Here two strings need to be concatenated so a + sign should exist between the two strings
System.out.println(file1.getFileName() + " is not larger");
}
}
catch(IOException e)
{
System.out.println("IO Exception");
}
}
}
Sample Output:

Need help debugging DebugThirteen1.Java Debug 13-1 DebugThirteen1.Java // Program describes two files // tells you which...
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Note: DebugDataOne1.txt and DebugDataOne2.txt do not need to be edited. They are used by the program. import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { public static void main(String[] args) { Path file1 = Paths.get("/root/sandbox/DebugDataOne1.txt"); // path to file DebugDataOne1.txt in...
I have the code
DebugDataOne1.txt
Somewhere over the rainbow.
DebugDataOne2.txt
There's no place like home.
Are you a good witch or a bad witch?
DebugThirteen1.java
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;
public class DebugThirteen1
{
public static void main(String[] args)
{
try
{
Path file1 =
Paths.get("C:\\Java\\Chapter.13\\\\DebugData1.txt");
Path file2 =
Paths.get("C:\\Java\\Chapter.13\\\\DebugData2.txt");// Please use
the path of the file from where you want to access it.
BasicFileAttributes attr1 =
Files.readAttributes(file1, BasicFileAttributes.class);
System.out.println("File: " + file1.getFileName());
System.out.println("Creation time " + attr1.creationTime());
System.out.println("Last...
Programming Exercise 13-3 Instructions Write an application that displays the sizes of the files lyric1.txt and lyric2.txt in bytes as well as the ratio of their sizes to each other. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- FileSizeComparison.java import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class FileSizeComparison { public static void main(String[] args) { Path textFile = Paths.get("/root/sandbox/lyric1.txt"); Path wordFile = Paths.get("/root/sandbox/lyric2.txt"); // Write your code here } } ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- lyric1.txt I hope you had the time of your life. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- lyric2.txt Would you lie with...
This is a JAVA language The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Note: DebugData2.txt does not need to be edited. It is used by the program. DebugData2.txt 435-9845 239-9845 981-9883 384-5656 875-3784 874-8120 DebugThirteen2.java // Program reads in a file of phone numbers without area codes // inserts "(312)...
I need help debugging this Java program. I am getting this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at population.Population.main(Population.java:85) I am not able to run this program. ------------------------------------------------------------------- import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /* Linked list node*/ class node { long data; long year; String country; node next; node(String c,long y,long d) { country=c; year=y; data = d; next = null; } } public class Population { private static node head; public static void push(String...
Java: Hello, can someone please find a way to call my arraylist "list" and linkedhashmap called "jobMap" in my main method instead of calling them in the 2 classes? Also, is there a way to avoid the "Suppress Warning" portion in RoundRobin.java? I haven't been able to find a way for some reason. This is a job scheduling program, so the output should give the same values. To run: javac Main.java, java Main 5jobs.txt . txt file will be provided...
Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...
Need help in the below question. Answer in java Start with the tree.java program (Listing 8.1) and modify it to create a binary tree from a string of letters (like A, B, and so on) entered by the user. Each letter will be displayed in its own node. Construct the tree so that all the nodes that contain letters are leaves. Parent nodes can contain some non-letter symbol like +. Make sure that every parent node has exactly two children....
In JAVA, In two classes: As a zookeeper, it is important to know the activities of the animals in your care and to monitor their living habitats. Create a monitoring system that does all of the following: -Asks a user if they want to monitor an animal, monitor a habitat, or exit -Displays a list of animal/habitat options (based on the previous selection) as read from either the animals or habitats file and asks the user to enter one of...
pls help me with it. you just need to answer the question in Appointment.Java, There is only 1 question u need to answer! Appointment.Java package option1.stage3; import option1.stage1.Doctor; import option1.stage1.Patient; import option1.stage2.TimeSlot; public class Appointment { private Doctor doctor; private Patient patient; private TimeSlot timeSlot; public Doctor getDoctor() { return doctor; } public void setDoctor(Doctor doctor) { this.doctor = doctor; } public Patient getPatient() { return patient; } public void setPatient(Patient patient) { this.patient = patient; } public TimeSlot getTimeSlot()...