Assignment on Computer Science and IT Department

Added on - 09 Oct 2019

  • 3

    pages

  • 1065

    words

  • 14

    views

  • 0

    downloads

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;ship.name = ‘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
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Unlock This Document