Question

Need help with code in C# Create an application that reads a file named Accounts.txt. Your application should load the file and display back the results. The application should allow the user to enter...

Need help with code in C#

Create an application that reads a file named Accounts.txt. Your application should load the file and display back the results.

The application should allow the user to enter additional entries and save them back to the same file.

The CSV file should contain the following fields:

AccountName, InvoiceDate, DueDate, AmountDue

If the CSV file contains invalid data you want to inform the user which row contained bad data.

Below is an example of what the output should look like; however, it does not need to match the output exactly.

Row 1: AccountName: John Smith. InvoiceDate: 1/1/2017. Due Date: 1/31/2017. AmountDue: $1000.00
...
Row 4: AccountName: Titan Industries. Invoice Date: 1/31/2017. Due Date: 2/28/2017. AmountDue: 1897.50

Would you like to enter additional data?
Please enter the Account Name: {UserInput}
Please enter the Invoice Date: {UserInput}
Please enter the Due Date: {UserInput}
Please enter the AmountDue: {UserInput}

Your data has been saved

You only need to allow the user to enter in one row per execution of the program. Make sure to validate the user input. Be sure to catch if the user enters an invalid date (hint: use the TryParse() function for both dates and decimals)

Make sure to use good object-oriented design principles (i.e., create separate classes for separate purposes, etc.).

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication8
{
class r
{
public void fileread()
{
try
{
string s = File.ReadAllText("e:\\Accounts.txt");
string[] s1 = s.Split('\n');
Console.WriteLine(" Account Name,Invoice Date, Due Date,Amount due");
int i = 1;
foreach (string ss in s1)
{
Console.WriteLine("Row " + i.ToString() + " " + ss);
i++;
}
}
catch (Exception e1)
{
Console.WriteLine(e1.Message.ToString());
}
}

}
class w
{
public void filewrite()
{
// Regex r = new Regex();
  
string name, invoicedate, duedate,dueamt;
  
  
string a = "y";
while (a == "y")
{
Console.WriteLine("Enter Name");

name = Console.ReadLine();
if(Regex.IsMatch (name,@"[A-Z,a-z]+$"))
{
}
else
{
Console.WriteLine("Not a valid Name,Press enter to exit");
Console.ReadLine();
Environment.Exit(0);

}
Console.WriteLine("Enter Invoice Date(2 digits for month/2 digits for day/4 digits for year)");
invoicedate = Console.ReadLine();
  
if (Regex.IsMatch(invoicedate, @"^\d{2}/\d{2}/\d{4}$"))
{
}
else
{
Console.WriteLine("Invalid Date,press Enter to exit");
Console.ReadLine();
Environment.Exit(0);

}
Console.WriteLine("Enter Due Date(2 digits for month/2 digits for day/4 digits for year)");

duedate = Console.ReadLine();
if (Regex.IsMatch(duedate, @"^\d{2}/\d{2}/\d{4}$"))
{
}
else
{
Console.WriteLine("Invalid Date,press Enter to exit");
Console.ReadLine();
Environment.Exit(0);

}

Console.WriteLine("Enter Due Amount(After decimal only 2 digits are allowed");
dueamt = Console.ReadLine();
if (Regex.IsMatch(dueamt, @"^\d*.\d{0,2}$"))
{
dueamt = "$"+dueamt;
}
else
{
Console.WriteLine("Invalid amount,press Enter to exit");
Console.ReadLine();

Environment.Exit(0);
  
  


}

  


  

  
  

string newcontent = name + "," + invoicedate + "," + duedate + "," + dueamt.ToString();
File.AppendAllText("e:\\Accounts.txt", newcontent + Environment.NewLine);
//File.AppendAllText("e:\\Accounts.txt", );
Console.WriteLine("Do you want to Add more record?(y/n)");
a = Console.ReadLine();
}
  
}
}

class Program
{
static void Main(string[] args)
{
  
char a = 'y';
r o=new r();
o.fileread();
w ow = new w();
ow.filewrite();
Console.ReadKey();

}
}
}

Add a comment
Know the answer?
Add Answer to:
Need help with code in C# Create an application that reads a file named Accounts.txt. Your application should load the file and display back the results. The application should allow the user to enter...
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
  • Java This application will be menu driven. The application should allow: 1. Collect student information and...

    Java This application will be menu driven. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID.   The user should be able to view/edit an existing student. Do not allow the user to edit student ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique ID. The user should be able to view/edit an existing course...

  • The application should be in JAVA and allow: 1. Collect student information and store it in...

    The application should be in JAVA and allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow the user to edit student ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique ID. The user should be able to view/edit an existing course information. User is...

  • In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student...

    In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...

  • (C++ Program) 1. Write a program to allow user enter an array of structures, with each...

    (C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • I am writing a console application in C#. It is a receipt where the user inputs...

    I am writing a console application in C#. It is a receipt where the user inputs the item then quantity and then price per item. It is then validated through regular expressions. I need to put this in a multidimensional array to print out (command line print), like each row would have a columns for item, quantity, price and then subtotal for each item, but cannot figure it out. I also need the regular expression in a do while loop...

  • need help please! thanks!! C++ programming Your program should do the following Prompt the user for...

    need help please! thanks!! C++ programming Your program should do the following Prompt the user for the first number (int data type) Read the first number Prompt the user for the second number (int data type) Read the second number Write code to calculate the quotient and remainder when the first number is divided by the second number Make sure to used variables in your output statements. /* OUTPUT Enter the first number: 126 Enter the second number: 31 126...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • 6-1 Test and debug the Invoice Application i need help with this please.. all help is...

    6-1 Test and debug the Invoice Application i need help with this please.. all help is appreciated Source code Java: import java.util.Scanner; import java.text.NumberFormat; public class InvoiceApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user System.out.print("Enter customer type (r/c): "); String customerType = sc.next(); System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); // get the discount percent double discountPercent = 0.0; switch(customerType) {...

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