St Brendan’s as computer Science Summer task Summer 2016 St Brendan’s Computer Science Summer task


Useful links to go with chortle reading above and help with exercises to follow below



Download 1.82 Mb.
Page9/10
Date28.05.2018
Size1.82 Mb.
#51383
1   2   3   4   5   6   7   8   9   10

Useful links to go with chortle reading above and help with exercises to follow below:

Basic BlueJ program www.youtube.com/watch?v=-Pt2cl3lfmI

Use of Scanner www.youtube.com/watch?v=cEwVhv_JW1A

Bucky tutorials (use Eclipse IDE instead of BlueJ but otherwise are relevant)

Java Programming Tutorial - 6 - Getting User Input

http://www.youtube.com/watch?v=5DdacOkrTgo&feature=relmfu

(OR on the new boston: http://thenewboston.org/watch.php?cat=31&number=6 etc)

Java Programming Tutorial - 7 - Building a Basic Calculator

http://www.youtube.com/watch?v=2MjKuUTXa4o
StBrendan (use BlueJ Scanner with integer division and remainder useful for que 2)

https://www.youtube.com/watch?v=pcyIU7RRSmA

Code academy – learn Java (units 1 and 2 – free stuff only – also try code in BlueJ)

www.codecademy.com 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 1

Create 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 = 30, 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 provide

Include the following in your Electronic Answer Document.


Your corrected PROGRAM SOURCE CODE. (2 marks)
SCREEN CAPTURE of program output in terminal window (1 mark)


0 1



0 2

(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)

Question 2

Create 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 variables

Scanner sc = new Scanner(System.in);

int allMonths, years, partMonths;

//ask for age in months

System.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: 40

40 months = 3 years and 4 months

What you need to do

Modify 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: 9

Test 2: 24

Test 3: 47

Evidence that you need to provide

Include the following in your Electronic Answer Document.


Your completed PROGRAM SOURCE CODE. (6 marks)
SCREEN CAPTURE for Test 1 (1 mark)
SCREEN CAPTURE for Test 2 (1 mark)
SCREEN CAPTURE for Test 3 (1 mark)



0 4



0 5




0 6



0 7


Question 3

Create 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 do

Modify 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 for an equal share. Do not worry about the number 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 provide

Include the following in your Electronic Answer Document.


Your completed PROGRAM SOURCE CODE. (5 marks)
SCREEN CAPTURE for the test (2 marks)



0 8



0 9

Question 4

Create 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

Download 1.82 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   10




The database is protected by copyright ©ininet.org 2024
send message

    Main page