chapter 3 -revisited Flashcards

1
Q

what is a class?

A

blueprint of an object

defines the variables and methods an object contains.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
what are the parts of the following line of code (class, etc):
Scanner scan = new Scanner(System.in);
A

Scanner scan = new Scanner(System.in);
__________________________________
Scanner – is the class and the blue print for objects.
scan – is an object being created/
new – is a java operator that is the creator of a new object.
Scanner – this is a constructor and part of the Scanner class.
( )— used after the Scanner as part of its constructor to set the parameters that must be used.
(System.in) — parameters used represents input from the keyboard.

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

if i wanted to create a second scanner object with the same functionality as the first then how would i and what is this called?

A

Scanner scan2;
^ is a deceleration in itself.
scan2 = scan;
^^ both are the same in functionality.
Aliases of one another: 2 ways to get to the same object.
“when multiple reference variables refer to the same object”.

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

if i wanted to create a second scanner object but have it scan from a different input such as a file then how would i do this?

A
scan2 = new Scanner(new File ("myData.txt"));
here a new object called scan2 is created and it uses the constructor with parameters that scans in data from a specific file.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a constructor?

A

constructor:

a method that sets up a newly created object used to give an initial value to a variable.

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

how to create a random object for generation of random numbers? (random class)

A
Random generating = new Random();
generating is the object name that we set for random
import java.util.random;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

int num1 = generating.nextInt(300);

what will this do?

A

will return a random number in the range between 0 and 299.

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

what code is written to create a random number between 0 and 6?

A

int num2 = generating.nextINT(5) + 1;

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

what range will the following code give me?

int num3 = generating.nextInt(20) - 10;

A

int num3 = generating.nextInt(20) - 10;
will produce a range of: -10 and 9
**the (20) produces a range of 0 through 19 then we add the -10 for the final range.

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

are math class methods static or do we use objects to invoke methods of the math class?

A
math class methods are static.
so what this means:
int num4 = Math.cos(30);
                        ^^ this object was not created by me b/c it is static with the math class and already made.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is the math function to raise a number to a power?

A

int squared = Math.pow(a, 2);

^ object name ^ a represents the number while 2 represents the exponent (power being raised to)

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

The math function uses what type of input? integer, double, float, String?

A

Math function always uses a double so do not assign anything else with it otherwise you will have errors.

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