Question 141
Given:
public class product {
int id; int price;
public Product (int id, int price) {
this.id = id;
this.price = price;
}
public String toString() { return id + ":" + price; }
}
and the code fragment:
List<Product> products = Arrays.asList(new Product(1, 10),
new Product (2, 30),
new Product (2, 30));
Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> {
p1.price+=p2.price;
return new Product (p1.id, p1.price);});
products.add(p);
products.stream().parallel()
. reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)
. ifPresent(System.out: :println);
What is the result?
Question 142
Given the content of /resourses/Message.properties:
welcome1="Good day!"
and given the code fragment:
Properties prop = new Properties ();
FileInputStream fis = new FileInputStream ("/resources/Message.properties"); prop.load(fis); System.out.println(prop.getProperty("welcome1")); System.out.println(prop.getProperty("welcome2", "Test"));//line n1 System.out.println(prop.getProperty("welcome3")); What is the result?
Question 143
Given the content of Operator.java, EngineOperator.java, and Engine.java files:
and the code fragment:
What is the result?
Question 144
Given the code fragments:
and
What is the result?
Question 145
Given:
Item table
* ID, INTEGER: PK
* DESCRIP, VARCHAR(100)
* PRICE, REAL
* QUANTITY< INTEGER
And given the code fragment:
9 . try {
1 0. Connection conn = DriveManager.getConnection(dbURL, username, password);
1 1. String query = "Select * FROM Item WHERE ID = 110";
1 2. Statement stmt = conn.createStatement();
1 3. ResultSet rs = stmt.executeQuery(query);
1 4. while(rs.next()) {
1 5. System.out.println("ID: " + rs.getInt("Id"));
1 6. System.out.println("Description: " + rs.getString("Descrip"));
1 7. System.out.println("Price: " + rs.getDouble("Price"));
1 8. System.out.println(Quantity: " + rs.getInt("Quantity"));
1 9. }
2 0. } catch (SQLException se) {
2 1. System.out.println("Error");
2 2. }
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the dbURL, userName, and passWordexists.
The SQL query is valid.
What is the result?
