Question

In: Computer Science

Create a new Java program named AllAboutMe (For JAVA we use blue J) Write code to...

Create a new Java program named AllAboutMe (For JAVA we use blue J)

Write code to have the program print your name, favorite color, and three hobbies to a new text file called “AllAboutMe” using PrintStream.

Submit code.

Solutions

Expert Solution

Java program :

AllAboutMe.java :


//import package
import java.util.*;
import java.io.*;

//Java class
public class AllAboutMe {
   // main() method
   public static void main(String[] args) throws FileNotFoundException {
       // This line will create object of Scanner class
       Scanner sc = new Scanner(System.in);
       // asking user name
       System.out.print("Enter name : ");
       // reading name
       String name = sc.nextLine();
       // asking user favorite color,
       System.out.print("Enter favorite color : ");
       // reading favorite color,
       String favoriteColor = sc.nextLine();
       // asking user hobbies
       System.out.print("Enter hobbie 1 : ");
       // reading hobbie1
       String hobbie1 = sc.nextLine();
       // asking user hobbies
       System.out.print("Enter hobbie 2 : ");
       // reading hobbie2
       String hobbie2 = sc.nextLine();
       // asking user hobbies
       System.out.print("Enter hobbie 3 : ");
       // reading hobbie3
       String hobbie3 = sc.nextLine();
       //Object of FileOutputStream
       FileOutputStream fileOutStream=new FileOutputStream("AllAboutMe.txt");
       //Object of PrintStream class
       PrintStream printStream=new PrintStream(fileOutStream);
       printStream.println("Name : "+name);//write name
       printStream.println("Favorite color : "+favoriteColor);
       //write hobbies
       printStream.println("Hobbies are : "+hobbie1+" , "+hobbie2+" , "+hobbie3);
       printStream.close(); //close PrintStream
       try {
           fileOutStream.close();//close FileOutputStream
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }

   }

}
======================================

Screen taking input from user :

File :AllAboutMe.txt


Related Solutions

Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
Create a class named RemoveDuplicates and write code: a. for a method that returns a new...
Create a class named RemoveDuplicates and write code: a. for a method that returns a new ArrayList, which contains the nonduplicate elements from the original list public static ArrayList removeDuplicates(ArrayList list) b. for a sentinel-controlled loop to input a varying amount of integers into the original array (input ends when user enters 0) c. to output the original array that displays all integers entered d. to output the new array that displays the list with duplicates removed Use this TEST...
WRITE CODE IN JAVA it is now your turn to create a program of your choosing....
WRITE CODE IN JAVA it is now your turn to create a program of your choosing. If you are not sure where to begin, think of a task that you repeat often in your major that would benefit from a program. For example, chemistry unit conversions, finding the area for geometric shapes, etc. You can also create an interactive story that changes based on the user input/decisions. The possibilities are endless. The program must include instructions for the user. Be...
Please write a java code. Write a generic program for New Home Construction Pricing with the...
Please write a java code. Write a generic program for New Home Construction Pricing with the following specifications. Note, each one of the 2, 3 or 4 bedroom homes are priced with standard type bathrooms. Update to deluxe or premium choice of bathrooms can be ordered by paying the difference in prices.    Types of homes Price 2 bedroom, 2 bathroom (standard type) and 1 car garage home = $350,000 3 bedroom, 2 bathroom (standard type) and 2 car garage...
I need the output of the code like this in java First we create a new...
I need the output of the code like this in java First we create a new building and display the result: This building has no apartments. Press enter to continue......................... Now we add some apartments to the building and display the result: This building has the following apartments: Unit 1 3 Bedroom Rent $450 per month Currently unavailable Unit 2 2 Bedroom Rent $400 per month Currently available Unit 3 4 Bedroom Rent $1000 per month Currently unavailable Unit 4...
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
Code in Java Create a class named DictionaryWord as: DictionaryWord - word: String                            &n
Code in Java Create a class named DictionaryWord as: DictionaryWord - word: String                                                              - meanings: String + DictionaryWord (String word, String meanings) + getWord(): String + setWord (String word): void + getMeanings(): String + setMeanings(String meanings): void Write a program with the following requirements: Creates 8 DictionaryWord objects with: Word and meanings as the table: word meanings bank robber Steals money from a bank burglar Breaks into a home to steal things forger Makes an illegal copy of something...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT