Paper4:Practical Notes

Tips, reminders, and sample codes for paper5

Tips

Trend

一般来说 每套卷子的每道题的知识点都是差不多固定的

Q1: Queue, Stack; Binary tree, Linked list.
Q2: Binary search; Insertion Sort Bubble Sort; Recursion
Q3: OOP with file handling.

Keyboard shortcuts

Windows

Win+shift+s: 截图 存在剪贴板

Mac

command+shift+4: 截图 - 可选择存在剪贴板/删除/存在某个位置

Java tricks

function传 by reference 的 parameter(除array以外) 可以用global variable 代替

  • 🉑见 9618 y21 41 Q3 第一小题
  • array是可以被引用传递的(can be passed by reference)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//one dimensional array
public class Main {

public static void main(String[] args) {
int[] arr = new int[3];
arr[0]=1;
change(arr);
System.out.println(arr[0]);

}
public static void change(int[] arr) {
arr[0]=2;
}
}
//two dimentional array
public class Main {

public static void main(String[] args) {
int[][] arr = new int[3][2];
arr[0][0]=1;
change(arr);
System.out.println(arr[0][0]);

}
public static void change(int[][] arr) {
arr[0][0]=2;
}

}
1
Output: 2

注意题目问的是”takes xx, xx, as input“ 还是 “takes xx, xx as parameter

  • input: 在console 用 scanner输入
  • parameter: 作为 function/procedure 的参数输入

input注意是否有要求在某个范围内或者是某种形式 记得validate

记得看完题目再开始写代码!!

reader用完记得关掉!

不要盲目用global variable 可以用local variable的尽量用 注意审题

  • 如果需要update的话就用global, 否则用local是ok的

需要print解释信息的时候记得print


Record

9618

S21-41:

  • Q1
    • Linked list
    • mark scheme 错误:
      1. 把class nodedatanextNode设置成private后, 在后面addNode方法中却可以直接.data&.nextNode来进行访问。错误原因是因为用private修饰符过后是不能直接访问的 而是需要通过class里面的method来访问, 所以我写了两个getter methods.
      2. addNode方法中 只有array能够传入, startPointeremptyList需要作为global variable因为他们不能by Reference传入
    • 这题的addNode方法在本题当linked List已有数据的时候是可用的, 但如果linked List 一开始是空的话, addNode方法就不能更新startPointer。修改方案为在[Chapter19.1 Algorithm]中Linked List的insertAtend方法. 只需在while循环结束后判断prevPointer是否为-1, 如是则改变startpointernewPointer;如不是则为本题写法,将linkedList[prevPointer]的指针指向newPointer.
      • 在本题情况下不需要修改:链表为空则添加会不更新startPointer,而本题链表不为空
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//9618 s21 41
import java.util.Scanner;

public class papei_9618_s21_41_Q1 {
static Integer startPointer =0;
static Integer emptyList =5;
public static void main(String[] args) {
node[] linkedList = new node[10];
linkedList[0] = new node(1,1);
linkedList[1] = new node(5,4);
linkedList[2] = new node(6,7);
linkedList[3] = new node(7,-1);
linkedList[4] = new node(2,2);
linkedList[5] = new node(0,6);
linkedList[6] = new node(0,8);
linkedList[7] = new node(56,3);
linkedList[8] = new node(0,9);
linkedList[9] = new node(0,-1);
System.out.println("before adding node, the contents are:");
outputNodes(linkedList, startPointer);
System.out.println("adding node now");//inputting data: 5
if(addNode(linkedList)) {
System.out.println("added successfully");
}
else {
System.out.println("linked list is full, cannot add");
}
System.out.println("after adding nodem the contents are:");
outputNodes(linkedList, startPointer);

}
public static void outputNodes(node[] linkedList, Integer currentPointer) {
while(currentPointer!=-1) {
System.out.println(linkedList[currentPointer].getData());
currentPointer=linkedList[currentPointer].getnextNode();
}
}
public static Boolean addNode(node[] linkedList) {
Scanner sca = new Scanner(System.in);
System.out.println("input the number you want to add");
Integer input = sca.nextInt();
if(emptyList>=0 && emptyList<=9) {
Integer newPointer = emptyList;
emptyList=linkedList[emptyList].getnextNode();
linkedList[newPointer]= new node(input, -1);
Integer prevpointer=startPointer;
while(linkedList[prevpointer].getnextNode()!=-1) {
prevpointer=linkedList[prevpointer].getnextNode();
}
linkedList[prevpointer]=new node(linkedList[prevpointer].getData(),newPointer);
return true;
}
else {
return false;
}
}
public static Boolean addNode1(node[] linkedlist) {
Scanner sca = new Scanner(System.in);
System.out.println("Input the data you want to add to the linkedList");
Integer input = sca.nextInt();
if(emptyList<0 || emptyList>9) {
return false;
}
else {
int newPointer = emptyList;
emptyList=linkedlist[emptyList].getnextNode();
linkedlist[newPointer]=new node(input,-1);
int prevPointer=-1;
int nowPointer=startPointer;
while(nowPointer!=-1) {
prevPointer=nowPointer;
nowPointer=linkedlist[nowPointer].getnextNode();
}
linkedlist[prevPointer].setNextNode(newPointer);
return true;
}
}
}

