public int getMark1() {
return mark1;
}
public int getMark2() {
return mark2;
}
public String getName() {
return name;
}
protected int result() {
return mark1 + mark2;
}
public boolean isPassed() {
return result() >= PASS_MARK;
}
@Override
public String toString() {
return name + ";" + mark1 + ";" + mark2 + ";" + isPassed();
}
}
import by.gsu.lecture.Trial;
import by.gsu.lecture.LiteTrial;
import by.gsu.lecture.StrongTrial;
class Runner0 {
public static void main(String[] args) {
Trial trial = new Trial("Sakovich", 45, 93);
if(trial != null) {
System.out.println("Name:" +"\t\t" + trial.getName());
System.out.println("Mark 1:" + "\t\t" + trial.getMark1());
System.out.println("Mark 2:" + "\t\t" + trial.getMark2());
// System.out.println("Result:" + "\t\t" + trial.result()); //error! as needed...
System.out.println("Is passed:" + "\t" + trial.isPassed());
System.out.println("To string:" +"\t" + trial.toString());
System.out.println("To string:" +"\t" + trial);
}
}
}
class Runner1 {
public static void main(String[] args) {
Trial[] trials = {
new Trial("Sakovich", 45, 93),
new Trial("Zhylinsky", 51, 35),
new Trial()
};
for (int i=0; i < trials.length; i++) {
System.out.println(trials[i]);
}
}
}
package by.gsu.lecture;
public class LiteTrial extends Trial {
private static final int PASS_MARK1 = 35;
private static final int PASS_MARK2 = 60;
public LiteTrial() {
super();
}
public LiteTrial(String name, int mark1, int mark2) {
super(name, mark1, mark2);
}
public boolean isPassed() {
return mark1 >= PASS_MARK1 && mark2 >= PASS_MARK2;
}
}
package by.gsu.lecture;
public class StrongTrial extends Trial {
public StrongTrial() {
super();
}
public StrongTrial(String name, int mark1, int mark2) {
super(name, mark1, mark2);
}
protected int result() {
return (int) (0.5 * mark1) + mark2;
}
}
class Runner2 {
public static void main(String[] args) {
Trial[] trials = {
new Trial("Sakovich", 45, 93),
new Trial("Zhylinsky", 51, 35),
new LiteTrial("Barkou", 29, 95),
new LiteTrial("Lis", 35, 68),
new Trial("Astapenka", 90, 57)
};
for (int i=0; i < trials.length; i++) {
System.out.println(trials[i]);
}
}
}
class Runner3 {
public static void main(String[] args) {
Trial[] trials = {
new Trial("Sakovich", 45, 93),
new Trial("Zhylinsky", 51, 35),
new LiteTrial("Barkou", 29, 95),
new LiteTrial("Lis", 35, 68),
new StrongTrial("Astapenka", 90, 57)
};
for (int i=0; i < trials.length; i++) {
System.out.println(trials[i]);
}
}
}
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.