public static void WriteToTxtFile(SimpleCar car) { const string filePath = "@//..//..//..//data//AddCars.txt"; StreamWriter w = new StreamWriter(filePath, true); w.WriteLine(car.Model + "\t" + car.Fuel + "\t" + car.Expense + "\t" + car.Price + "\t" + car._countofdoors); w.Close(); }
public static SimpleCar AddNewSimpleCar() { Console.WriteLine("Enter parameters for the new Simple Car:"); Console.WriteLine("model: "); string sname = Convert.ToString(Console.ReadLine()); Console.WriteLine("how many doors: "); double sdoors = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("fuel: "); string stank = Convert.ToString(Console.ReadLine()); Console.WriteLine("fuel expense per km: "); int sfuelExpense = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("price: "); int stotalPrice = Convert.ToInt32(Console.ReadLine()); var newCar = new SimpleCar(sdoors, sname, stank, sfuelExpense, stotalPrice); SimpleCar.WriteToTxtFile(newCar); return newCar; }
private static void WriteJsonFile(SimpleCar car) { //Serialize Car object to Json string jsonCar = JsonConvert.SerializeObject(car); using (StreamWriter f = File.CreateText("D:\\helloci\\HomeTask2\\HomeTask2\\data\\AddJsonCar.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(f, jsonCar); } Console.WriteLine(jsonCar); }
private static void AddJsonFile() { Console.WriteLine("Enter parameters for the new Simple Car:"); Console.WriteLine("model: "); string sname = Convert.ToString(Console.ReadLine()); Console.WriteLine("how many doors: "); double sdoors = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("fuel: "); string stank = Convert.ToString(Console.ReadLine()); Console.WriteLine("fuel expense per km: "); int sfuelExpense = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("price: "); int stotalPrice = Convert.ToInt32(Console.ReadLine()); var newCar = new SimpleCar(sdoors, sname, stank, sfuelExpense, stotalPrice); WriteJsonFile(newCar); }