public static interface Action {
void apply(int power);
String getActionName();
}
public static class JumpAction implements Action {
private int gravity;
public JumpAction(int gravity) {
this.gravity = gravity;
}
@Override
public void apply(int power) {
if (power > gravity) {
System.out.println("прыгает на " + (power - gravity) + " метров...");
} else {
System.out.println("немогу подпрыгнуть...");
}
}
@Override
public String getActionName() {
return "прыжок";
}
}
public static interface Human {
void doAction(Action action);
}
public static class Man implements Human {
public String name;
private int power = 10;
public Man(String name) {
this.name = name;
}
@Override
public void doAction(Action action) {
System.out.println(name + " делает " + action.getActionName());
action.apply(power);
}
}
public static class Woman implements Human {
public String name;
private int power = 7;
public Woman(String name) {
this.name = name;
}
@Override
public void doAction(Action action) {
System.out.println(name + " вертя задницей делает " + action.getActionName());
action.apply(power);
}
}
public static void main(String[] args) {
JumpAction jump = new JumpAction(8);
Man man = new Man("Анатолий");
man.doAction(jump);
Woman woman = new Woman("Наталья");
woman.doAction(jump);
}
Анатолий делает прыжок
прыгает на 2 метров...
Наталья вертя задницей делает прыжок
немогу подпрыгнуть...
select * from groups where group_id in (select group_id from student_group where student_id = ид_студента);
insert into student_group (student_id, group_id) values (ид_студента, ид_группы)
String sql = "insert into student_group (student_id, group_id) values (?, ?)";
Connection connection = new getConnection();
PreparedStatement ps = connection.prepareStatement(sql);
String student_id = "Какойто_ид_студента";
ArrayList<String> groups = // это твой лист с группами
for (Student group : groups) {
ps.setString(1, student_id);
ps.setString(2, group);
ps.addBatch();
}
ps.executeBatch();
ps.close();
connection.close();
public string Second_method(){
return "Hello";
}
public void First_method(){
String out = Second_method();
System.out.println(out);
}