COP 3330 FINAL Exam with
complete solutions latest version
True or False
When String objects are compared using ==, the result is true if the strings contain the
same values. - CORRECT ANSWER-False. String objects are compared using the
operator == to compare if they are the same object in memory.
True or False
A string can be modified after it's created. - CORRECT ANSWER-False. string objects
are immutable and cannot be modified after they're created. Stringbuilder objects can
be modified after they're created.
Compare the string in s1 to the string in s2 for equality of contents. - CORRECT
ANSWER-s1.equals(s2)
Append the string s2 to the string s1, using +=. - CORRECT ANSWER-s1 += s2;
Determine the length of the string in s1. - CORRECT ANSWER-s1.length()
True or False
You must explicitly create the stream objects System.in, System.out, and System.err. -
CORRECT ANSWER-False. These 3 streams are created for you when a java app
begins execution
When reading data from a file using class Scanner, if you wish to read data in the file
multiple times, the file must be closed and reopened to read from the beginning of the
file - CORRECT ANSWER-True
T/F
BRAINSCAPE1
, BRAINSCAPE1
Files static method "exists" receives a Path and determines whether it exists (either as a
file or as a directory) on disk. - CORRECT ANSWER-True
Binary files are human readable in a text editor. - CORRECT ANSWER-False. Text files
are human Readable, Binary files are only readable if they appear in ASCII text
An absolute path contains all the directories, starting with the root directory, that lead up
to a specific file or directory. - CORRECT ANSWER-True
Class "Formatter" contains method printf, which enables formatted data to be output to
the screen or to a file. - CORRECT ANSWER-False. Formatter contains method
"format" which enables formatted data to be output to a screen or to a file.
Write a statement that opens file "oldmast.txt" for input - use Scanner variable "in-
OldMaster" - CORRECT ANSWER-Scanner inOldMaster = new Scanner
(Paths.get("oldmast.txt"));
Write a statement that opens file "trans.txt" for input - Use Scanner variable "in-
Transaction - CORRECT ANSWER-Scanner inTransaction = new
Scanner(Paths.get("trans.txt"));
Write a statement that opens file "newmast.txt" for output (and Creation) - use formatter
variable "outNewMaster" - CORRECT ANSWER-Formatter outNewMaster = new
Formatter("newmast.txt");
Write the statements needed to read a record from the file "oldmast.txt". Use the data to
create an object of class "Account" - use Scanner Variable "inOldMaster". Assume the
class Account is the same as figure 15.9 - CORRECT ANSWER-Account account =
new Account();
account.setAccount(inOldMaster.nextInt( ));
account.setFirstName(inOldMaster.next( ));
account.setLastName(inOldMaster.next( ));
account.setBalance(inOldMaster.nextDouble( ))
Write the statements needed to read a record form the file "trans.txt". the record is an
object of class "TransactionRecord" - use scanner variable "inTransaction" Assume the
class contains method "setAccount" which takes in an int, to set the account number
and method "setAmount" which takes in a double for the amount of the transaction -
CORRECT ANSWER-TransactionRecord transaction = new Transaction ( );
transaction.setAccount(inTransaction.nextInt( ));
transaction.setAmount(inTransaction.nextDouble( ));
Write a statement that outputs a record to the file "newmast.txt". the Record is an object
of type Account - use Formatter variable outNewMaster - CORRECT ANSWER-
outNewMaster.format("%d %s %s %.2f%n", account.getAccount(),
account.getFirstName(), account.getLastName(), account.getBalance());
BRAINSCAPE1