class node{
private Integer data;
private Integer nextNode;
public node(Integer dataP, Integer nextNodep) {
this.data=dataP;
this.nextNode=nextNodep;
}
public Integer getData() {
return this.data;
}
public Integer getnextNode() {
return this.nextNode;
}
public void setNextNode(Integer nextN) {
this.nextNode=nextN;
}
}

  • Q2
    • Linear search
    • Bubble sort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.*;
import java.io.*;

public class papei_9618_s21_41_Q2 {
static int[] arrayData = {10,5,6,7,1,12,13,15,21,8};
public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
System.out.println("input the value you want to search");
int item = sca.nextInt();
if(linearSearch(item)) {
System.out.println("the search data is found");
}
else {
System.out.println("the search data is not found");
}

}
public static Boolean linearSearch(int item) {
for(int i=0;i>arrayData.length;++i) {
if(arrayData[i]==item){
return true;
}
}
return false;
}
public static void bubbleSort() {
Integer temp;
for(int x=0;x<10;++x) {
for(int y=0;y<9;++y) {
if(arrayData[y]<arrayData[y+1]) {
temp=arrayData[y];
arrayData[y]=arrayData[y+1];
arrayData[y+1]=temp;
}
}
}
}

}

  • Q3
    • Object Oriented Programming
    • File handling
    • Exception handling
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class papei_9618_s21_41_Q3 {
static treasureChest[] arraryTreasure;
public static void main(String[] args) {
readData();
Scanner sca = new Scanner(System.in);
System.out.println("pick a trasure chest to open");
Integer answer,choice;
choice=sca.nextInt();
Integer attempts;
if(choice>0 && choice<6) {
Boolean result=false;
attempts=0;
while(result==false) {
System.out.println(arraryTreasure[choice-1].getQuestion());
answer = sca.nextInt();
result = arraryTreasure[choice-1].checkAnswer(answer);
attempts++;
}
System.out.println("the number of points obtained is: "+ arraryTreasure[choice=1].getPoints(attempts));
}

}
public static void readData() {
arraryTreasure = new treasureChest[5];
String filename = "treasureChestData.txt";
String dataRead;
String question;
String answer;
String points;
File fi = new File(filename);
Integer numberOfQuestions=0;
try {
FileReader fr = new FileReader(fi);
BufferedReader bfr = new BufferedReader(fr);
dataRead=bfr.readLine();
while(dataRead!=null) {
question=dataRead;
answer=bfr.readLine();
points=bfr.readLine();
arraryTreasure[numberOfQuestions]=new treasureChest(question, Integer.parseInt(answer), Integer.parseInt(points));
numberOfQuestions++;
dataRead=bfr.readLine();
}
bfr.close();
fr.close();
}catch(FileNotFoundException e) {
System.out.println("No file found");
}catch (IOException e) {
System.out.println("No file found");
}
}

}

class treasureChest{
private String question;
private Integer answer,points;
public treasureChest(String que,Integer ans, Integer poi) {
this.question=que;
this.answer=ans;
this.points=poi;
}
public String getQuestion() {
return this.question;
}
public Boolean checkAnswer(Integer ans) {
return ans==this.answer;
}
public Integer getPoints(Integer attempts) {
if(attempts==1) {
return this.points;
}
else if(attempts==2) {
return this.points/2;
}
else if(attempts==3 || attempts==4) {
return this.points/4;
}
else {
return 0;
}
}
}

W21-41

  • Q1
    • Iteration
    • Recursion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

