final lab Flashcards
the first step of every class you make:
identify the attributes (ex: private String name;)
the Scanner is used in the _____ class
main public class
how to make a getter? [what are the two steps] (ex: for private string attribute name for class trainee)
public String getName(){ //(step 1: make a PUBLIC method)
return name; //(step 2: use RETURN to return the wanted private value.)
}
what does a getter method do?
a getter method returns its value.
what does a setter method do?
sets or updates its value.
how do we declare/call out a private value?
using a getter
where do we create the getter and setter method?
in the same class the attribute is identified
the (setter/getter) method is always void.
setter
how to make a setter?
public class Vehicle {
private String color;
public void setColor(String c) {
this.color = c;
}
}
steps of making a parameterized constuctor:
1 - intialization for each value/attribute in the constructor (using <this> method or etc)</this>
when to use <this> method?</this>
when intializing a value that has the same name as an attribute in the class
when to use <this> method?</this>
when intializing a value that has the same name as an attribute in the class
write the code for f2 using method display()
f2.display();
(bs it’s that easy)
t/f: there is no variable type for a parameterized constructor.
true (ex: public Author(String n, String em, String gen){})
write a statement to intialize String gender as char gen.
Gender = gen.charAt(0);
write the statement for char input
char ch = input.next().charAt(0);
write the statement for char input
char ch = input.next().charAt(0);
write a statement to update a private value with the input given from the user:
obj1.setOrderName(input.nextLine());
T/F: we initialize a static attribute in the declaration state.
true. DONT FORGET TO
in a switch code, where do we put the “wrong entry” statement?
in the default:
what’s the math method for Pi?
Math.PI
what’s the math method for to the power/
Math.pow(variable name, number to the power of)
if the method or attribute in the UML is underlined then that means….
it is static
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)
Shape.getShapeCounter();
(so remember it’s easy just type in the name of the class not the object of the class)