Question
Suppose you are using JUnit to write unit tests on the class Ship. Ship has public getters and setters for its variables weight, velocity, and
-
Suppose you are using JUnit to write unit tests on the class Ship. Ship has public getters and setters for its variables weight, velocity, and bearing, as well as several constructors. It also has the private method scuttle(), which causes the Ship to sink. Which statement is true?
You should create one Ship and use it in each test You should create one or more new Ships for each test instead of reusing them There is no way to test the setters You can easily test the method scuttle()
-
Suppose you have a class Ship, which was written by another programmer who used to work for your employer. Ship is used in several different applications. Ship contains a public method called getBearing() that consults gyroscopes and a compass to determine the direction in which the ship is moving and returns a Location object. You need to refactor the code to use a GPS receiver instead. You should
Write a new class with the new implementation of the method Write a new method called getBearingFromGPS() that uses the new equipment Rewrite getBearing(), leaving its signature the same Rewrite the applications that use Ship so that they can use the GPS receiver to determine the bearing of each ship without calling getBearing()
-
Why do we wait until the middle of CS2012 before teaching anything about GUI construction?
Because CS instructors are old and find it difficult to use mice and touchscreens accurately Because GUI frameworks like Swing and JavaFX usually require heavy use of OOP techniques Because the users of your applications won't care very much about the quality of your GUIs Because GUIs are likely to go out of fashion in the next few years
-
In GUI programming, an event is represented by
an object a method a variable a loop
-
Suppose you are writing a GUI-based program in which a menu item invokes a spell checker. Which of these is the best strategy?
Write the spell check code in the event handler Write a separate method in the GUI class with the spell check code Write a SpellChecker class with a method that runs the check, and call it from the event handler
-
Consider this code:
b.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler
(){ @Override public void handle(Event event) { JOptionPane.showMessageDialog(null, "Thanks!"); } }); The event handler in the code is
an example of separation of concerns an anonymous class static overloaded
-
Suppose you write an abstract class called Vehicle, which is extended by the classes Motorcycle, RedWagon, and MarsLander. In all the code that uses these classes, you call only the methods that are declared in Vehicle. This is an example of
Expense Encapsulation Separation of Concerns Composition Coding to the interface, not the implementation
-
Consider this code:
Demo d1 = new Demo(); Demo d2 = new Demo(); Demo d3 = d1; Demo d4;
How many Demos are instantiated?
1 2 3 4
-
Consider the following code:
String s1 = "Godzilla"; String s2 = "Godzilla"; String s3 = new String("Godzilla"); s1 = s1 + " is coming!";
In Java, Strings are interned and immutable. Which of these properties affects the number of Strings that are actually created in memory when this code executes?
Both interning and immutability Neither interning nor immutability Interning but not immutability Immutability but not interning
-
Consider this code:
String s1 = "Godzilla"; String s2 = "Godzilla"; System.out.println(s1==s2);
Which of the following affects the result of the boolean operation?
Immutability but not interning Interning but not immutability Both interning and immutability neither interning nor immutability
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started