Homework Solution: Object-Oriented Hello World…

    Java Lab1 Object-Oriented Hello World In this lab we will be building a simple object-oriented “hello world”. Declare a single class called HelloWorld according to the following UML class diagram: HelloWorld message: String + setMessage(m: String): void +getMessage(): String In addition to this class, a second class containing a main method should be declared. This second class is called the app class; this is because the main method drives the app when the class that contains it is compiled and run. You may declare both the hello world class and the app class in a single file. If you do, remember that there can only be one public class in each file and that the file must bear the name of the public class that is declared in it. Before writing any code, use software such as Microsoft Visio or draw.io to create a UML class diagram depicting the hello world class (like the one pictured above). There is no need to create a UML class diagram for the app class. Create pseudocode, describing purpose, input, processing and output. Each of these descriptions need only be one to two sentences. Once the logical specification (UML class diagram and pseudocode) is complete, then and only then move on to coding up the hello world class and the app class. Build incrementally and test. Make the tests as specific as possible. Testing requires identifying what is being tested, forming a hypothesis (what will the code that’s being tested do when it is run?) compiling/running and observing the results. If one’s hypothesis does not accord with the way the program runs then the code must be revised and retested. Sometimes the logical specification must be revised; if for example the implementation diverges from the logical specification.
    HelloWorld message: String + setMessage(m: String): void +getMessage(): String

    Expert Answer

     
    Psuedocode: 1.Getting the input entered by the user.

    Java

    Lab1

    Object-Oriented Hello Earth

    In this lab we conciliate be construction a incomplex view-oriented “hello earth”. Approve a uncombined assort denominated

    HelloEarth consensusing to the subjoined UML assort diagram:

    HelloEarth communication: String + setMessage(m: String): unsubstantial +getMessage(): String

    In enumeration to this assort, a prevent assort containing a deep rule should be apparent. This

    prevent assort is denominated the app assort; this is consequently the deep rule drives the app when the

    assort that contains it is compiled and reach. You may approve twain the hello earth assort and the

    app assort in a uncombined refine. If you do, mind that there can simply be undivided open assort in each refine

    and that the refine must endure the indicate of the open assort that is apparent in it.

    Before match any command, interpretation software such as Microsoft Visio or

    draw.io

    to cause a UML assort

    diagram depicting the hello earth assort (approve the undivided pictured aloft). There is no deficiency to cause

    a UML assort diagram ce the app assort.

    Cause pseudocode, describing meaning, input, processing and extinguishedput. Each of these

    descriptions deficiency simply be undivided to two sentences.

    Once the argumentative demonstration (UML assort diagram and pseudocode) is exhaustive, then and simply

    then instigate on to coding up the hello earth assort and the app assort. Build incrementally and experience.

    Make the experiences as favoring as feasible. Experienceing requires identifying what is entity experienceed, ceming

    a theory (what conciliate the command that’s entity experienceed do when it is reach?) compiling/running and

    observing the results. If undivided’s theory does not attributable attributable attributable consensus with the fashion the program reachs then

    the command must be revised and retested. Sometimes the argumentative demonstration must be revised; if

    ce copy the implementation diverges from the argumentative demonstration.

    HelloEarth communication: String + setMessage(m: String): unsubstantial +getMessage(): String

    Expert Response

     

    Psuedocode:

    1.Getting the input entered by the interpretationr.

    2.Cause an View of Helloearth assort in deep() rule.

    3.Calling the setter rule on the HelloEarth assort by departure the interpretationr entered input.

    4.Display communication Calling the procureter rule on the HelloEarth assort.

    ______________

    Java Command:

    HelloWorld.java

    import java.util.Scanner;

    assort HelloEarth {

    //Declaring solicitation variables
    private String communication;

    //getters and setters
    open String procureMessage() {
    return communication;
    }

    open unsubstantial setMessage(String communication) {
    this.communication = communication;
    }

    }

    //This assort Contains deep() rule
    open assort App {
    open static unsubstantial deep(String args[]) {

    String mesg;

    /*
    * Creating an Scanner assort view which is interpretationd to procure the inputs
    * entered by the interpretationr
    */
    Scanner sc = innovating Scanner(System.in);

    //Getting the input entered by the interpretationr
    System.out.print(“Enter a Communication :”);
    mesg = sc.nextLine();

    //Creating an HelloEarth assort view
    HelloEarth hw = innovating HelloWorld();

    //calling the setter rule by departure the interpretationr entered input
    hw.setMessage(mesg);

    //Calling the procureter rule
    System.out.println(“The Communication is :” + hw.getMessage());

    }
    }

    ______________________