CSF2 Flashcards
(42 cards)
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?
???
Give 3 examples of static methods…
int.Parse();
Console.ReadLine();
Console.WriteLine();
Give 3 examples of an instance method.
whereas ToUpper()., ToLower()., AddDays()
**all require an **
INSTANCE or variable of the datatype to call them.
** Console.ForegroundColor = ConsoleColor.Yellow;**
How do you reset colors in a console program
Console.ResetColor();
bool colorMenu = true;
do
{
Console.WriteLine(“Pick your text color: Green, Blue,”
+ “ Red, Cyan”);
string textColor = Console.ReadLine().ToLower();
switch (textColor)
{
case “green”:
case “g”:
Console.ForegroundColor = ConsoleColor.Green;
break;
case "blue": case "b": Console.ForegroundColor = ConsoleColor.Blue; break; case "red": case "r": Console.ForegroundColor = ConsoleColor.Red; break; case "cyan": case "c": Console.ForegroundColor = ConsoleColor.Cyan; break; default: Console.WriteLine("Invalid entry. Re-run program!!"); break; }//end switch Console.WriteLine("Here is your text now!\n");
What’s happening here:
Volunteer v1 = new Volunteer();
Volunteer is complex datatype…it’s pulling from the Volunteer.cs file
v1 is the variable to call the code from that file
it requires the use of the NEW keyword
If you do not define a constructor in the class file, what happens?
you get a free one with no parameters
What’s happening here…
Volunteer v1 = new Volunteer();
- *v1._name = “Spider Man”;
v1. _isActive = true;
v1. _yearsOfService = 12;**
Volunteer is a complex data…meaning there is a Volunteer.cs file
the variables initialized are datatypes from the Volunteer.cs file