public class papei_9618_w21_41_Q1 {

public static void main(String[] args) {
System.out.println("Running with paramters:10,15");
System.out.println("The return value is:"+Unknown(10, 15));

System.out.println("Running with paramters:10,10");
System.out.println("The return value is:"+Unknown(10, 10));

System.out.println("Running with paramters:15,10");
System.out.println("The return value is:"+Unknown(15, 10));


}
public static Integer Unknown(Integer X,Integer Y) {
if(X<Y) {
System.out.println(X+Y);
return Unknown(X+1, Y)*2;
}
else {
if(X==Y) {
return 1;
}
else {
System.out.println(X+Y);
return Unknown(X-1, Y)/2;
}
}
}
public static Integer IterativeUnknown(Integer X,Integer Y) {
Integer total=1;
while(X!=Y) {
System.out.println(X+Y);
if(X<Y) {
X=X+1;
total=total*2;
}
else {
X=X-1;
total=total/2;
}
}
return total;
}

}
  • Q2
    • Object Oriented Programming
    • File handling
    • mark scheme 错误:
      1. g问要求的colour无视大小写, mark scheme给出的答案是把input的colour全大写或者小写,但后面对比的时候仍然用的是.equals()直接与pictArray[i].getColour()进行对比。设想当pictArray[i].getColour() 为”Silver” 而input的colour为全大写或全小写时 “SILVER” “silver”; 这时候对比就不是equal的了。有两种解决方案
        1. pictArray[i].getColour()也对应的全大写或全小写
        2. 运用 .equalsIgnoreCase()方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.*;
import java.io.*;
public class papei_9618_w21_41_Q2 {
static Integer numberOfPictures;
public static void main(String[] args) {
Picture[] pictArray = new Picture[100];
ReadData(pictArray);
Scanner sca = new Scanner(System.in);
System.out.println("Now, try to input the requirements");
System.out.println("Input the colour of frame");
String colourOfFrame=sca.nextLine();
System.out.println("Input the maximum width");
Integer maxWid=Integer.parseInt(sca.nextLine());
System.out.println("Input the maximum height");
Integer maxHei=Integer.parseInt(sca.nextLine());
for(int i=0;i<numberOfPictures;++i) {
if(pictArray[i].getColour().equalsIgnoreCase(colourOfFrame) && pictArray[i].GetHeight()<=maxHei && pictArray[i].GetWidth()<=maxWid) {
System.out.println("found:\n"+pictArray[i].GetDescription()+" width: "+pictArray[i].GetWidth()+" Height: "+pictArray[i].GetHeight());
}
}
}
public static Integer ReadData(Picture[] pictArray) {
String readData;
String Description,Width,Height,FrameColour;
numberOfPictures=0;
try {
String fileName="Pictures.txt";
File fi = new File(fileName);
FileReader fr = new FileReader(fi);
BufferedReader bfr = new BufferedReader(fr);
readData=bfr.readLine();
while(readData!=null) {
Description=readData;
Width=bfr.readLine();
Height=bfr.readLine();
FrameColour=bfr.readLine();
pictArray[numberOfPictures]=new Picture(Description, Integer.parseInt(Width), Integer.parseInt(Height), FrameColour);
numberOfPictures++;
readData=bfr.readLine();
}
bfr.close();
fr.close();
}catch(FileNotFoundException e) {
System.out.println("File not found");
}catch (IOException e) {
System.out.println("File not found");
}
return numberOfPictures;
}

}
class Picture{
private String Description;
private Integer Width;
private Integer Height;
private String FrameColour;
public Picture(String Desc, Integer Wid, Integer Hei, String Fra) {
this.Description=Desc;
this.Width=Wid;
this.Height=Hei;
this.FrameColour=Fra;
}
public String GetDescription() {
return this.Description;
}
public Integer GetWidth() {
return this.Width;
}
public Integer GetHeight() {
return this.Height;
}
public String getColour(){
return this.FrameColour;
}
public void SetDescription(String fra) {
this.FrameColour=fra;
}
}
  • Q3
    • Binary tree
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.*;
import java.io.*;

