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

CODE IN JAVA Create a new class named Task1. In its main function, use Scanner to...
CODE IN JAVA Create a new class named Task1. In its main function, use Scanner to read integers from the keyboard with the method nextInt. Use a try catch block to capture non-integer input, and tell the user, "This is not an Integer". The program loop should end when the user enters the string "quit". (Hint: "quit" is clearly not a number and will be captured in the try / catch block.) A typical Output Dialog is shown below: Enter...
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
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...
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,...
Write in Java * Create a new client class called Plants.java * Write code in the...
Write in Java * Create a new client class called Plants.java * Write code in the Plants class that solves problems 1,2,3 and 4 * Include the solutions of the different problems in different methods and call them from the main method * Use the BagInterface.java and ArrayBag.java, but do not add any code Problem 1: Create a bag plantsCart, which holds the following spring seedlings(represented by String) Rose, Daisy, Cabbage, Cucumber, Carrot, Cucumber, Daffodil, Daisy, Rose, Iris, Rose, Spinach....
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...
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...
in java we need to order a list , if we create a program in java...
in java we need to order a list , if we create a program in java what  are the possible ways of telling your program how to move the numbers in the list to make it sorted, where each way provides the required result. list the name of sorting with short explanation
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT