Assignment on Computer Science and IT Department

Added on - 09 Oct 2019

  • 3


  • 1065


  • 135


  • 0


Trusted by +2 million users,
1000+ happy students everyday
Showing pages 1 to 1 of 3 pages
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:_______________________________IDNo: _______________ Section___Q1: Following program segments have logical/syntactical errors. Identify the errors and correctit. 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 attributesof 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; = ‘Royal Navy’;}ii.Developerextends the program of Ship to make sure that all ships must have some position x, y and speed = 0initially.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 iton 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
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document