Question

the language i wan used in C# is visual basic.Create a console program that contains the...

the language i wan used in C# is visual basic.Create a console program that contains the following

·         A Class named Account with the following properties:

o   public int Id { get; set; }

o   public string Firstname { get; set; }

o   public string Lastname { get; set; }

o   public double Balance { get; set; }

o   public DateTime CreationDate { get; set; }

o   Create a constructor that initializes all of the properties.

o   Create a ToString Account method which returns a string containing all of the properties with at least one space between property values in the string.

·         In the main method of the console program create a list of accounts.

·         Add 10 accounts to the list with the following data:

ID

first name

last name

balance

creation date

1006

John

Doe

100

1/18/2014

1009

Jane

Doe

300

1/18/2014

1002

Richard

Doe

548

1/18/2015

1003

John

Deer

28

3/18/2014

1004

Bob

Reindeer

396

1/22/2016

1005

Patricia

Rabbit

1523.72

7/8/2013

1000

Bill

Rabbit

152

6/28/2013

1007

Steve

Bear

768

9/18/2015

1008

Rita

Slowwalker

23.19

12/23/2015

1001

Cindy

Deer

10004.95

1/18/2014

·         Write a LINQ query to list and sort items in the list of accounts by Id.

·         Print the query result set.

·         Write a LINQ query to list accounts created before 2014/01/18, order by creation date.

·         Print the query result set.

·         Write a LINQ query to list the first name, last name and balance of accounts order by account balance descending.

·         Print the query result set.

·         Write a LINQ query to Display account Id and creation date ordered by creation date.

·         Print the query result set.


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

Screenshot

Program

using System;
using System.Globalization;
using System.Linq;
namespace LinqQueryUsage
{
    //Create a class Account
    class Account
    {
        //Attributes
        private int id;
        private string firstName;
        private string lastName;
        private double balance;
        private DateTime creationtime;
        //Constructor
        public Account(int id,string fname,string lname,double bal,DateTime t)
        {
            this.id = id;
            firstName = fname;
            lastName = lname;
            balance = bal;
            creationtime = t;
        }
        //Setters and getters
        public int Id { get { return id; } set { id = value; } }
        public string Firstname { get { return firstName; } set { firstName = value; } }
        public string Lastname { get { return lastName; } set { lastName = value; } }
        public double Balance { get { return balance; } set { balance = value; } }
        public DateTime CreationDate { get { return creationtime; } set { creationtime = value; } }
        //Overriding tostring method
        public override string ToString()
        {
            return id+" "+string.Format("{0:20} {1,-10}",firstName, lastName)+" "+balance.ToString("#.##")+"    "+ string.Format("{0:d}",creationtime);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //Create 10 accounts of list
            Account[] accounts = new Account[10];
            accounts[0] = new Account(1006, "John", "Doe", 100,Convert.ToDateTime("1/18/2014", new CultureInfo("en-US")));
            accounts[1] = new Account(1009, "Jane", "Doe", 300, Convert.ToDateTime("1/18/2014", new CultureInfo("en-US")).Date);
            accounts[2] = new Account(1002, "Richard", "Doe",548, Convert.ToDateTime("1/18/2015", new CultureInfo("en-US")).Date);
            accounts[3] = new Account(1003, "John", "Deer", 28, Convert.ToDateTime("3/18/2014", new CultureInfo("en-US")).Date);
            accounts[4] = new Account(1004, "Bob", "Reindeer",396, Convert.ToDateTime("1/22/2016", new CultureInfo("en-US")).Date);
            accounts[5] = new Account(1005, "Patricia", "Rabbit",1532.72, Convert.ToDateTime("7/8/2013", new CultureInfo("en-US")).Date);
            accounts[6] = new Account(1000, "Bill", "Rabbit", 152, Convert.ToDateTime("6/28/2013", new CultureInfo("en-US")).Date);
            accounts[7] = new Account(1007, "Steve", "Bear",768, Convert.ToDateTime("9/18/2015", new CultureInfo("en-US")).Date);
            accounts[8] = new Account(1008, "Rita", "Slowwalker", 23.19, Convert.ToDateTime("12/23/2015", new CultureInfo("en-US")).Date);
            accounts[9] = new Account(1001, "Cindy", "Deer", 10004.95, Convert.ToDateTime("1/18/2014", new CultureInfo("en-US")).Date);
            //Write a LINQ query to list and sort items in the list of accounts by Id.
            var sorted = from account in accounts
                       orderby account.Id
                       select account;
            //Print
            Console.WriteLine("Display sorted using ID:");
            foreach (var account in sorted)
                Console.WriteLine(account);
            //Write a LINQ query to list accounts created before 2014/01/18, order by creation date.
            sorted = from acc in accounts
                     where acc.CreationDate<Convert.ToDateTime("2014/01/18", new CultureInfo("en-US")).Date
                     orderby acc.CreationDate
                     select acc;
            //Print
            Console.WriteLine("\nDisplay sorted using creation date less than 2014/01/18:");
            foreach (var account in sorted)
                Console.WriteLine(account);
            //Write a LINQ query to list the first name, last name and balance of accounts
            //order by account balance descending.
            sorted = from account in accounts
                     orderby account.Balance descending
                     select account;
            //Print
            Console.WriteLine("\nDisplay sorted using balance descending:") ;
            foreach (var account in sorted)
                Console.WriteLine(account.Firstname+" "+account.Lastname+" "+account.Balance.ToString("#.##"));
            //Write a LINQ query to Display account Id and creation date ordered by creation date.
            sorted = from account in accounts
                     orderby account.CreationDate
                     select account;
            //Print
            Console.WriteLine("\n\nDisplay sorted using creation date:");
            foreach (var account in sorted)
                Console.WriteLine(account.Id + " " + account.CreationDate);
        }
    }
}

