final lab Flashcards

1
Q

the first step of every class you make:

A

identify the attributes (ex: private String name;)

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

the Scanner is used in the _____ class

A

main public class

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

how to make a getter? [what are the two steps] (ex: for private string attribute name for class trainee)

A

public String getName(){ //(step 1: make a PUBLIC method)
return name; //(step 2: use RETURN to return the wanted private value.)
}

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

what does a getter method do?

A

a getter method returns its value.

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

what does a setter method do?

A

sets or updates its value.

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

how do we declare/call out a private value?

A

using a getter

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

where do we create the getter and setter method?

A

in the same class the attribute is identified

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

the (setter/getter) method is always void.

A

setter

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

how to make a setter?

A

public class Vehicle {
private String color;

public void setColor(String c) {
this.color = c;
}

}

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

steps of making a parameterized constuctor:

A

1 - intialization for each value/attribute in the constructor (using <this> method or etc)</this>

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

when to use <this> method?</this>

A

when intializing a value that has the same name as an attribute in the class

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

when to use <this> method?</this>

A

when intializing a value that has the same name as an attribute in the class

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

write the code for f2 using method display()

A

f2.display();

(bs it’s that easy)

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

t/f: there is no variable type for a parameterized constructor.

A

true (ex: public Author(String n, String em, String gen){})

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

write a statement to intialize String gender as char gen.

A

Gender = gen.charAt(0);

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

write the statement for char input

A

char ch = input.next().charAt(0);

16
Q

write the statement for char input

A

char ch = input.next().charAt(0);

17
Q

write a statement to update a private value with the input given from the user:

A

obj1.setOrderName(input.nextLine());

18
Q

T/F: we initialize a static attribute in the declaration state.

A

true. DONT FORGET TO

19
Q

in a switch code, where do we put the “wrong entry” statement?

A

in the default:

20
Q

what’s the math method for Pi?

A

Math.PI

21
Q

what’s the math method for to the power/

A

Math.pow(variable name, number to the power of)

22
Q

if the method or attribute in the UML is underlined then that means….

A

it is static

23
Q

Write a statment that prints all the objects create in a class (ex: class Shape)…
(also there exists an attribute called ShapeCounter() which also has a getter in class Shape)

A

Shape.getShapeCounter();
(so remember it’s easy just type in the name of the class not the object of the class)