· web viewst brendan’s. computer science. transition task. 2019. a’ level computer science...

26
St Brendan’s A’ level Computer Science Transition task Summer 2019 page 1 of 16 St Brendan’s Computer Science Transition task 2019

Upload: vodang

Post on 29-Jun-2019

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 1 of 16

St Brendan’sComputer ScienceTransition task2019

Page 2:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 2 of 16

A’ level Computer Science at St Brendan’sThe computer science course at St Brendan’s follows the AQA syllabus and consists of both theory and practical work. The theory work material is largely covered by a textbook. Practical work uses the Java programming language. For more details on the whole course see: Welcome to Computer Science 2019.ppt

Introduction to Java

Java Basics – do not worry if you do not understand this section fully (you can do all the work below without it)Programming languages are typically written using text, called source code, using a text editor and translated, using a compiler or interpreter, into executable machine language object code which runs on specific platforms (machine types). Unlike many other programming languages Java source code is first translated (compiled) into byte code which is the same for different platforms. The Java Virtual Machine (JVM) is software that translates (interprets) and executes byte code on a particular platform. Byte code canbe thought of as machine language for the JVM software machine. The JVM allows Java source code to be translated to byte code that is the same for different machines (platform independent).

Java source code is held in .java files and compiled into byte code in .class files for the JVM to execute.[see h tt p ://c h o rtle.ccs u .ed u / j a v a 5 / N o tes/c h a p 0 5 /ch0 5 _ 1 . h t m l to ch05_5.html for more detail]

Java ProgrammingIn order to run a Java program the Java Runtime Environment (JRE) is required. In order to write a Java program a Java Development Kit (JDK) is required.

An Integrated Development Environment (IDE) is useful software to help develop Java programs. Popular IDEs for Java are IntelliJ, Eclipse, Netbeans, and BlueJ. In the firstyear at St Brendan’s we use BlueJ mostly.

Software installationUse the guidance in the next few pages to download and install the latest BlueJ IDE (containing the appropriate Java SE JDK).

Page 3:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 3 of 16

1 Download and install BlueJ this automatically installs Java (JDK ) also. From http://www.bluej.org/ download BlueJ 4 latest version (currently 4.1.2)For windows operating system your progress should be as follows (based on old screenshots):

2 Simple program using BlueJWe shall now use the BlueJ IDE to develop a simple Java program to say ‘Hello’. Note: latest BlueJ may look slightly different.

In BlueJ select: Project – New Project. Create a project ‘Transition project’ in a suitable location - Create – New Class – type HelloWorld for class name - Ok.

NB: Java is case sensitive

Double click to type code

Double click the HelloWorld class to open the code edit window (or right click – Open Editor).

Page 4:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 4 of 16

Delete all the example code and type in the HelloWorld code as shown below, but with your own name after author (and not anything in the dashed rectangles which are notes to help you).

Class name must be exactly the same as file name

Java multi line comment

Displays Hello World message

Java single line comments start with //

Don’t worry about this line – just that it is needed for now

Note: Java comments do not affect how a program runs but are used to help a programmer Indent code to help readability (does not affect compilation / execution): use Edit - Auto-layout Semi colon ; curly brackets {, } round brackets (, ) and square brackets [, ] must be used

correctly and are NOT interchangeable. To see line numbers (in the code editor): Options – preferences – display line numbers. BlueJ reference site: http://www.bluej.org/

Click compile (you should get ‘Class compiled - no syntax errors’ - otherwise check lines 5 to 11 are correctly typed – Java is case sensitive, and remember curly brackets and semicolon – Java is fussy!

Close the editor.Right click the HelloWorld class Select void main(String[] args) Select OkThe terminal window should contain“Hello World!” as output as shown:

{Note:It is possible to write Java using a normaltext editor, and compile and run java programs using the Java SDK without need for an IDE such as BlueJ by using the command line interface. You are not required to do so, but if you are interested to do this, see C ho r tle ch a pter 7 or YouTube tutorial 2 running Java: h tt p :// w w w . y ou t ub e.c o m / w atch ? v= 5 u8 r Fbpd vd s& f eat ur e=f v w r el .}

youTube reference links for installing BlueJ and a HelloWorld program, zaychenok Java Lesson 1&2: http://www.youtube.co m / watch ? v=aqQefkprf3 s , http://www.youtube.co m / watch ? v =l9nHHCgXBMk&feature=related

Now you are ready to start work. Allow at least 12 hours to complete the work that follows.

Page 5:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

a output5 5

a output8 7

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 5 of 16

3 User input using Scanner with BlueJType this code carefully into BlueJ.Now run as a program in BlueJ and test with data.

Note: it can be helpful in debugging a program to add a breakpoint and examine how your program behaves from that breakpoint line by line. For an example on adding a breakpoint see video: https://www.youtube.co m / watch ? v=Q625 R ZTc1Ho

4 Pseudocode tracePseudocode is a way of describing an algorithm without using a specific programming language. A trace is a way of checking an algorithm by working through line by line of an algorithm and keeping track of each relevant value. In the A’ level course you will be expected to use both.Trace 1The pseudocode below is traced for input value 5 and then for input value 8

Pseudocode Trace table for input value 5:

INPUT aIF a MOD 2 is 1

OUTPUT aELSE

OUTPUT a – 1END IF

Trace table for input value 8:

Where MOD means remainder.For example 13 MOD 5 is 3 because when 13 is divided by 5 the remainder is 3.

Youtube recording for this example: www.youtube.com/ watch? v=PSpm9 d2kq_o

The purpose of this pseudocode is: to output an odd number that is the same as the input number, if the input is odd, or one lower than the input number if the input is even.

Page 6:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 6 of 16

Trace 2

Consider the pseudocode in the box alongside:

Note:The pseudocode contains a loop starting atline 6: ‘FOR i is 3 to n’ and ending at the line 11: ‘END FOR LOOP’.This means lines 7 to 10 are repeated (in the order: 7, 8, 9, 10, 7, 8, 9, 10 . . . etc.)

This loop is controlled by stepper variable, i, which starts with a value of 3 and at the end of

1 SET sum to 02 SET v1 and v2 to 13 OUTPUT v14 OUTPUT v25 READ IN the value of n6 FOR i is 3 to n7 sum ← v1 + v28 v1 ← v29 v2 ← sum

10 OUTPUT sum11 END FOR LOOP

Lines 7 to 10 repeated for values of i from 3 to n

each iteration is increased by one until in the final iteration it reaches a value of n.

Suppose the algorithm is traced with variable n having a value read in of 10. We produce a trace by considering and tracking the values of each variable: n, i, sum, v1, v2 and what is output as we work through the pseudocode one line at a time (repeating lines 7 to 10 for each value of i).

n i sum v1 v2 output0 1 1 1

110 3 2 1 2 2

4 3 2 3 35 5 3 5 56 8 5 8 87 13 8 13 138 21 13 21 219 34 21 34 3410 55 34 55 55

Notice: the table shows n stays as 10 all the way through i has values 3,4, . . . , 10 v1 and v2 start with value 1 when i is 3, the value of sum is set to 2, v1 is set to 1 (again), v2 to 2 and 2 is printed out when i is 4, the value of sum is set to 3, v1 changes to 2, v2 to 3 and 3 is printed out etc

HELP:See video on how to fill in this trace table: www.youtube.com/watch? v=ycdcDYl7yd4

When tracing an algorithm make sure you work through carefully one line at a time and do not worry about the purpose of the algorithm until you have finished.

The purpose of this algorithm is to print out the first n values of the Fibonacci sequence. Research the Fibonacci sequence and check if the algorithm works for other values of n.

I think this algorithm should work fine for most whole number values of n. But what about values less than 2 (n = 1 or 0 or a negative). We can rewrite the algorithm so that it will better cope with n being 1 or less by printing out the correct number or giving an error message.

Page 7:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 7 of 16

Java Work – do this before attempting Java exercises (or after you get stuck!)Make sure you have completed sections 1-4 of this booklet.Go to chortle site http://chortle.ccsu.edu/CS151/cs151java.ht m l or use mirror site http://programmedlessons.org/java5/index.ht m l . Go through chapters 8 – 11 and do as many exercises and quizzes as you need. Set aside at least six hours to work through these chapters and more if you do more than a few of the exercises. After chapters 8 – 9c attempt question 1 below (filling in answers 01 to 03). After chapters 10 – 11 attempt question 2, 3 and 4 below (filling in answers 04 to 11).

Useful links to go with chortle reading above and help with exercises to follow below:Basic BlueJ program www . yout u be.com/watch?v=-Pt2cl3lfmI Use of Scanner www.youtube.co m /watch ? v=c E wVhv_ J W 1 A Bucky tutorials (use Eclipse IDE instead of BlueJ but otherwise are relevant)

Java Programming Tutorial - 6 - Getting User Inputhttp://www.youtube.com/watch?v=5DdacOkrTgo&feature=relmfu

Java Programming Tutorial - 7 - Building a Basic Calculatorhttp://www. youtub e.com/watch?v=2MjKu UT Xa4o

StBrendan (use BlueJ Scanner with integer division and remainder useful for que 2)https://www.youtube.co m / w atch ? v =pcyIU7RRSmA

Code academy – learn Java (units 1 and 2 – free stuff only – also try code in BlueJ)www.codecademy.c o m www.codecademy.com/learn/learn-java

Type your answers to the exercises below in your Electronic Answer Document. You must save this document at regular intervals.

Question 1Create a class Exercise1 with the code below (you can type in or copy and paste):public class Exercise1{

public static void main (String[] args){

double km = 40, miles miles = km * 5 / 8;System.println(km + " kilometres is " + miles + " miles");

}//end main}//end class

(a) The program has two compilation errors. Correct these.What you need to do

Modify the program so that it so the program compiles and runs

Evidence that you need to provideInclude the following in your Electronic Answer Document.

0 1 Your corrected PROGRAM SOURCE CODE. (2 marks)

0 2 SCREEN CAPTURE of program output in terminal window (1 mark)

(tip: see EAD front sheet for help on pasting screenshots into EAD)

(b) (i) replace miles = km * 5 / 8; by miles = 5.0 / 8 * km; compile and run(ii) replace miles = 5.0 / 8 * km; by miles = 5 / 8 * km; compile and run

0 3 Explain fully the results obtained in running versions b(i) and (ii). To gain full marks you will need to note the relevance of data types (Chortle chp 8, 9B) (2 marks)

Page 8:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 8 of 16

Question 2Create a class Exercise2 with the code below:

import java.util.Scanner; //package needed to read from keyboard public class Exercise2{

public static void main (String[] args){

//declare Scanner and integer variablesScanner sc = new Scanner(System.in);int allMonths, years, partMonths;

//ask for age in monthsSystem.out.print("Age in months: ");

//set allMonths to value typed in//code here

//calculate years from allMonths//code here//calculate partMonths from allMonths//code here

//display message about calculated years and months//code here

}//end main}//end class

Currently the program prompts the user for a number of months but does not yet calculate and output how many years and months this is equivalent to. For example when the user types an input of 40 the program output should be:

Age in months: 4040 months = 3 years and 4 months

What you need to doModify the program so that for an input number of months the whole years and months are calculated and displayed

Test your program with age values in months as follows.Test 1: 8Test 2: 48Test 3: 47

Evidence that you need to provideInclude the following in your Electronic Answer Document.

0 4 Your completed PROGRAM SOURCE CODE. (6 marks)

0 5 SCREEN CAPTURE for Test 1 (1 mark)

0 6 SCREEN CAPTURE for Test 2 (1 mark)

0 7 SCREEN CAPTURE for Test 3 (1 mark)

Page 9:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 9 of 16

Question 3Create a class PizzaCost with the code below:

Currently the program prompts the user for how many share a pizza but the pizza price is set at £10.95 and does not allow a user to input a pizza price or the number of pizzas.

What you need to doModify the program so that the user is prompted for the number of pizzas and the price of each pizza as well as how many people are sharing and outputs the amount each person has to pay foran equal share. Do not worry about thenumber of decimal places in your answer – this will be dealt with later.

Test your program as follows.Test: 4 pizzas, £8.50 for each pizza and 8 people sharing

Evidence that you need to provideInclude the following in your Electronic Answer Document.

0 8 Your completed PROGRAM SOURCE CODE. (5 marks)

0 9 SCREEN CAPTURE for the test (2 marks)

Page 10:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 10 of 16

Question 4Create a class BillChange class with the code below:

This program contains 3 errors: 2 syntax errors and 1 semantic error. Note: the decimal formatting used will round the decimal number to two decimal places

What you need to doTASK A: Modify the program to calculate the change for a payment

of a random bill (up to £100). An example is shown here.

Test: Test your program with an appropriate payment for your random bill.

Evidence that you need to provideInclude the following in your Electronic Answer Document.

1 0 Your completed PROGRAM SOURCE CODE. (3 marks)

1 1 SCREEN CAPTURE for Test (1 mark)

Page 11:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 11 of 16

Question 5aCreate a class SwapUsingTeacup class with the code below:

What you need to doModify the above program to swap the values held in variables x and y by making use of thevariable temp (do not just print other way round).The variable temp used in the swap issometimes called a teacup. An example output is shown here.

Test: Test your program with the initial values5 and 7 in x and y

Evidence that you need to provideInclude the following in your Electronic Answer Document.

1 2 Your completed PROGRAM SOURCE CODE. (2 marks)

1 3 SCREEN CAPTURE for Test (1 mark)

Page 12:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 12 of 16

Question 5bCreate a class SwapWithoutTeacup class with the code below:

What you need to doModify the program to swap the values held in variables x and y by only making use of variablesx and y (and not creating/using any other variables). An example output is shown here.

Test: Test your program with the initial values 12and -5 in x and y

Evidence that you need to provideInclude the following in your Electronic Answer Document.

1 4 Your completed PROGRAM SOURCE CODE. (2 marks)

1 5 SCREEN CAPTURE for Test (1 mark)

Page 13:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

a b output8 2

a b output3 7

n x s output4 0

1

n x s output8 0

1

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 13 of 16

Question 6 a (review traces on page 5 and 6 of this booklet before trying this question)Trace the pseudocode of an algorithm.Consider the pseudocode shown in the box alongside:

What you need to doComplete the trace below with input values: a is 8 and b is 2. Copy your answers to the Electronic Answer Document (EAD)

1 6

INPUT a and bIF a > b THEN

OUTPUT a – bELSE

OUTPUT b – aEND IF

(1 mark)

Fill in the trace below with a input as 3 and b as 7 and copy to your EAD

1 7(1 mark)

1 8 State the purpose of this algorithm? (1 mark)

Question 6 bTrace the pseudocode of an algorithm.Consider the pseudocode shown in the box alongside:

What you need to doComplete the trace below with input values: n is 4.Copy your answers to the Electronic Answer Document (EAD)

1 9

INPUT nSET s to 0FOR x is 1 to n

IF x MOD 2 is 0 s ← s + x

END IFEND FOR LOOP OUTPUT s

(2 marks)

Fill in the trace below with n input as 8 and copy to your EAD

2 0

(2 marks)

2 1 State the purpose of this algorithm? (1 mark)

Note: MOD calculates the remainder (what is left) from integer division. For example17 MOD 5 is 2

You may want to code these to check your answers (but you are not required to do so).

Page 14:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 14 of 16

Theory workSet aside about five hours to work through the tutorial chapters below.

Read through http://ch or tle. c csu.edu/java5/index.ht m l chapters 1 to 4. Try the quizzes and flashcards. Then work through the rest of the questions below.Note Chortle does NOT use binary prefix so you also need a little extra research for question 10.You may need to search the web for help with question 7.

Type your answers to the exercises below in your Electronic Answer Document. You must save this document at regular intervals.

Question 7

2 2 Tejinder knows he needs to find the shortest route from Bath to Milton Keynes. Mary knows Dijkstra’s algorithm/method for finding the shortest path between any two locations. State and explain which person has imperative knowledge and whichperson has declarative knowledge in this situation. (1 mark)

2 3 Two students want to sum up the integer variables x and y using Java.James writes int z = x + y and forgets to place a semicolon at the end of the statementMiranda writes int z = x – y; and has wrongly put a minus instead of a plus. Both have made errors. State and explain who has made a syntax error and who has made a semantic error

(1 mark)

Question 8 (based on Chortle Chapter 1)

2 4 Explain what bus refers to for a computer system (1 mark)

2 5 Main Memory (RAM) is volatile but Secondary Memory (also called secondarystorage or auxiliary storage) is not. Explain what volatile means. (1 mark)

2 6 Where are programs and data kept for long-term storage (when computer isswitched off)? (1 mark)

2 7 Where is a program and its data kept whilst the program runs (from wheresmall chunks are then fetched into the processor to be executed)? (1 mark)

Question 9 (based on Chortle Chapter 2)

2 8 Explain what bit stands for and what it means. (1 mark)

2 9 What does one Hertz mean? (1 mark)Question 10 (based on Chortle Chapter 3 + binary prefix research)For this question also investigate binary prefix as defined by the US National Institute of Standards and Technology and in particular the meaning of kibibyte, mebibyte and gibibyte. NOTE: Chortle does NOT cover this and you should NOT rely on GCSE knowledge for this – so look up each binary prefix in Wikipedia (for examplehttps://en.wikip e dia.or g /wiki/Ki b i b y t e ).

Page 15:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 15 of 16

3 0 How many bits are there in one byte? (1 mark)

3 1 What are 220 bytes and 230 bytes (using binary prefix) called respectively? (1 mark)

3 2 A particular digital image is 1024 rows by 1024 columns, and each location (pixel) is represented by 24 bits. How many mebibytes are needed to store this image? (1 mark)

3 3 How many bytes can a 64-bit processor read from (or write to) memory at one time? (1mark)

Question 11 (based on Chortle Chapter 4)

3 4 Is Java a high or low-level programming language? (1 mark)

3 5 Software X is used to translate the whole source code of a high-level language program and saves it to a binary (machine code) file that can then be run later. Which type of translator is software X - a compiler or an interpreter? (1 mark)

Systematic counting exampleThree students have a total of 15 chocolates. Each student has a different odd number of chocolates. There are three combinations of possible number of chocolates each student has:

1, 3, 11 1, 5, 9 3, 5, 7

Four students have a total of 22 chocolates. Each student has a different odd number of chocolates. There are three combinations of possible number of chocolates each student has:

1, 3, 5, 13 1, 3, 7, 11 1, 5, 7, 9

Question 12 (systematic counting questions)

3 6 Three students have a total of 17 chocolates. Each student has a different odd number of chocolates. How many chocolates can each student have? Give all possible combinations

(1 mark)

3 7 Three students have a total of 19 chocolates. Each student has a different odd number of chocolates. How many chocolates can each student have? Give all possible combinations

(1 mark)

3 8 Three students have a total of 21 chocolates. Each student has a different odd number of chocolates. How many chocolates can each student have if each has more than 1?Give all possible combinations (1 mark)

3 9 Four students have a total of 24 chocolates. Each student has a different odd number of chocolates. How many chocolates can each student have? Give all possible combinations

(1 mark)

4 0 Four students have a total of 28 chocolates. Each student has a different even number of chocolates. How many chocolates can each student have?Give all possible combinations (1 mark)

Page 16:   · Web viewSt Brendan’s. Computer Science. Transition task. 2019. A’ level Computer Science at St Brendan’s. The computer science course at St Brendan’s follows the AQA

St Brendan’s A’ level Computer Science Transition task Summer 2019

page 16 of 16

End of questions

Please complete the feedback survey at the end of the EAD

Optional extras,

Computer science fundamentals: Joy of logic: https://www.youtube.com/watch?v=ZO UZ6iV0A CS50 introduction Harvard https://www.youtube.com/watch?v=y62zj9ozPOM

The future? Ubiquitous computing: Youtube (BBC4) Mi c hio Kaku - The Intelli g ence Rev o lution Jobs: TED talk: Andrew Mcafee - future jobs