ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 22 May 2017 My Price 9.00

public class Service1 : IService1

public class Service1 : IService1

{

public List books = new List();//All book information

public static string path = @"C:UsersHPDesktop7204assignmentassignment3books.txt";//path of book.txt

public List GetAllBooks()

//This operation reads all books information from file books.txt (Download from Blackboard) and returns a list of books.

{

books = new List();

FileStream file1 = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);

StreamReader a = new StreamReader(file1);

String line = "";

int i = 0;

a = new StreamReader(file1);

i = 0;

Book last = new Book();

String[] str = new String[6];

try

{

while ((line = a.ReadLine()) != null)//read txt

{

str = new String[6];

str = line.Split(',');

last = new Book();

last.id = str[0];

last.Name = str[1];

last.Author = str[2];

last.Year = int.Parse(str[3]);

last.Price = float.Parse(str[4].Substring(1));

last.Stock = int.Parse(str[5]);

books.Add(last);

i++;

}

}

catch (Exception)

{

 

}

a.Close();

file1.Close();

return books;

}

public Boolean AddBook(Book a)

///This operation receives the information of a book and creates an instance of class

///Book, then add this book into existing book list and save into file books.txt. If the

///operation succeeds to add a book into the book list and save to file, it returns true.

///Otherwise it returns false.

{

int n;

n = books.FindIndex(s => s.id == a.id);

if ((n == -1) & (a.Author != "") & (a.id != "") & (a.Name != "") & (a.Year > 1970) & (a.Year 0) & (a.Stock > 0))

{

books.Add(a);

FileStream file2 = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);

StreamWriter b = new StreamWriter(file2);

for (int i = 0; i {

string str = books[i].id + "," + books[i].Name + "," + books[i].Author + "," + books[i].Year.ToString() + ",$" + books[i].Price.ToString() + "," + books[i].Stock.ToString();

b.WriteLine(str);

}

b.Close();

file2.Close();

return true;

}

else

{

return false;

}

}

 

 

i dont understand what the 'S' is, in "s.id=a.id”, it desnot claim a "s"  before , right? so how itcan  judge s.id=a.id ?. and what the "n==-1" means?  could someone explain this code for me?

Answers

(11)
Status NEW Posted 22 May 2017 02:05 AM My Price 9.00

-----------

Attachments

file 1495420378-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)