Oop Lab Session 6
Oop Lab Session 6
Q1) You are required to design a class that represents sections of courses in university. Each
section has a number that represents the course ID, the number of students registered in the
section, and a maximum number of registered students allowed. All sections should have the
same maximum number of registered students allowed. All data fields should be
encapsulated. In addition, your class should provide methods to update the number of
students registered when a new student is registered and when a student drops the course.
SOURCE CODE
public class Lab6 {
else{
else{
System.out.println("no seats left in this section/course")}} public int drop2(){
else{
OUTPUT
Q2) For this problem you will complete a class named Flight. public class Flight {
• Default Constructor: It initializes the object using the values 2, “STAFF”, and 10.
• The sample output below can help you verify the functionality of some of the
o Captain: Nerdson
o Passengers:
o Yulu
o Justin
SOURCE CODE
package flight1; public class Flight1 {
captain=c_name;
this(2,"STAFF",10);
}
void addPassenger(String PN,String pn, String kn,String ln, String mn){ p_name=PN;
public int getNO(){ return flightNumber;} public String getName(){ return captain;}
obj.addPassenger("Bakhtawar","Sana","Jaweria","Ummul Qura","none");
System.out.println("Flight Number: "+obj.getNO()); System.out.println("Captain:
"+obj.getName()); System.out.println("Maximum number of seats: "+obj.getSeats());
System.out.println("passengers: ");
OUTPUT
Q3) Create a class Number with only one private instance variable as a double primitive type.
Include a default constructor which initializes an instance variable to 0.0. The class should
have the following methods:
• isZero( )
• isPositive()
• isNegative( )
• isOdd( )
• isEven( )
The above methods return Boolean primitive type. Write a driver class NumberTest to test
constructor and each method in the class.
SOURCE CODE
public class Number { double num;
return false;}}
if(num>0){
return false;}}
return false;}}
return false;}}
return false;}}}
public class NumberTest {
System.out.println(obj.isZero(0)); System.out.println(obj.isPositive(-2));
System.out.println(obj.isNegative(-4)); System.out.println(obj.isOdd(4));
System.out.println(obj.isEven(6));}}
OUTPUT