Student myStudent = new Student("Baxter", 1);
What is the correct way to implement an array "x" that will hold 17 integer values?
int x = new int[17]
Write a no argument constructor for the Burger class that sets the values of its two instance variables, integer cals and double price to default values.
public Burger(){
price = 10.50;
cals = 0;
}
Write an enhanced for loop to traverse through an ArrayList of Strings named myStrings and print out each element.
for(String x : myStrings){
System.out.println(x);
}
Write two overloaded methods that could be added to the same class as the following method:
public void mystery(int x){}
public void mystery(String x)
public void mystery(double y)
public void mystery(int x, int y)
Write the class header for the clubOfficer class that is a subclass of the clubMember class.
for(int i = 0; i < genshinCharacters.length; i++){
if(genshinCharacter[i].substring(0,1).equals("T")){
filterNames.add(genshinCharacter[i])
}}
Write the class header and constructor for the Painter class. The Painter class had four instance variables. Paint, Direction, X, and Y Location.
public class Painter{
private int paint;
private int x;
private int y;
private String direction;
public Painter(int p, String dir, int x, int y){
}
}
Given the String array, fantasyNames, write a method to search through the array to find the names beginning with an "A" or ending with "a". Print out the names.
for(int i = 0; i < fantasyNames.length; i++){
if(fantasyNames[i].substring(0,1).equals("A") || fantasyNames[i].substring(fantasyNames[i].length).equals("a"){
System.out.print(fantasyNames[i]);
}
}
What will be returned by the call mystery(3, 2, 6)?
public int mystery(int n, int a, int d){
if( n == 1){
return a;
} else{
return d + mystery(n-1, a, d);
}
}
14
Create a method that removes all the odd numbers from an ArrayList of integers. The ArrayList name is myNumbers.
for(int i = 0; i < myNumbers.size(); i++){
if(myNumbers.get(i) % 2 != 0){
myNumbers.remove(i);
i--;
}