1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
almond37 [142]
3 years ago
5

Public class Question4

Computers and Technology
1 answer:
enyata [817]3 years ago
4 0

Answer:

See explaination

Explanation:

import java.io.File;

import java.io.PrintWriter;

public class Question4 {

/*

* For this exercise you will be doing some basic operations to write to a

* file. You will be creating your very own Secrets of the Universe (TM)

*

* You can use the PrintWriter class to write to files (Chapter 11.4)

*

* Your code should perform the following actions:

*

* 1) Open/Create a file for writing at the following location:

* "files/question4/MySecretsOfTheUniverse.txt" If the file already exists

* you will want to overwrite its contents. 2) Add at least 3 of your own

* secrets of the universe to the file. Each secret should be on its own

* line. 3) Make sure to close your file so that the results are saved.

*

* Note: Your code should not throw any checked exceptions.Note: You will

* need to import some classes from the java.io package.

*/

public static void Question4() {

// creating a File object

File file = new File("files/question4/MySecretsOfTheUniverse.txt");

try {

// opening print writer to write to the file. the file will be

// created if not exist, but you have to ensure that the directory

// files/question4/ exists.

PrintWriter writer = new PrintWriter(file);

// writing three random statements to the file. I dont know anything

// about the secrets of universe you mentioned, so I'm just writing

// some random stuff that came into my mind. You can replace below

// lines with whatever you want to write.

writer.println("Humans are aliens from Mars, sent here to colonize Earth after they screwed up mars.");

writer.println("This universe and everything in it are probably brain cells of some huge cosmic organism.");

writer.println("There may be other forms of life co-exist here on our Earth that we can't see,"

+ " because they vibrate at a different frequency outside of all our measurements");

//closing file, saving changes

writer.close();

} catch (Exception e) {

//printing error if exception is occurred.

System.err.println(e);

}

}

public static void main(String[] args) {

Question4();

}

}

You might be interested in
Look at the following Python code:
aliya0001 [1]

Ump will be assigned to word2

word1[0:3] gets all of the letters from index 0 to index 3 exclusive (that means index 3 is not included)

4 0
3 years ago
Write a MIPS assembly language program that
8_murik_8 [283]

Answer:

123456789098765432

Explanation:

asdfghjklokjhgfdsasertyujn nbgfdfvbnjujhgvfcdec vgfredfghjmk

5 0
3 years ago
A _________ is a series of commands and instructions that you group together as a single command to accomplish a task automatica
melamori03 [73]
A macro is a series of commands and instructions that you group together as a single command to accomplish a task automatically.
8 0
4 years ago
How many people in the world
sveticcg [70]

Answer:

Around seven billion people

4 0
3 years ago
An array of strings , names , has been declared and initialized . write the statements needed to determine whether any of the th
OLEGan [10]
#Python

hasempty = False
for name in names:
   if ( not name ):
      hasempty = True
      break  # speed things up
3 0
4 years ago
Other questions:
  • Consider a relation representing the present position of molecules in a closed container. The attributes are the ID for the mole
    12·1 answer
  • To include totals and other statistics at the bottom of a datasheet, click the ____ button on the HOME tab to include the Total
    12·1 answer
  • A four-year old laptop will not boot and presents error messages on screen. You have verified with the laptop technical support
    11·1 answer
  • American company Software Unlimited is planning to expand its operations to the Bangor Republic where the group is the primary u
    7·1 answer
  • Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp
    11·1 answer
  • Short notes on Supply chain Management System (SCMS)
    12·1 answer
  • What is digital scavenger hunting? A. An application that locates addresses B. A scavenger hunt where players use GPS and digita
    5·1 answer
  • 25 Points Asap <br> Write a Java program named Light.java that displays a light bulb shown below:
    14·1 answer
  • Quick!! Im taking a timed test so pls hurry!! Ill even mark as brainliets!!
    5·2 answers
  • QUICK HELP ME PLEASE
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!