public class papei_9618_w21_41_Q3 {
static Integer RootPointer = -1;
static Integer FreeNode =0;
public static void main(String[] args) {
Integer[][] ArrayNodes = new Integer[20][3];
//10 5 15 8 12 6 20 11 9 4
AddNode(ArrayNodes);
AddNode(ArrayNodes);
AddNode(ArrayNodes);
AddNode(ArrayNodes);
AddNode(ArrayNodes);
AddNode(ArrayNodes);
AddNode(ArrayNodes);
AddNode(ArrayNodes);
AddNode(ArrayNodes);
AddNode(ArrayNodes);
InOrder(0,ArrayNodes);
}
public static void AddNode(Integer[][] ArrayNodes) {
System.out.println("Enter the data");
Integer NodeData;
Scanner sca = new Scanner(System.in);
NodeData = sca.nextInt();
if(FreeNode<=19) {
ArrayNodes[FreeNode][0] = -1;
ArrayNodes[FreeNode][1] = NodeData;
ArrayNodes[FreeNode][2] = -1;
if(RootPointer==-1) {
RootPointer=0;
}
else {
Boolean placed=false;
Integer nownode=RootPointer;
while(placed==false) {
if(NodeData<ArrayNodes[nownode][1]) {
if(ArrayNodes[nownode][0]==-1) {
ArrayNodes[nownode][0]=FreeNode;
placed=true;
}
else {
nownode=ArrayNodes[nownode][0];
}
}
else {
if(ArrayNodes[nownode][2]==-1) {
ArrayNodes[nownode][2]=FreeNode;
placed=true;
}
else {
nownode=ArrayNodes[nownode][2];
}
}
}
}
FreeNode++;
}
else {
System.out.println("Unable to add node, tree is full");
}
}

public static void PrintAll(Integer[][] ArrayNodes) {
for(int i=0;i<20;++i) {
System.out.println(ArrayNodes[i][0]+" "+ArrayNodes[i][1]+" "+ArrayNodes[i][2]);
}
}
public static void InOrder(Integer nowNode,Integer[][] ArrayNodes) {
if(ArrayNodes[nowNode][0]!=-1) {
InOrder(ArrayNodes[nowNode][0],ArrayNodes);
}
System.out.println(ArrayNodes[nowNode][1]);
if(ArrayNodes[nowNode][2]!=-1) {
InOrder(ArrayNodes[nowNode][2],ArrayNodes);
}

}

}

Y21-4

  • Q1
    • Insertion sort
    • Linear search
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.*;
import java.io.*;
public class papei_9618_y21_4_Q1 {

public static void main(String[] args) {
int[] TheData = {20,3,4,8,12,99,4,26,4};
// System.out.println("the data before sorting");
// printContent(TheData);
// InsertionSort(TheData);
// System.out.println("the data after sorting");
// printContent(TheData);
search(TheData);
}
public static void InsertionSort(int[] TheData) {
for(int Count=1;Count<TheData.length;++Count) {
int DataToInsert=TheData[Count];
int Inserted=0;
int NextValue=Count-1;
while(NextValue>=0 && Inserted!=1) {
if(DataToInsert<TheData[NextValue]) {
TheData[NextValue+1]=TheData[NextValue];
NextValue--;
TheData[NextValue+1]=DataToInsert;
}
else {
Inserted=1;
}
}
}
}
public static void printContent(int[] TheData) {
for(int i=0;i<TheData.length;++i) {
System.out.print("At index: "+i+" :");
System.out.println(TheData[i]);
}
}
public static Boolean search(int[] TheData) {
Scanner sca = new Scanner(System.in);
System.out.println("Input the data that you want to search:");
int searchData=sca.nextInt();
for(int i=0;i<TheData.length;++i) {
if(TheData[i]==searchData) {
System.out.println("found");
return true;
}
}
System.out.println("not found");
return false;
}

}
  • Q2
    • Object Oriented Programming
      • inheritance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;

public class papei_9618_y21_4_Q2 {
static int boxNum;
public static void main(String[] args) {
HiddenBox[] TheBoxes=new HiddenBox[10000];
NewBox(TheBoxes);
}
public static void NewBox(HiddenBox[] TheBoxes) {
Scanner sca = new Scanner(System.in);
System.out.println("input name");
String name = sca.nextLine();
System.out.println("input creator");
String creator = sca.nextLine();
System.out.println("input datehidden");
String datehidden = sca.nextLine();
System.out.println("input gamelocation");
String gamelocation=sca.nextLine();
TheBoxes[boxNum]=new HiddenBox(name, creator, datehidden, gamelocation);
boxNum++;
}

}

class HiddenBox{
private String BoxName;
private String Creator;
private String DateHidden;
private String GameLocation;
private String[][] LastFinds;
private Boolean Active;
public HiddenBox(String boxp,String creap,String datep,String gamep) {
this.BoxName=boxp;
this.Creator=creap;
this.DateHidden=datep;
this.GameLocation=gamep;
this.Active=false;
for(int i=0;i<10;++i) {
for(int j=0;j<2;++j) {
this.LastFinds[i][j]="";
}
}
}
public String GetBoxName() {
return this.BoxName;
}
public String GetGameLocation() {
return this.GameLocation;
}
}

