CSF2 Flashcards

32
Q

What are characteristics of the datatype DateTime?

A

- 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What does a complex datatype need?

A

Complex data types often need the NEW keyword and
a constructor method, which has the same name as the data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What’s the syntax for DateTime?

…and what format specificers can be used with DateTime?

A

DateTime x= new DateTime();

You can use format specificers on DateTime.
(t, T, d, D, f, F)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

How do you explore an object with intellisense?

A

…using a period

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

How do you determine the current date?

A

DateTime.Today

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

How do you determine the current date AND time?

A

DateTime.Now

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

How do you explore a method with intellisense?

A

Use an open paren (

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Random myRandomNbr = new Random();

int myNextRandomNbr = myRandomNbr.Next(5, 11);
Console.WriteLine(“Number between 5-10: “ +
myNextRandomNbr);

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Is Random a complex or instrinsic data type?

A

**is a complex and requires a the NEW keyword **

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What’s happening here…

** int nbr0and20 = randomNbrGen.Next(21);
Console.WriteLine(“A number between 0-20 is “+ nbr0and20);**

A

a random number is output less than 21

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What’s this doing…

** int Nbr50and105 = randomNbrGen.Next(50, 106);
Console.WriteLine(“A number between 50-105 is “ + Nbr50and105);**

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

How are METHODS OUTSIDE the class, but INSIDE the project, called?

A

ClassName.MethodName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

How is the console cleared?

A

Console.Clear();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

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);

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

What is Random?

A

** 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.**

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

What is the difference between a static method and an instance method?

A

???

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Give 3 examples of static methods…

A

int.Parse();

Console.ReadLine();

Console.WriteLine();

49
Q

Give 3 examples of an instance method.

A

whereas ToUpper()., ToLower()., AddDays()

**all require an **

INSTANCE or variable of the datatype to call them.

50
Q

** Console.ForegroundColor = ConsoleColor.Yellow;**

A
51
Q

How do you reset colors in a console program

A

Console.ResetColor();

52
Q

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");
A
53
Q

What’s happening here:

Volunteer v1 = new Volunteer();

A

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

54
Q

If you do not define a constructor in the class file, what happens?

A

you get a free one with no parameters

55
Q

What’s happening here…

Volunteer v1 = new Volunteer();

  • *v1._name = “Spider Man”;
    v1. _isActive = true;
    v1. _yearsOfService = 12;**
A

Volunteer is a complex data…meaning there is a Volunteer.cs file

the variables initialized are datatypes from the Volunteer.cs file

56
Q

Console.WriteLine(“{0} has volunteered for {1} years.\n”
+ “Still Active? {2}\n”,
v1._name, v1._yearsOfService, v1._isActive);

A
57
Q

Volunteer v2 = new Volunteer();
v2._name = “Iron Man”;
v2._isActive = true;
v2._yearsOfService = 5;
Console.WriteLine(“{0} has volunteered for {1} years.\n”
+ “Still Active? {2}”,
v2._name, v2._yearsOfService, v2._isActive);

A
58
Q

What 4 things makeup a dataytype class and what letter casing must they be in?

A

fields (camelCase) …for parameters

properites (PascalCase) …for how outside files will use the data

constructors (ClassName is PascalCase and parameter is camelCase) …a specialized method within a class definition that let’s you create objects from the class

methods …performs some action or block of code when called

59
Q

What is “call a method”

A

calling a method to perform its action, passing whatever arguments are needed to be used as parameters

60
Q

What is this…

** public override string ToString()
{**
** return string.Format(“{0}\t\tSalary: {1:c}\n”**
** + “Hired: {2:d}\nPaid Bi-Weekly?: {3}\n”
+ “Exmployer: {4}\t\tfounded {5:d}\n”,
Name, Salary, DateOfHire, IsPaidBiWeekly, Employer.Name, Employer.DateFounded);
}**

A
61
Q

What represents the info that can be stored for an object of this type?

A

fields

62
Q

For a datatype class, are fields public or private?

A

private

63
Q

What do properties do?

A

encapsulate or protect fields;

controls access to getting or setting info within the fields

64
Q

Are properties public or private?

A

public

65
Q

What does the keyword value do?

A

it represents whatever value that is trying to be set to a field

66
Q

Whata is this an example of:

**public DateTime DateFounded
{
get { return _dateFounded; } //get…allows program to get data
set { _dateFounded = value;
} **

A
67
Q

What does get and set do?

A

get and set are part of the scope of a variable;

get allows a program to get data

set allows a program to set or put data in

68
Q

What are constructors a.k.a. ctors?

A

Constructors are specialized methods to create objects of this type; they are called with the new keyword.

The constrcutor method always has the same name as the data type where it’s defined.

NO return type is listed in a constructor’s method

Note: this is what is ultimately displayed in intellisense

69
Q

What’s the sytax for a constrcutor?

A

public className(datatype name, …)

{

Property = parameter

}

70
Q

What’s missing here…

**
return string.Format(“\nOrganization: {0}\nRevenue:
{1:c}\n”
+ “Is not for profit?: {2}\nDate Founded: {3:d}”,
Name, Revenue, IsNotForProfit, DateFounded);
}**

A
**        public override string ToString()
         {
             //return base.ToString();
             //the base.ToString() gives us namespace.class which is
             //NOT what we want
             return string.Format("\nOrganization: {0}\nRevenue: {1:c}\n"
                 \+ "Is not for profit?: {2}\nDate Founded: {3:d}",
                 Name, Revenue, IsNotForProfit, DateFounded);
         }//end ToString**
71
Q

** public string _name;
public bool _isActive;
public int _yearsOfService;**

A
72
Q

How should parameters be named?

A

underscore camelCase

_name

73
Q

…CSF2 …3Wed …MoreCollections

A