environment ・ MacBook pro ・ IntelliJ IDEA CE
I will post it for output while learning Java.
Class: Design document, skeleton Instance: An entity created based on a class
You have been instructed by your boss to build a human world care robot and one of its sister robots from a mass-produced cat robot factory.
My boss gave me detailed data.
About human world care robots
Name: Dora Emon
Color: blue
Gender: Male
About Dora Emon's sister robot
Name: Dorami-chan
Color: pink
Gender: Woman
Create the above two bodies.
Looking at the detailed data, three elements are required. ・ Name ・ Color ・ Gender (sex)
First, complete the class as instructed by your boss.
Robot.java
class Dora {
String name;
String color;
String sex;
Robot(String name, String color , String sex){
this.name = name;
this.color = color;
this.sex = sex;
}
String sayBox(){
return name +"is. color is,"+color+"is. what is your gender"+sex+"is.";
}
}
Now you have a class.
Next, create an instance (details).
RobotFactory.java
public class RobotFactory {
public static void main(String[] args){
Dora robota = new Dora("Dora picture mon","Blue","Man");
System.out.println(robota.sayBox());
Dora roboco = new Dora("Dora Minoru","pink","woman");
System.out.println(roboco.sayBox());
}
}
I will output it.
It's a success. : relaxed:
Recommended Posts