Question

In: Computer Science

Linux Question: Describe how you created above file and its contents in VI. a) Bash/VI commands:...

Linux Question: Describe how you created above file and its contents in VI.

a) Bash/VI commands: 20pts;

b) Non-brute-force solution: 10pts).

Note: Brute-force solution means that entering characters one by one

Install JDK 1.8 by the following command: $ sudo dnf –y install java-1.8.0-openjdk-devel.x86_64

Use VI to create a file “YourFirstNameHomework.java” (e.g., “MollyHomework.java”) and add the following contents into it.

(grading details: file name format:10 pts, a screenshot of the file content in the VI environment: 10pts, paragraphs: 10pts, empty lines and indentations: 10, text: 10pts)

import java.util.Scanner; // Import the Scanner class

class CynthiaHomework {

public static void main(String[] args) {

Scanner myObj = new Scanner(System.in); // Create a Scanner object

System.out.println("Enter your first name");

String fName = myObj.nextLine(); // Read user input of the first name

System.out.println("Enter your last name");

String lName = myObj.nextLine(); // Read user input of the last name

System.out.println("Hello " + fName + “ “ + lName); // Output user input

}

}

To compile the above java code, run the following command (you need to use your java file name): $ javac MollyHomework.java

To execute the java program, run the following command $ java MollyHomework

Solutions

Expert Solution

To do the stated commands follows the instructions:

1.Intially open the command prompt by using

  1. Open the command prompt. Follow the menu path Start > Programs > Accessories > Command Prompt.
  2. Type: java -version and press Enter on your keyboard. Result: A message similar to the following indicates that Java is installed and you are ready to use MITSIS via the Java Runtime Environment.

then you are set to go.

2. Now type in

$ mkdir javaprograms

$ cd javaprograms

$ vi MollyHomework.java

The cmd will open the file for you and then paste the code in the file:

import java.util.Scanner; // Import the Scanner class

class CynthiaHomework {

public static void main(String[] args) {

Scanner myObj = new Scanner(System.in); // Create a Scanner object

System.out.println("Enter your first name");

String fName = myObj.nextLine(); // Read user input of the first name

System.out.println("Enter your last name");

String lName = myObj.nextLine(); // Read user input of the last name

System.out.println("Hello " + fName + “ “ + lName); // Output user input

}

}

to move out of the vi editor:

Quit the vi editor by saving your changes

  1. To save a file, you must first be in Command mode. Press Esc to enter Command mode, and then type :wq to write and quit the file.

And back to the cmd and type in

$ javac MollyHomework.java

If there are any errors then it will show or else continue..

$ java MollyHomework.java

And then it will show the output.


Related Solutions

Use Vi text editor or ATOM to create a bash script file. Use the file name...
Use Vi text editor or ATOM to create a bash script file. Use the file name ayaan.sh. The script when ran it will execute the following commands all at once as script. Test your script file make sure it works. Here is the list of actions the script will do: It will create the following directory structure data2/new2/mondaynews off your home directory. inside the mondaynews, create 4 files sports.txt, baseball.txt, file1.txt and file2.txt. Make sure file1.txt and file2.txt are hidden...
Linux Ubuntu 1. Use the appropriate commands to locate the device file used by the device,...
Linux Ubuntu 1. Use the appropriate commands to locate the device file used by the device, mount the filesystem to a directory of your choice, and check the filesystem for errors. 2. Finally, add a line to /etc/fstab to ensure that the filesystem can be easily mounted in the future (this line should not automount the filesystem at boot time). You have to document all your steps and provide the screenshot of your work process.
Linux-Practise1: Run the following commands (Print working directory) pwd. What is the output of the above...
Linux-Practise1: Run the following commands (Print working directory) pwd. What is the output of the above command Create a file named Linux1 nano Linux1 Type the following in the file Hello world Save the file Create a copy of the file cp Linux1 Linux2 view the listing of the files in the directory            ls What is the output of the above command rename the file mv Linux2 Linux3 view the listing of the files in the directory            ls...
Unix / Linux 6. vi editor: In vi command mode, what are the keystrokes you would...
Unix / Linux 6. vi editor: In vi command mode, what are the keystrokes you would type to... Quit the vi editor and save any changes? 7. C language source files, by convention, have the suffix ".c". The associated "header" files have the suffix ".h". What is the command to perform the following task: List all the C source and C header files in the current directory. [Hidden files may remain hidden.] 8. C language source files, by convention, have...
Using Node.js, show how you would read a file and and write out its contents to...
Using Node.js, show how you would read a file and and write out its contents to a new file in reverse order. As an example, if the source file had: Roses are red, Violets are blue. If the Trump administration continues to lose cabinet members, I will not be sad. Boo hoo hoo. The destination file would have: I will not be sad. Boo hoo hoo. If the Trump administration continues to lose cabinet members, Violets are blue. Roses are...
1. When a file is created on Linux Operating System, What are the default permissions of...
1. When a file is created on Linux Operating System, What are the default permissions of the file? 2. Write a command to find the total disk space used by a specific user on linux system? 3. What is "s" permission bit in a file? 4. Explain the difference between grep and egrep? 5. Write a command to list files where third letter is x or y? 6. Write command to remove array element with id 5? 7. Write a...
Try the Linux commands listed below. Post your thoughts about how to use these commands. Discuss...
Try the Linux commands listed below. Post your thoughts about how to use these commands. Discuss options that you might use with them, compare and contrast them and/or ask questions about commands you are not sure about. mount and umount more and less head and tail grep kill / xkill / pkill / killall su and sudo man and whatis ping and traceroute
Linux Commands 8.How would you find out information about systemdon your Linux workstation? 9.A user would...
Linux Commands 8.How would you find out information about systemdon your Linux workstation? 9.A user would like to put the firefoxprogram in the background –what would you type into the command prompt to do this? 10.For the program in above, how would you bring it back into the foreground? 11.What is the fork()function call? 12.In Linux what command sequence do we enter to stop a program? 13.What is the UIDcolumn in the output of the command ps -ef? 14.What is...
PLEASE USE LINUX/UNIX 1.Use either pico, vi, or cat to create the following file and name...
PLEASE USE LINUX/UNIX 1.Use either pico, vi, or cat to create the following file and name it as “mysedfile”: Name Class1 Class2 Class3 Tom 92 94 88 Nancy 91 85 95 Lisa 99 77 96 Jerry 84 98 90 2. Please use sed command(s) to complete the following tasks. display Tom’s record. display Lisa’s record. display both Tom’s and Lisa’s records. remove the blank line(s) from “mysedfile.” replace all the digits with *.
Your First Bash Script Now that we know how to execute multiple commands and error check...
Your First Bash Script Now that we know how to execute multiple commands and error check using the command-line, we will start to put logic into a script. Bash scripts are interpreted by bash just like commands on the command-line. Use an editor to make the following script, called count.sh: echo “1” echo “2” echo “3” You can now run this script using the command: $ bash count.sh This feeds the script to the bash interpreter, which interprets the commands....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT