Question

The following file has syntax and/or logical errors. In each case, determine the problem, and fix...

The following file has syntax and/or logical errors. In each case, determine the problem, and fix the program.

using System;
using static System.Console;
using System.IO;
class DebugFourteen1
{
static void Main()
{
string fileName;
string directory;
string path;
string files;
int x;
Write("Enter a directory: ");
directory = ReadLine();
if(Directory.Exists(Directory))
{
files = Directory.GetFiles(directory);
if(files.Length = 0)
WriteLine("There are no files in " + directory);
else
{
WriteLine(directory + " contains the following files");
for(x = 0; x <= files.Length; ++x)
WriteLine(" " + files[y]);
Write("\nEnter a file name: ");
fileName = ReadLine();
path = directory + "/" + fileName;
if(File.Exists(path))
{
WriteLine(" File exists and was created " + File.GetCreationTime(path));
WriteLine("File was created " + File.GetCreationTime(fileName));
}
else
WriteLine(" " + fileName + " does not exist in the " + directory, " directory");
}
}
else
{
WriteLine("Directory " + directory + " does not exist");
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per requirement submitted above kindly find below solution.

Here new Windows Forms Application in C# is created using visual studio 2019 with name "DebugProgram".This application contains a class "DebugFourteen1.cs".Below are the details of this class.

DebugFourteen1.cs :

//namespace
using System;
using static System.Console;
using System.IO;
//application namespace
namespace DebugProgram
{
class DebugFourteen1 //C# class
{
//entry point main() method
static void Main(string[] args)
{
//declaring variables
string fileName;
string directory;
string path;
string[] files;
int x;
Write("Enter a directory: ");//asking user to enter directory
directory = ReadLine();//reading directory
//checking directory
if (Directory.Exists(directory))
{
files = Directory.GetFiles(directory);//get all directory
if (files.Length == 0)
//if directory doesnot exists
WriteLine("There are no files in " + directory);
else
{
//print directory
WriteLine(directory + " contains the following files");
for (x = 0; x < files.Length;x++) //using for loop
WriteLine(" " + files[x]);
Write("\nEnter a file name: ");//asking file name
fileName = ReadLine();//reading file
path = directory + "/" + fileName;
//checking file
if (File.Exists(path))
{
//if file exists
WriteLine(" File exists and was created " + File.GetCreationTime(path));
WriteLine("File was created " + File.GetCreationTime(fileName));//display time
}
else
//if file does not exists
WriteLine(" " + fileName + " does not exist in the " + directory, " directory");
}
}
else
{
//if directory does not exits
WriteLine("Directory " + directory + " does not exist");
}
}
}
}

==================================

Output :Run application using F5 and will get the screen as shown below

Screen 1:

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
The following file has syntax and/or logical errors. In each case, determine the problem, and fix...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# Programming: DebugNine2 The provided file has syntax and/or logical errors. Determine the problem(s) and fix...

    C# Programming: DebugNine2 The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. +DebugNine2.cs Instructions Build Output The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. 1/ Creates a Breakfast class 2 // and instantiates an object 3// Displays Breakfast special information 4 using static System.Console; Conpilation fatled: 2 error(s), 8 warnings DebugNine2.cs(9,61): error C$1810: Newline in constant DebugNine2.cs (11,6): error CS1525: Unexpected synbol "Writeltne class DebugNine2 7static void...

  • The files provided contain syntax and/or logic errors. In each case, determine and fix the problem,...

    The files provided 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. import java.util.*; public class DebugEight1 { public static void main(String args[]) { Scanner input = new Scanner(System.in); char userCode; String entry, message; boolean found = false; char[] okayCodes = {'A''C''T''H'}; StringBuffer prompt = new StringBuffer("Enter shipping code for this delivery\nValid codes are: "); for(int x = 0; x <...

  • Help In C# CHECKS: Program outputs score before and after bonus Method GiveBonus is overloaded Output:...

    Help In C# CHECKS: Program outputs score before and after bonus Method GiveBonus is overloaded Output: It has to look exactly like that Output Scores was 82.Now it is 5. Grade was B Now it is + --------------------------------------------------------------------- DebugEight2.cs has syntax and/or logical errors. Determine the problem(s), and fix the program. CODE: // Overloaded method gives bonus points // whether grade is a number or letter using static System.Console; class DebugEight2 { static void Main() { int numericScore = 82;...

  • In Chapter 11, you created the most recent version of the GreenvilleRevenue program, which prompts the...

    In Chapter 11, you created the most recent version of the GreenvilleRevenue program, which prompts the user for contestant data for this year’s Greenville Idol competition. Now, save all the entered data to a Greenville.ser file that is closed when data entry is complete and then reopened and read in, allowing the user to view lists of contestants with requested talent types. The program should output the name of the contestant, the talent, and the fee. using System; using static...

  • Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now...

    Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics: The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing, Dancing, Musical instrument, and Other. Name these fields talentCodes and talentStrings respectively. The class contains an auto-implemented property Name that holds a contestant’s name. The class contains fields for a talent code (talentCode) and description (talent)....

  • Using listAllFiles as a guide, write a method that has one File argument: if the argument...

    Using listAllFiles as a guide, write a method that has one File argument: if the argument is a directory, the method returns the total number of files below it. If the argument represents a file, the method just returns 1. public static int countFiles(File f)   import java.io.File; public class FileLister { public static void main(String[] args) { // Choose the directory you want to list. // If running in Eclipse, "." will just be the current project directory. // Use...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    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. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    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. // Prompt user for value to start // Value must be between 1 and 20 inclusive // At command line, count down to blastoff // With a brief pause between each displayed value import java.util.*; public class DebugSix3 { public static void...

  • Fix all syntax and logical errors for the following program. Please generate the correct output. //...

    Fix all syntax and logical errors for the following program. Please generate the correct output. // Program Typos prints three integer numbers, sums the numbers, calculates // the average, and prints the sum and the average of the three numbers. #Include #Include using namespace std; const ONE = 5; const TWO = 6; const THREE = 7; int Main () int sum; float average; cout << fixed << showpoint; c0ut << SetW(5) << ONE << TWO << THREE << end1;...

  • Identify a logical error in the following code and fix it. public class test1 {    ...

    Identify a logical error in the following code and fix it. public class test1 {     public static void main(String[] args){         int total;         float avg;         int a, b, c;         a=10;         b=5;         c=2;         total=a+b+c;         avg=total/3;         System.out.println("Average: "+avg);     } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT