Question

Complete the code, compile, and run (make sure the program runs as specified). /* File: HelloWorldTwo.java...

Complete the code, compile, and run (make sure the program runs as specified).

/* File: HelloWorldTwo.java
* Author: Big Boss
* CST 261 - ###
* Instructor: Professor Kojima
* Date: January 1, 1970 (Why is is not true?)
* Last Modified: January 1, 1970 (Still not true)
*
* Description: Variation on the ubiquitous "hello, world!"
* program.
*
* Usage: java HelloWorldTwo [OPTION] or no option
*
* Options:
*
*            -h   The option -h is used to send the string "hello" is
*                sent to the standard output device
*           
*            -w   The options -w is used to send the string "world is
*                sent to the standard output device
*
* If no option is provided, then the string "hello, world!" is sent to
* the standard output device.
*/

/**
* <h1>HelloWorldTwo</h1>
*
* <p>HelloWorldTwo implements a program which either writes
* "hello", "world", or "hello, world!" to the standard output.
* </p>
*
*/
public class HelloWorldTwo {

/**
* Program entry point<br><br>
*
* Preconditions: a string of length &gt; 0 passed to the
   * main method through the command line arguments or
   * no argument is provided<br>
* Postcondition: a string output written to
* standard output<br><br>
*
* @param args args[0] should contain the value "-h",
* "-w", or none.
*/
public static void main(String[] args)
   {
       // TODO: Your code goes here
      
   }
} // end of class HelloWorldTwo

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/* File: HelloWorldTwo.java
 * Author: Big Boss
 * CST 261 - ###
 * Instructor: Professor Kojima
 * Date: January 1, 1970 (Why is is not true?)
 * Last Modified: January 1, 1970 (Still not true)
 *
 * Description: Variation on the ubiquitous "hello, world!"
 * program.
 *
 * Usage: java HelloWorldTwo [OPTION] or no option
 *
 * Options:
 *
 *            -h   The option -h is used to send the string "hello" is
 *                sent to the standard output device
 *
 *            -w   The options -w is used to send the string "world is
 *                sent to the standard output device
 *
 * If no option is provided, then the string "hello, world!" is sent to
 * the standard output device.
 */

/**
 * <h1>HelloWorldTwo</h1>
 *
 * <p>HelloWorldTwo implements a program which either writes
 * "hello", "world", or "hello, world!" to the standard output.
 * </p>
 */
public class HelloWorldTwo {

    /**
     * Program entry point<br><br>
     * <p>
     * Preconditions: a string of length &gt; 0 passed to the
     * main method through the command line arguments or
     * no argument is provided<br>
     * Postcondition: a string output written to
     * standard output<br><br>
     *
     * @param args args[0] should contain the value "-h",
     *             "-w", or none.
     */
    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("hello, world!");
        } else {
            if (args[0].equals("-h")) {
                System.out.println("hello");
            } else if (args[0].equals("-w")) {
                System.out.println("world");
            } else {
                System.out.println("hello, world!");
            }
        }
    }
} // end of class HelloWorldTwo
Add a comment
Know the answer?
Add Answer to:
Complete the code, compile, and run (make sure the program runs as specified). /* File: HelloWorldTwo.java...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • /* * Purpose: Test an implementation of an array-based list ADT. * To demonstrate the use...

    /* * Purpose: Test an implementation of an array-based list ADT. * To demonstrate the use of "ListArrayBased" the project driver * class will populate the list, then invoke various operations * of "ListArrayBased". */ import java.util.Scanner; public class ListDriver {    /*    * main    *    * An array based list is populated with data that is stored    * in a string array. User input is retrieved from that std in.    * A text based...

  • When I try running this code in java, it doesn't work properly. The part where it...

    When I try running this code in java, it doesn't work properly. The part where it should ask the user to write some string, where I would write in "one two three four" doesn't work, it says "bash: one: command not found" Please help fix. public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); System.out.println("The arguments are:"); for(String element : args) {    System.out.println("\t" + element); } } } Sample output: Hello World! The arguments are:        ...

  • JAVA CODE This program causes an error and crashes. Compile and give it a test run,...

    JAVA CODE This program causes an error and crashes. Compile and give it a test run, note the exception that is thrown. Then do the following to fix the problem 1. Write code to handle this exception 2. Use try, catch and finally blocks. 3. Display, the name of the exception 4. Display a message from the user about what happened. Here is the starting file BadArray.java: public class BadArray { public static void main(String[] args) { // Create an...

  • 1. What does a Java compiler do? Select one: a. Runs Java programs b. Translates byte...

    1. What does a Java compiler do? Select one: a. Runs Java programs b. Translates byte code in ".class" files into machine language c. Translates source code in ".class" files into machine language d. Translates source code in ".java" files into Java byte code in ".class" files e. Translates source code in ".java" files into machine language 2. A subclass will _____ one superclass. Select one: a. abstract b. extend c. implement d. inherit e. override 3. Consider the following...

  • Complete the program below in order to make run properly by competing validName methods and add...

    Complete the program below in order to make run properly by competing validName methods and add trycatch block in the main method public class ExceptionWithThrow { public static String validName(String name) throws InputMismatchException{ // check here if the name is a valid name // through InputMismatchException if invalid //throw // return the name if it is valid } public static void main(String[] args) { // Ask the user to enter a name and their validity through validName method // Add...

  • #1. Operators and values, expressions Please correct the following code to make it print the given...

    #1. Operators and values, expressions Please correct the following code to make it print the given expressions and their answers well (3pts). public class DataTypes {    public static void main(String[] args) {       System.out.println("5*8/6 = " + 5*8/6);       System.out.println("(2*6)+(4*4)+10 = " + (2*6)+(4*4)+10);       System.out.println("6 / 2 + 7 / 3 = " + 6 / 2 + 7 / 3);       System.out.println("6 * 7 % 4 = " + 6 * 7 % 4 );       System.out.println("22 + 4 * 2 = "...

  • Write a program that will check a Java file for syntax errors. The program will ask...

    Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • In each of the following questions, first use NetBeans IDE to run the code (if there...

    In each of the following questions, first use NetBeans IDE to run the code (if there is an error fix it) then take a screenshot of the output and paste it under (A). In (B), justify the output you obtained in (A). - 9. Given the following: public class WorkingSheet {     public static void main(String[] args) {        B myB = new B();        A myA = new B();        System.out.print(myB instanceof A);        System.out.print(myB instanceof C);        System.out.print(myA...

  • java question: Write a program that reads in data from a text file named in.txt. Compute...

    java question: Write a program that reads in data from a text file named in.txt. Compute the sum of all the valid integers in the input file. Likewise, compute the sum of all the valid doubles in the input file. Write the former to an output file called int_total.txt, and write the latter to an output file called double_total.txt. B) Write a program that converts the Java source code from the next-line brace style to the end-of-line brace style. For...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT