Sunday, April 2, 2017

Day 1 Java Training

Day 1 Java Training


//Creating "Hello World" in an Object Oriented Manner

public class MessageDisplay {
String message;
void display()
{
System.out.println(message);
}
public static void main(String Arg[]){
MessageDisplay mg = new MessageDisplay();
mg.message="Hello World";
mg.display();
}
}
_______________________________________________________
// Using Classes

class ByeWorld{
public static void main(String[] arg){
MessageDisplay bw=new MessageDisplay();
bw.message="Bye World!";
bw.display();
}
}
_______________________________________________________
//
public class MessageDisplay {
String message;
void display()
{
System.out.println(message);
}
void setMessage(String s){
message=s;
}
public static void main(String Arg[]){
MessageDisplay mg = new MessageDisplay();
mg.setMessage("Hello World!");
mg.display();
}
}
________________________________________________________
class temperature {
int temp;
boolean iswitch=true;
void checkTemp(int t){
temp=t;
if(temp>=100){
iswitch=false;}
else{
iswitch=true;
}
}
void displaystatus(){
String switchstatus;
if(iswitch)
{
switchstatus="ON";}
else{
switchstatus="OFF";
}
System.out.println("The temperature is: " + temp);
System.out.println("Device Status is: " + switchstatus);
}
}

class TestHeater{
public static void main(String[] arg){
temperature device1 = new temperature();
device1.checkTemp(100);
device1.displaystatus();
temperature device2 = new temperature();
device2.checkTemp(50);
device2.displaystatus();
}
}

download more info

No comments:

Post a Comment