Java Jupyter Notebook
Prints hello using a printer class
//imports
import java.time.*;
//Class can print a value with current date
public class Printer {
private String value;
//takes in value to print
public Printer (String value) {
this.value = value;
}
//prints the value & date info from java.time
public void print() {
//get current date in YYYY-MM-DD format
String currentDate = LocalDate.now().toString();
//print value & currentdate
System.out.println("[" + currentDate + "]: " + value);
}
//tests the class by printing hello and hello world
public static void main (String[] args) {
//this printer prints hello
Printer helloPrinter = new Printer("hello");
helloPrinter.print();
//this printer prints hello world
Printer helloWorldPrinter = new Printer("hello world");
helloWorldPrinter.print();
}
}
// use main method from Printer
Printer.main(null);
/* expected output (ran on 8/20/2022):
* [2022-08-20]: hello
* [2022-08-20]: hello world
*/