13. What is the output of the following program?(1 point) int sum = 0, k, val =
ID: 3810104 • Letter: 1
Question
13.
What is the output of the following program?(1 point)
int sum = 0, k, val = 1;
for (k = 0; k <=4; k++)
{
sum += val;
val++;
}
System.out.println(sum);
Question 13 options:
14.
The purpose of a class constructor is to (1 point)
Question 14 options:
15.
When is it not necessary to invoke method myMethod using dot notation? (1 point)
Question 15 options:
16.
What is a mutator method? (1 point)
Question 16 options:
17.
What is the output of the following code?(1 point)
ArrayList<Integer> grades = new ArrayList<Integer>();
grades.add(88);
grades.add(92);
grades.add(95);
grades.add(1, 80);
grades.add(83);
System.out.println(grades.get(2 + 3 / 2));
Question 17 options:
18.
Consider the following class designed to store weather statistics at a particular date and time.
public class WeatherSnapshot
{
private int tempInFahrenheit;
private int humidity; // value of 56 means 56% humidity
private int dewpoint; // in degrees Fahrenheit
private Date date; // uses a Date object to store the date
private int time; // in military time, such as 1430 = 2:30 pm
private boolean cloudy; // true if 25% or more of the sky is covered
// constructor not shown, but it initializes all instance variables
// postcondition: returns temperature
public int getTemp()
{
return tempInFahrenheit;
}
// postcondition: returns date
public Date getDate()
{
return date;
}
// postcondition: returns true if precipitation is likely; false otherwise
public boolean precipitationLikely()
{
// implementation not shown
}
// other methods not shown
}
Which of the following is a class constructor? (1 point)
I. getTemp
II. precipitationLikely
III. WeatherSnapshot
Question 18 options:
19.
Consider the following class designed to store weather statistics at a particular date and time.
public class WeatherSnapshot
{
private int tempInFahrenheit;
private int humidity; // value of 56 means 56% humidity
private int dewpoint; // in degrees Fahrenheit
private Date date; // uses a Date object to store the date
private int time; // in military time, such as 1430 = 2:30 pm
private boolean cloudy; // true if 25% or more of the sky is covered
// constructor not shown, but it initializes all instance variables
// postcondition: returns temperature
public int getTemp()
{
return tempInFahrenheit;
}
// postcondition: returns date
public Date getDate()
{
return date;
}
// postcondition: returns true if precipitation is likely; false otherwise
public boolean precipitationLikely()
{
// implementation not shown
}
// other methods not shown
}
Suppose a WeatherSnapshot object named currentWeather has been correctly instantiated in a client class. Which of the following will correctly call the precipitationLikely method? (1 point)
Question 19 options:
20.
What is meant by the term "encapsulation"? (1 point)
Question 20 options:
21.
What is output by the following code fragment?(1 point)
String[] fruits = { "apple", "banana", "peach", "strawberry" };
String str = "a";
for (String item : fruits)
{
str += item.substring(1, 2);
}
System.out.println(str);
Question 21 options:
22.
Consider the following code segment. What would be the expected output?(1 point)
int i = 10;
while (i >= 0)
{
if ((i % 2) > 0)
{
System.out.print(i + " ");
}
i -= 2;
}
Question 22 options:
23.
Assume that the following code exists inside a method of MyClass, and that this code compiles without errors:
int result = book.getYearPublished();
where book is an object of the Book class.
Which of the following is not true about the getYearPublished method?(1 point)
I. It is a mutator method.
II. It is a public method in the Book class.
III. It returns a String.
Question 23 options:
24.
What does the decimal number 207 equal in the hexadecimal system? (1 point)
Question 24 options:
1) 15 2) 28 3) 16 4) 10 5) 21Explanation / Answer
13.
What is the output of the following program?(1 point)
int sum = 0, k, val = 1;
for (k = 0; k <=4; k++)
{
sum += val;
val++;
}
System.out.println(sum);
answer:
option 1)15
14.The purpose of a class constructor is to
answer:
Option 1)initialize the class instance variables.
15.When is it not necessary to invoke method myMethod using dot notation?
answer:
option 2)When myMethod is invoked by a method in the same class as myMethod.
16.What is a mutator method?
Answer:
option 2)
A method that modifies an instance variable.
17.What is the output of the following code?(1 point)
ArrayList<Integer> grades = new ArrayList<Integer>();
grades.add(88);
grades.add(92);
grades.add(95);
grades.add(1, 80);
grades.add(83);
System.out.println(grades.get(2 + 3 / 2));
Answer:
option 5)95
18.
Consider the following class designed to store weather statistics at a particular date and time.
public class WeatherSnapshot
{
private int tempInFahrenheit;
private int humidity; // value of 56 means 56% humidity
private int dewpoint; // in degrees Fahrenheit
private Date date; // uses a Date object to store the date
private int time; // in military time, such as 1430 = 2:30 pm
private boolean cloudy; // true if 25% or more of the sky is covered
// constructor not shown, but it initializes all instance variables
// postcondition: returns temperature
public int getTemp()
{
return tempInFahrenheit;
}
// postcondition: returns date
public Date getDate()
{
return date;
}
// postcondition: returns true if precipitation is likely; false otherwise
public boolean precipitationLikely()
{
// implementation not shown
}
// other methods not shown
}
Which of the following is a class constructor? (1 point)
I. getTemp
II. precipitationLikely
III. WeatherSnapshot
Answer:
Option 5)III only
19. Consider the following class designed to store weather statistics at a particular date and time.
public class WeatherSnapshot
{
private int tempInFahrenheit;
private int humidity; // value of 56 means 56% humidity
private int dewpoint; // in degrees Fahrenheit
private Date date; // uses a Date object to store the date
private int time; // in military time, such as 1430 = 2:30 pm
private boolean cloudy; // true if 25% or more of the sky is covered
// constructor not shown, but it initializes all instance variables
// postcondition: returns temperature
public int getTemp()
{
return tempInFahrenheit;
}
// postcondition: returns date
public Date getDate()
{
return date;
}
// postcondition: returns true if precipitation is likely; false otherwise
public boolean precipitationLikely()
{
// implementation not shown
}
// other methods not shown
}
Suppose a WeatherSnapshot object named currentWeather has been correctly instantiated in a client class. Which of the following will correctly call the precipitationLikely method?
Answer:
Option 2)
20.What is meant by the term "encapsulation"?
Answer:
Option 4)Encapsulation occurs when instance variables are declared as private.
21.What is output by the following code fragment?(1 point)
String[] fruits = { "apple", "banana", "peach", "strawberry" };
String str = "a";
for (String item : fruits)
{
str += item.substring(1, 2);
}
System.out.println(str);
Answer:
Option 3)apaet
22.
Consider the following code segment. What would be the expected output?(1 point)
int i = 10;
while (i >= 0)
{
if ((i % 2) > 0)
{
System.out.print(i + " ");
}
i -= 2;
}
Answer:
Option 5)nothing is printed
23.
Assume that the following code exists inside a method of MyClass, and that this code compiles without errors:
int result = book.getYearPublished();
where book is an object of the Book class.
Which of the following is not true about the getYearPublished method?(1 point)
I. It is a mutator method.
II. It is a public method in the Book class.
III. It returns a String.
Answer:
Option 3)III only
24.What does the decimal number 207 equal in the hexadecimal system?
Answer:
Option 1)CF
A method that modifies an instance variable.
17.What is the output of the following code?(1 point)
ArrayList<Integer> grades = new ArrayList<Integer>();
grades.add(88);
grades.add(92);
grades.add(95);
grades.add(1, 80);
grades.add(83);
System.out.println(grades.get(2 + 3 / 2));
Answer:
option 5)95
18.
Consider the following class designed to store weather statistics at a particular date and time.
public class WeatherSnapshot
{
private int tempInFahrenheit;
private int humidity; // value of 56 means 56% humidity
private int dewpoint; // in degrees Fahrenheit
private Date date; // uses a Date object to store the date
private int time; // in military time, such as 1430 = 2:30 pm
private boolean cloudy; // true if 25% or more of the sky is covered
// constructor not shown, but it initializes all instance variables
// postcondition: returns temperature
public int getTemp()
{
return tempInFahrenheit;
}
// postcondition: returns date
public Date getDate()
{
return date;
}
// postcondition: returns true if precipitation is likely; false otherwise
public boolean precipitationLikely()
{
// implementation not shown
}
// other methods not shown
}
Which of the following is a class constructor? (1 point)
I. getTemp
II. precipitationLikely
III. WeatherSnapshot
Answer:
Option 5)III only
19. Consider the following class designed to store weather statistics at a particular date and time.
public class WeatherSnapshot
{
private int tempInFahrenheit;
private int humidity; // value of 56 means 56% humidity
private int dewpoint; // in degrees Fahrenheit
private Date date; // uses a Date object to store the date
private int time; // in military time, such as 1430 = 2:30 pm
private boolean cloudy; // true if 25% or more of the sky is covered
// constructor not shown, but it initializes all instance variables
// postcondition: returns temperature
public int getTemp()
{
return tempInFahrenheit;
}
// postcondition: returns date
public Date getDate()
{
return date;
}
// postcondition: returns true if precipitation is likely; false otherwise
public boolean precipitationLikely()
{
// implementation not shown
}
// other methods not shown
}
Suppose a WeatherSnapshot object named currentWeather has been correctly instantiated in a client class. Which of the following will correctly call the precipitationLikely method?
Answer:
Option 2)
boolean couldRain = currentWeather.precipitationLikely();20.What is meant by the term "encapsulation"?
Answer:
Option 4)Encapsulation occurs when instance variables are declared as private.
21.What is output by the following code fragment?(1 point)
String[] fruits = { "apple", "banana", "peach", "strawberry" };
String str = "a";
for (String item : fruits)
{
str += item.substring(1, 2);
}
System.out.println(str);
Answer:
Option 3)apaet
22.
Consider the following code segment. What would be the expected output?(1 point)
int i = 10;
while (i >= 0)
{
if ((i % 2) > 0)
{
System.out.print(i + " ");
}
i -= 2;
}
Answer:
Option 5)nothing is printed
23.
Assume that the following code exists inside a method of MyClass, and that this code compiles without errors:
int result = book.getYearPublished();
where book is an object of the Book class.
Which of the following is not true about the getYearPublished method?(1 point)
I. It is a mutator method.
II. It is a public method in the Book class.
III. It returns a String.
Answer:
Option 3)III only
24.What does the decimal number 207 equal in the hexadecimal system?
Answer:
Option 1)CF
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.