❔ new to programming and can't figure out
i want to create an appointment scheduler that let's the user create view update and delete but can't figure out how
using System;
using System.Data;
namespace appointment
{
class Program
{
static void Main(string[] args)
{
bool showMenu = true;
while (showMenu)
{
showMenu = Mainmenu();
}
}
private static bool Mainmenu()
{
Console.Clear();
Console.WriteLine("menu");
Console.WriteLine("1 )schedule appointment");
Console.WriteLine("2 )view appointment");
Console.WriteLine("3 )update appointment");
Console.WriteLine("4 )delete appointment");
Console.WriteLine("5 )exit");
Console.Write("\r\nselect an option:");
switch (Console.ReadLine())
{
case "1":
return true;
case "2":
return true;
case "3":
return true;
case "4":
return true;
case "5":
return false;
default:
return true;
}
}
private static void
}
}
27 Replies
ok, but any more details?
where do you want to keep your data?
@divolo more details needed.
Where are you stuck? What have you tried? How do you want to persist (store) your data?
i don't know how to store data the user inputs nor how to let the user delete any changes they want
okay, well, you'll likely want to have a list of appointments in your program, and then save/load that to/from a file on disk as needed
step 1 might be to define what an
Appointment
class looks likelike this?
class appointment
{
public string title;
public string date;
public string time;
public string loation;
}
Something like that, but those are fields and should probably be properties in an idiomatic C# program
like this
public string? Title { get => title; set => title = value; }
public string? Date { get => date; set => date = value; }
public string? Time { get => time; set => time = value; }
public string? Location { get => location; set => location = value; }
should just be able to do
public string? Title { get; set; }
{
internal class Appointment
{
public string? title;
public string? date;
public string? time;
public string? location;
public string Title { get; set; }
public string Date { get; set; }
public string Time { get; set; }
public string? Location { get; set; }
} right?
} right?
don't need all your
public string? title;
public string? Title { get; set; }
public string? Date { get; set; }
public string? Time { get; set; }
public string? Location { get; set; }
or should i delete the ?
you can remove it, but you'll then get a compiler warning, this explains it a bit more and what options you have, but don't worry if it's a bit much right now! https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings#nonnullable-reference-not-initialized
Resolve nullable warnings
Several compiler warnings indicate code that isn't null-safe. Learn how to address those warnings by making your code more resilient.
if you do remove the
?
you'll still be able to carry on with your program without doing anything about it, just that if you then forget to assign a value to one of those properties you'll get an exceptionso if i remove it it won't change anything right?
nothing will "change" exactly, no, you'll see a warning under those lines in visual studio telling you that you haven't given those properties a value
but at that point it's just a warning
so i've defined appointment how do i store what the user inputs in the appointment?
sorry if my english isn't clear english isn't my first language
well you'll have to receive, Read, data from the user, make an Appointment from it, and store it in a file/database/whatever you're using
I recommend making a
public Appointment CreateAppointment()
method that you call from your main menu, and add the returned appointment object to your list of appointments
you'll need to make that function and that listwell
public Appointment CreateAppointment();
is just a method signature, i.e. just the name of the method and what it will return, you haven't created a body for that methodalso, don't declare methods inside other methods like that
and please: $codegif
like this?
something like that
you should add more code in that block thou, to ask for details and fill the object before returning it
im sorry but can you please tell me the steps i should be taking right now
well, it seems to me like you already know how to read and write from/to the console
so how about you do that?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.