class PuzzleBox extends HiddenBox{
String PuzzleText;
String Solution;
public PuzzleBox(String name, String creator, String date, String location,String Puzzle,String solu) {
super(name,creator,date,location);
this.PuzzleText=Puzzle;
this.Solution= solu;
}
}
  • Q3
    • Queue
    • File handling
    • Exception handling
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class papei_9618_y21_4_Q3 {
static int startPointer=0;
static int endPointer=0;
public static void main(String[] args) {
String[] QueueData = new String[20];
int ans = ReadFile(QueueData);
if(ans==-1) {
System.out.println("file not found");
}
else if(ans==1) {
System.out.println("queue is full and not all data could be inserted");
}
else {
System.out.println("successfully added");
}
}
public static Boolean Enqueue(String item,String[] QueueData){
if(endPointer==20) {
return false;
}
else {
QueueData[endPointer]=item;
endPointer++;
return true;
}
}
public static String Remove(String[] QueueData) {
if(endPointer-startPointer>1) {
String ans=QueueData[startPointer]+" "+QueueData[startPointer+1];
startPointer+=2;
return ans;
}
else {
return "No items";
}
}

public static int ReadFile(String[] QueueData) {
Scanner sca = new Scanner(System.in);
System.out.println("input file name");
String fileName = sca.nextLine();
File fi = new File(fileName);
if(fi.exists()) {
try {
FileReader fr = new FileReader(fi);
BufferedReader bfr = new BufferedReader(fr);
String dataRead=bfr.readLine();
Boolean flag=true;
while(dataRead!=null && flag) {
flag=Enqueue(dataRead, QueueData);
dataRead=bfr.readLine();
}
bfr.close();
fr.close();
if(!flag) {
return 1;
}
else {
return 2;
}
}catch(FileNotFoundException e) {
return -1;
}catch(IOException e) {
return -1;
}
}
else {
return -1;
}
}

}

9608

S21-42

  • Q4
    • circular queue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class papei_9608_s21_42_Q4 {
static int HeadIndex;
static int TailIndex;
static int NumberInQueue;
static int[] MyNumbers= new int[10];
public static void main(String[] args) {

}
public static Boolean Enqueue(Integer DataToInsert) {
if(NumberInQueue>9) {
return false;
}
else {
MyNumbers[TailIndex]=DataToInsert;
TailIndex=TailIndex+1;
if(TailIndex>9) {
TailIndex=0;
}
NumberInQueue+=1;
return true;
}

}
public static Integer Dequeue() {
if(NumberInQueue==0) {
return -1;
}
else {
Integer ans=MyNumbers[HeadIndex];
HeadIndex++;
if(HeadIndex>9) {
HeadIndex=0;
}
NumberInQueue--;
return ans;
}
}
}

S18-42

  • Q5:
    • Object Oriented Programming
      • inheritance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

public class papei_9608_s18_41_Q5 {

public static void main(String[] args) {
Scenery GiftBox = new Scenery(150, 150, 50, 75, "box.png", true, 50);
}

}

class GameElement{
private Integer PositionX;
private Integer PositionY;
private Integer Width;
private Integer Height;
private String ImageFilename;
public GameElement(Integer Posx, Integer PosY, Integer Wid, Integer Hei, String imgfn) {
this.PositionX=Posx;
this.PositionY=PosY;
this.Width=Wid;
this.Height=Hei;
this.ImageFilename=imgfn;
}
public String GetDetails() {
String message="PositionX: "+this.PositionX+" PositionY: "+this.PositionY+" Width: "+this.Width+" Height: "+this.Height+" ImageFileName: "+this.ImageFilename;
return message;
}
}

class Scenery extends GameElement{
private Boolean CauseDamage;
private Integer DamagePoints;
public Scenery(Integer Posx, Integer PosY, Integer Wid, Integer Hei, String imgfn, Boolean Caus,Integer DamaP) {
super(Posx, PosY, Wid, Hei, imgfn);
this.CauseDamage=Caus;
this.DamagePoints=DamaP;
}
public Integer GiveDamagePoints() {
if(this.CauseDamage) {
return this.DamagePoints;
}
else {
return 0;
}
}
public String GetScenery() {
String message=super.GetDetails()+" CauseDamage: "+this.CauseDamage+" DamagedPoints: "+this.DamagePoints;
return message;
}
}