100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CSC 1351 Exam 1 with Answers 2024/2025 $14.99   Add to cart

Exam (elaborations)

CSC 1351 Exam 1 with Answers 2024/2025

 2 views  0 purchase

File infile = new File(""); Answer: Declare and initialize a File variable infile for the file with name Scanner in = new Scanner(infile); Answer: Declare and initialize a Scanner variable in that reads from infile String word = (); Answer: Declare and initialize a va...

[Show more]

Preview 4 out of 194  pages

  • August 30, 2024
  • 194
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
All documents for this subject (6)
avatar-seller
Schoolflix
CSC 1351 Exam 1 with Answers 2024/2025

File infile = new File("in.txt"); Answer: Declare and initialize a File variable infile for the file with
name in.txt



Scanner in = new Scanner(infile); Answer: Declare and initialize a Scanner variable in that reads from
infile



String word = in.next(); Answer: Declare and initialize a variable word with the first word from the
file.



in.close(); Answer: Close the scanner.



PrintWriter out = new PrintWriter("out.txt"); Answer: Declare and initialize a PrintWriter variable
out that writes to out.txt.



out.println("Hello"); Answer: Write a line consisting of the word Hello to out.txt.



out.close(); Answer: Close the writer.



B Answer: Which of the following is the correct way to create a Scanner object to read text from an
input file data.txt?



A) Scanner inputFile = new Scanner("data.txt");

B) File theFile = new File("data.txt"); Scanner inputFile = new Scanner(theFile);

C) Scanner inputFile = new Scanner("data.txt"); File theFile = new File(inputFile);

D) Scanner inputFile = new File("data.txt");

,D Answer: Which of the following is the correct way to create a PrintWriter object to write text to
an output file results.txt?



A) PrintWriter outputFile = new

PrintStream("results.txt");

B) PrintWriter outputFile = new

File("results.txt")

C) Scanner theFile = new Scanner("results.txt");

PrintWriter outputFile = new

PrintWriter (theFile);

D) PrintWriter outputFile = new

PrintWriter("results.txt");



D Answer: What happens when you supply the same name for the input and output files to the
Total program? Try it out if you are not sure.



A) The program reads all input from the file and then writes the formatted values and the total to the
file.

B) An exception is thrown in the PrintWriter construction

C) An exception is thrown in the call in.nextDouble()

D) The while loop is never entered



D Answer: What happens when you supply the name of a nonexistent input file to the Total
program? Try it out if you are not sure.



A) The program writes an empty output file and exits normally

,B) The program writes "Total: 0.00" to the output and exits normally

C) The statement File inputFile = new File(inputFileName); throws an exception

D) The statement Scanner in = new Scanner(inputFile); throws an exception



objects Answer: "Hello" and System.out are examples of _____.



methods Answer: length, substring, and println are examples of _____.



classes Answer: String, Student, and PrintStream are examples of _____.



String Answer: length and substring are methods of the _____ class, but println is not.



public interface Answer: The names and behavior of the methods of a class form the _____ _____
of the class.



encapsulation Answer: The user of a class only knows the public interface, not the implementation
details, of a class. This is called _____.



C Answer: Assuming that name is a String object, which of the following is a legal method call?



A) name.println();

B) name.nextInt();

C) name.charAt(0);

D) name.parseInt();



A Answer: Suppose you want to work with objects of the Student class. What do you need to know?

, A) The public interface of the class

B) The private implementation of the class

C) Both the public interface and the private implementation

D) Only the names of the method parameters



True Answer: True or False? System.out is an object.



False Answer: True or False? String is an object.



False Answer: True or False? The String class stores strings as arrays of characters.



True Answer: True or False? Suppose that a new version of Java is released, and that the Java
compiler changes the way that string objects store characters. If the string methods are updated
accordingly, then you won't need to change your code.



D Answer: What is the purpose of an object's instance variables?



A) To provide access to the data of an object

B) To create variables with public visibility

C) To store the data for all objects created by the same class

D) To store the data for a single instance of a class



1 Answer: 1 public class Counter

2{

3 private int value;

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller Schoolflix. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $14.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

73314 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$14.99
  • (0)
  Add to cart