logo

Assignment on Computer Science and IT Department

3 Pages1065 Words235 Views
   

Added on  2019-10-09

Assignment on Computer Science and IT Department

   Added on 2019-10-09

ShareRelated Documents
King Faisal UniversityComputer Science BS ProgramCollege of Computer Science and ITDepartment of Computer Science1439/1440H – 2018/2019OOPII: Assignment 1, Due date: 11 Feb 2019Student Name:_______________________________ID No: _______________ Section___Q1: Following program segments have logical/syntactical errors. Identify the errors and correct it. The correction should fulfills the intended objectives of the program.i.The program segments represents Ship and its usage. The program objectives is to expose some attributes of Ship such as x, y and speed with principal of information hiding.public class Ship{private double x, y, speed;public String name;}public class ShipTest{Ship1 ship = new Ship();ship.x = 1.0;ship.y = 2.0;ship.name = ‘Royal Navy’;}ii.Developer extends the program of Ship to make sure that all ships must have some position x, y and speed = 0 initially.public class Ship{private double x, y, speed;public String name;private Ship( x, y ){ x = x; y = y;}}public class ShipTest{Ship1 ship = new Ship(2.0, 3.0);Ship.speed = 0;}iii.Keeping objectives mentioned in i), ii), developer now want to set attributes of ship3, ship4 and display it on screen.public class ShipTest{Ship ship3 = new Ship(2.0, 3.0);ship.speed = 0;Ship ship4 = new Ship();ship4.x = 5.0;ship4.y = 6.0;ship.speed = 350;System.out.println(Ship3: (x,y,Speed): + ship3.x + “,” + ship3.y + “,” + ship3.speed);}Output:Ship3:(x,y,Speed): 2.0, 3.0, 0Ship4:(x,y,Speed): 5.0, 6.0, 350.0
Assignment on Computer Science and IT Department_1

End of preview

Want to access all the pages? Upload your documents or become a member.