Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Lab1 Object-Oriented Hello World In this lab we will be building a simple o

ID: 3873260 • Letter: J

Question

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:

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

Explanation / Answer

Psuedocode:

1.Getting the input entered by the user.

2.Create an Object of Helloworld class in main() method.

3.Calling the setter method on the HelloWorld class by passing the user entered input.

4.Display message Calling the getter method on the HelloWorld class.

______________

Java Code:

HelloWorld.java
  
import java.util.Scanner;
  
class HelloWorld {
  
//Declaring instance variables
private String message;
  
//getters and setters
public String getMessage() {
return message;
}
  
public void setMessage(String message) {
this.message = message;
}
  
}
  
//This class Contains main() method
public class App {
public static void main(String args[]) {
  
String mesg;
  
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
  
//Getting the input entered by the user
System.out.print("Enter a Message :");
mesg = sc.nextLine();
  
//Creating an HelloWorld class object
HelloWorld hw = new HelloWorld();
  
//calling the setter method by passing the user entered input
hw.setMessage(mesg);
  
//Calling the getter method
System.out.println("The Message is :" + hw.getMessage());
  
}
}

______________________

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote