CSF2 Flashcards
What are characteristics of the datatype DateTime?
- it’s a datatype from the FCL (framework class library)
- used to create variables that hold date and time info
- time defaults to 12am
- it’s a complex data type, unlike strings, ints, etc…which are all intrinsic data types
What does a complex datatype need?
Complex data types often need the NEW keyword and
a constructor method, which has the same name as the data type.
What’s the syntax for DateTime?
…and what format specificers can be used with DateTime?
DateTime x= new DateTime();
You can use format specificers on DateTime.
(t, T, d, D, f, F)
How do you explore an object with intellisense?
…using a period
How do you determine the current date?
DateTime.Today
How do you determine the current date AND time?
DateTime.Now
How do you explore a method with intellisense?
Use an open paren (
Random myRandomNbr = new Random();
int myNextRandomNbr = myRandomNbr.Next(5, 11);
Console.WriteLine(“Number between 5-10: “ +
myNextRandomNbr);
Is Random a complex or instrinsic data type?
**is a complex and requires a the NEW keyword **
What’s happening here…
** int nbr0and20 = randomNbrGen.Next(21);
Console.WriteLine(“A number between 0-20 is “+ nbr0and20);**
a random number is output less than 21
What’s this doing…
** int Nbr50and105 = randomNbrGen.Next(50, 106);
Console.WriteLine(“A number between 50-105 is “ + Nbr50and105);**
How are METHODS OUTSIDE the class, but INSIDE the project, called?
ClassName.MethodName
How is the console cleared?
Console.Clear();
bool exit = false; //COUNTER
do { Console.WriteLine("\nPlease choose a program\n" \+ "(B) Break Change\n" \+ "(W) Water Weight\n" \+ "(N) Numbers\n" \+ "(T) Display Time\n" \+ "(C) Calendar App\n" \+ "(X) Exit");
string choice = Console.ReadLine().ToUpper();
Console.Clear();
switch (choice) { case "B": Console.WriteLine("Break Change"); BreakChange(); break; case "W": Console.WriteLine("Water Weight"); WaterWeight(); break; case "N": Console.WriteLine("Numbers"); CountNumbers(); break; case "T": Console.WriteLine("Display Time"); DateTimeWarehouse.DisplayTime(); break; case "C": Console.WriteLine("Calendar App");
Console.WriteLine(“Please type a number of days from today to display”);
int userDays = int.Parse(Console.ReadLine()); DateTime newDate = DateTimeWarehouse.CalculateDate(userDays);
DateTimeWarehouse.DisplayTime(newDate);
break;
case "X": Console.WriteLine("Thank you for using the program"); exit = true; break; default: Console.WriteLine("Input not recognized. Please try again."); break; }//end switch
} while (!exit);
bool exit = false; //COUNTER
do { //print menu Console.WriteLine("\nPlease choose a program\n" \+ "(B) Break Change\n" \+ "(W) Water Weight\n" \+ "(N) Numbers\n" \+ "(T) Display Time\n" \+ "(C) Calendar App\n" \+ "(X) Exit");
string choice = Console.ReadLine().ToUpper(); Console.Clear();//clears the console of the previous display //BEST USED AFTER ReadLine() don't do this BEFORE or they //will never see the menu...
switch (choice) { case "B": Console.WriteLine("Break Change"); BreakChange(); break; case "W": Console.WriteLine("Water Weight"); WaterWeight(); break; case "N": Console.WriteLine("Numbers"); CountNumbers(); break; case "T": Console.WriteLine("Display Time"); DateTimeWarehouse.DisplayTime(); break; case "C": Console.WriteLine("Calendar App");
//print out today's date for now, we will come //back and figure out a calculated date next //DateTimeWarehouse.DisplayTime(DateTime.Now); Console.WriteLine("Please type a number of days from today to display"); int userDays = int.Parse(Console.ReadLine()); //ask the user for a number of days
//use the calculate date method DateTime newDate = DateTimeWarehouse.CalculateDate(userDays);
//print the calculated date with our custom format DateTimeWarehouse.DisplayTime(newDate); break;
case "X": Console.WriteLine("Thank you for using the program"); exit = true; break; default: Console.WriteLine("Input not recognized. Please try again."); break; }//end switch
//} while (exit == false); //revere logic } while (!exit); //see !...think not since the CONDITION needs a TRUE statement //the ! merely states that it should look for a NOT TRUE
What is Random?
** Random is a class in the FCL
(Framework Class Library).
* It has an instance method, Next() which generates the “next”
* random number in a desired range if specified.**
What is the difference between a static method and an instance method?
???