Output

Display sorted using ID:
1000 Bill Rabbit      152    28-06-2013
1001 Cindy Deer        10004.95    18-01-2014
1002 Richard Doe         548    18-01-2015
1003 John Deer        28    18-03-2014
1004 Bob Reindeer    396    22-01-2016
1005 Patricia Rabbit      1532.72    08-07-2013
1006 John Doe         100    18-01-2014
1007 Steve Bear        768    18-09-2015
1008 Rita Slowwalker 23.19    23-12-2015
1009 Jane Doe         300    18-01-2014

Display sorted using creation date less than 2014/01/18:
1000 Bill Rabbit      152    28-06-2013
1005 Patricia Rabbit      1532.72    08-07-2013

Display sorted using balance descending:
Cindy Deer 10004.95
Patricia Rabbit 1532.72
Steve Bear 768
Richard Doe 548
Bob Reindeer 396
Jane Doe 300
Bill Rabbit 152
John Doe 100
John Deer 28
Rita Slowwalker 23.19


Display sorted using creation date:
1000 28-06-2013 00:00:00
1005 08-07-2013 00:00:00
1006 18-01-2014 00:00:00
1009 18-01-2014 00:00:00
1001 18-01-2014 00:00:00
1003 18-03-2014 00:00:00
1002 18-01-2015 00:00:00
1007 18-09-2015 00:00:00
1008 23-12-2015 00:00:00
1004 22-01-2016 00:00:00

Add a comment
Know the answer?
Add Answer to:
the language i wan used in C# is visual basic.Create a console program that contains the...
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# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employee...

    C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...

  • (Enable the Account class comparable & cloneable) @ Create ComparableAccount class inheritanc...

    (Enable the Account class comparable & cloneable) @ Create ComparableAccount class inheritance from the Account class, and implemented the comparable and cloneable interfaces. Override the compareTo method to compare the balance of two accounts. Print the Account ID, balance and dataCreated information from the toString() method. Implements the cloneable interface and override the clone method to perform a deep copy on the dateCreated field. Write a driver program to create one array contains 5 ComparableAcccount objects (account #: 1001-1005, initial...

  • C++ really need help I will rate you well promise Write a program that will use...

    C++ really need help I will rate you well promise Write a program that will use a linked list to hold the following information: Date (int), Time (int), TZ (string), Size (Int) and Name (string) Follow the guidelines below: Records should be read from a file by the main program. And content should be stored in the doubly linked list or single linked list. After that, you can print separately dates or times or names ... or print hole line  ...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Hi, So I have a finished class for the most part aside of the toFile method...

    Hi, So I have a finished class for the most part aside of the toFile method that takes a file absolute path +file name and writes to that file. I'd like to write everything that is in my run method also the toFile method. (They are the last two methods in the class). When I write to the file this is what I get. Instead of the desired That I get to my counsel. I am having trouble writing my...

  • You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

    You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID                       a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...

  • answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a cl...

    answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relationship among classes because an ATM can contain many Accounts. You will need to reuse/modify the Account class you created in Assignment 10. The default constructor for the ATM class should initialize a private vector of 10 accounts, each with...

  • The code should work exactly the same as given example. The files: ---------------------------------------------------...

    The code should work exactly the same as given example. The files: ---------------------------------------------------------------------------------------------------- -------- FILE NAME ------- album0 ---------- FILE ------- <album> 323 Licensed to Ill Beastie Boys 25.0 </album> <album> 70 Enter the Wu_Tang: 36 Cham... Wu Tang Clan 25.99 </album> turning to Alice, she went on, `What's your name, child?' and there stood the Queen in front of them, with her arms folded, <album> 115 Daydream Nation Sonic Youth 5.0 </album> <album> 414 52nd Street Billy Joel 25.75...

  • Write a program that can read XML files for customer accounts receivable, such as <ar>        <customerAccounts>...

    Write a program that can read XML files for customer accounts receivable, such as <ar>        <customerAccounts>               <customerAccount>                       <name>Apple County Grocery</name>                       <accountNumber>1001</accountNumber>                       <balance>1565.99</balance>               </customerAccount>               <customerAccount>                       <name>Uptown Grill</name>                       <accountNumber>1002</accountNumber>                       <balance>875.20</balance>               </customerAccount>        </customerAccounts>        <transactions>               <payment>                       <accountNumber>1002</accountNumber>                       <amount>875.20</amount>               </payment>               <purchase>                       <accountNumber>1002</accountNumber>                       <amount>400.00</amount>               </purchase>               <purchase>                       <accountNumber>1001</accountNumber>                       <amount>99.99</amount>               </purchase>               <payment>                       <accountNumber>1001</accountNumber>                       <amount>1465.98</amount>               </payment>        </transactions>     </ar> Your program should construct an CustomerAccountsParser object, parse the XML data & create new CustomerAccount objects in the CustomerAccountsParser for each of the products the XML data, execute all of...

  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

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