SlideShare a Scribd company logo
2
Q-14 Given a non-negative int n, return the sum of its digits recursively (no loops). Note that mod
(%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost
digit (126 / 10 is 12).
*Q-15 Given a non-negative int n, return the count of the occurrences of 7 as a digit, so for
example 717 yields 2. (no loops). Note that mod (%) by 10 yields the rightmost digit (126 % 10 is
6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12).
Q-16 Write a program to find the number of and sum of all integers greater than 200 that are
divisible by 7.
*Q-17 Given any number, write a program using while loop to reverse the digits of the number.
Q-18 Write a program to determine the sum of the following harmonic series for a given value of
n:
1+1/2+1/3+ ----- +1/n The value of n should be given interactively through the keyboard.
*Q-19 Write a program that computes the area of a triangle. The sides of triangle should be given
interactively through the keyboard.
*Q-20 Write a program to sort any list of given numbers.
*Q-21 Write a program to add two 3 by 3 matrices.
Day 4, 5, 6: Inheritance programming techniques
Q-22 Write a java code to find the distance from Ranchi to major cities of India.
Hint: Create an String array of major cities and integer array of distances. User
gives the city name and the same is searched (use binary search) in the respective
array and displays result.
Q-23 Write a Patient class which inherits from the Person class. You may also need to
use the Money class. The Patient class requires the following:
• a variable to store the patient number for the patient
• a variable to store the hospital
• a variable to store the patient 's year of joining the hospital
• a variable to store the patient 's address
• a variable to store the medical fees that the patient pays
• constructor methods, which initialise the variables
• methods to set the hospital , year of joining and address
• methods to get the hospital, year of joining and address
• a method to calculate the medical fees : It should take a Money object (the basic fee per
year) as a parameter and use it to return the basic fee for the patient. A patient should
pay the basic fee for the year of R 1200, 50.
• a toString method
Q-24: a. Explain the difference between early and late/dynamic binding.
b. Which keyword can be used to indicate that a method cannot be overridden with
Most read
3
a new definition in a derived class?
c. Give the code for an abstract method called getArea() that calculates and returns
the area of a shape as a double.
Q-25: A small company dealing with transportation has just purchased a computer for
its new automated reservations system. You have been asked to program the new
system. You are to write a program called ReservationSystem to assign seats on a
vehicle. Your class also requires the following:
a constructor method, which initialise the variables
a method to assign the capacity of seating.
a method for assigning seats. Use a 1-d array to represent the seating chart of the plane.
Initialize all the elements of the array to 0 to indicate that all the seats are empty. As
each seat is assigned, set the corresponding elements of the array to 1 to indicate that
the seat is no longer available. Your program should, of course never assign a seat that
has already been assigned.
appropriate mutator and accessor methods
The company also needs a program dealing especially with its only plane with each
flight having a capacity of 10 seats. Name this class AirlineReservationSystem. This
class is a type of ReservationSystem but the way it reserves seats are different.
Your program should display the following menu of alternatives for reserving a seat on
the flight:
Please type 1 for “smoking”
Please type 2 for “non-smoking”
If the person types 1,then your program should assign a seat in the smoking
section(seats 1-5) If the person types 2,then your program should assign a seat in the
non-smoking section(seats 6-10). Your program should then print a boarding pass
indicating the person’s seat number and whether it is in the smoking or non-smoking
section of the plane.
When the smoking section is full, your program should ask the person if it is
acceptable to be placed in the non-smoking section (and vice versa). If yes, then make
the appropriate seat assignment. If no, then print the message “Next flight leaves in 3
hours.”
Create a main() method to test the next scheduled flight.
Q-26:
• Create a superclass, Student, and two subclasses, Undergrad and Grad.
• The superclass Student should have the following data members: name, ID, grade, age,
and address.
• The superclass, Student should have at least one method: boolean isPassed (double
grade)
Most read
4
The purpose of the isPassed method is to take one parameter, grade (value between 0 and
100) and check whether the grade has passed the requirement for passing a course. In the
Student class this method should be empty as an abstract method.
• The two subclasses, Grad and Undergrad, will inherit all data members of the Student
class and override the method isPassed. For the UnderGrad class, if the grade is above
70.0, then isPassed returns true, otherwise it returns false. For the Grad class, if the
grade is above 80.0, then isPassed returns true, otherwise returns false.
• Create a test class for your three classes. In the test class, create one Grad object and
one Undergrad object. For each object, provide a grade and display the results of the
isPassed method.
Q-27: a. How do you use the scope of class members and methods to hide information
from other classes?
b. When should you use inheritance programming techniques to solve problems?
c. What are the benefits of using inheritance? To save time? Shorter programs?
d. Java can deal with single inheritance (one superclass with multiple subclasses). How
can a class inherit from more than one superclass (multiple inheritances)?
Q-28: Create an applet program for Banner; banner text (Your Roll No.) should be
passed as parameter. This applet creates a thread that scrolls the message
contained in message right to left across the applet's window & also uses status
window.
Q-29: Create an applet program for Menu demonstration. Menu bar should contain
File, Edit, View and its submenus.
Q-30: Create Labels (One, Two & Three), add Buttons (Yes, No, Undecided) when
user click any button show message regarding user click, add
Checkboxes(Windows 98/XP, Windows NT/2000) when user chose any
checkbox show message regarding user choice & add text boxes (name,
password) and text on these textboxes should be displayed on Panel.
Q-31: Draw colour lines, Rectangle, Filled Rectangle, Rounded Rectangle, Filled
Rounded Rectangle, Oval, Filled oval, arc, fill arc, & polygon every drawing
shape should be in different colour, Write a text “hello everyone” at the center.
Q-32: Create an applet program for key events it should recognize normal as well as
special keys & should be displayed on the panel.
Q-33: Create an applet program for mouse events it should recognize mouse entry, exit,
and its coordinates.
Tip: When a web page is to be developed, the following are to be planned:
1. Content of the page
2. Appearance of the page
Appearance of the page is coded in HTML using HTML tags.
Most read
JAVA PROGRAMMING LAB ASSIGNMENTS
Q-1 The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are
on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
Q-2 Given two int values, return their sum. Unless the two values are the same, then return double
their sum.
Q-3 Given an int n, return the absolute difference between n and 21, except return double the
absolute difference if n is over 21.
*Q-4 Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.
*Q-5 Given 2 int values, return true if one is negative and one is positive. Unless negative is true,
then they both must be negative.
Q-6 Given a string, return a new string where the first and last chars have been exchanged.
frontBack("code") → "eodc"
frontBack("a") → "a"
frontBack("ab") → "ba"
Q-7 Given a string, take the last char and return a new string with the last char added at the front
and back, so "cat" yields "tcatt". The original string will be length 1 or more.
backAround("cat") → "tcatt"
backAround("Hello") → "oHelloo"
backAround("a") → "aaa"
*Q-8 Given a string, return true if the string starts with "hi" and false otherwise.
Q-9 Given three int values, A B C, return the largest.
Q-10 Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or
return 0 if neither is in that range.
*Q-11 Given a string, return a new string where the last 3 chars are now in upper case. If the string
has less than 3 chars, uppercase whatever is there. Note that str.toUpperCase() returns the
uppercase version of a string.
Q-12 Given n of 1 or more, return the factorial of n, which is n * (n-1) * (n-2) ... 1. Compute the
result recursively (without loops).
Q-13 The fibonacci sequence is a famous bit of mathematics, and it happens to have a recursive
definition. The first two values in the sequence are 0 and 1 (essentially 2 base cases). Each
subsequent value is the sum of the previous two values, so the whole sequence is: 0, 1, 1, 2, 3, 5, 8,
13, 21 and so on. Define a recursive fibonacci(n) method that returns the nth fibonacci number,
with n=0 representing the start of the sequence.
Q-14 Given a non-negative int n, return the sum of its digits recursively (no loops). Note that mod
(%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost
digit (126 / 10 is 12).
*Q-15 Given a non-negative int n, return the count of the occurrences of 7 as a digit, so for
example 717 yields 2. (no loops). Note that mod (%) by 10 yields the rightmost digit (126 % 10 is
6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12).
Q-16 Write a program to find the number of and sum of all integers greater than 200 that are
divisible by 7.
*Q-17 Given any number, write a program using while loop to reverse the digits of the number.
Q-18 Write a program to determine the sum of the following harmonic series for a given value of
n:
1+1/2+1/3+ ----- +1/n The value of n should be given interactively through the keyboard.
*Q-19 Write a program that computes the area of a triangle. The sides of triangle should be given
interactively through the keyboard.
*Q-20 Write a program to sort any list of given numbers.
*Q-21 Write a program to add two 3 by 3 matrices.
Day 4, 5, 6: Inheritance programming techniques
Q-22 Write a java code to find the distance from Ranchi to major cities of India.
Hint: Create an String array of major cities and integer array of distances. User
gives the city name and the same is searched (use binary search) in the respective
array and displays result.
Q-23 Write a Patient class which inherits from the Person class. You may also need to
use the Money class. The Patient class requires the following:
• a variable to store the patient number for the patient
• a variable to store the hospital
• a variable to store the patient 's year of joining the hospital
• a variable to store the patient 's address
• a variable to store the medical fees that the patient pays
• constructor methods, which initialise the variables
• methods to set the hospital , year of joining and address
• methods to get the hospital, year of joining and address
• a method to calculate the medical fees : It should take a Money object (the basic fee per
year) as a parameter and use it to return the basic fee for the patient. A patient should
pay the basic fee for the year of R 1200, 50.
• a toString method
Q-24: a. Explain the difference between early and late/dynamic binding.
b. Which keyword can be used to indicate that a method cannot be overridden with
a new definition in a derived class?
c. Give the code for an abstract method called getArea() that calculates and returns
the area of a shape as a double.
Q-25: A small company dealing with transportation has just purchased a computer for
its new automated reservations system. You have been asked to program the new
system. You are to write a program called ReservationSystem to assign seats on a
vehicle. Your class also requires the following:
a constructor method, which initialise the variables
a method to assign the capacity of seating.
a method for assigning seats. Use a 1-d array to represent the seating chart of the plane.
Initialize all the elements of the array to 0 to indicate that all the seats are empty. As
each seat is assigned, set the corresponding elements of the array to 1 to indicate that
the seat is no longer available. Your program should, of course never assign a seat that
has already been assigned.
appropriate mutator and accessor methods
The company also needs a program dealing especially with its only plane with each
flight having a capacity of 10 seats. Name this class AirlineReservationSystem. This
class is a type of ReservationSystem but the way it reserves seats are different.
Your program should display the following menu of alternatives for reserving a seat on
the flight:
Please type 1 for “smoking”
Please type 2 for “non-smoking”
If the person types 1,then your program should assign a seat in the smoking
section(seats 1-5) If the person types 2,then your program should assign a seat in the
non-smoking section(seats 6-10). Your program should then print a boarding pass
indicating the person’s seat number and whether it is in the smoking or non-smoking
section of the plane.
When the smoking section is full, your program should ask the person if it is
acceptable to be placed in the non-smoking section (and vice versa). If yes, then make
the appropriate seat assignment. If no, then print the message “Next flight leaves in 3
hours.”
Create a main() method to test the next scheduled flight.
Q-26:
• Create a superclass, Student, and two subclasses, Undergrad and Grad.
• The superclass Student should have the following data members: name, ID, grade, age,
and address.
• The superclass, Student should have at least one method: boolean isPassed (double
grade)
The purpose of the isPassed method is to take one parameter, grade (value between 0 and
100) and check whether the grade has passed the requirement for passing a course. In the
Student class this method should be empty as an abstract method.
• The two subclasses, Grad and Undergrad, will inherit all data members of the Student
class and override the method isPassed. For the UnderGrad class, if the grade is above
70.0, then isPassed returns true, otherwise it returns false. For the Grad class, if the
grade is above 80.0, then isPassed returns true, otherwise returns false.
• Create a test class for your three classes. In the test class, create one Grad object and
one Undergrad object. For each object, provide a grade and display the results of the
isPassed method.
Q-27: a. How do you use the scope of class members and methods to hide information
from other classes?
b. When should you use inheritance programming techniques to solve problems?
c. What are the benefits of using inheritance? To save time? Shorter programs?
d. Java can deal with single inheritance (one superclass with multiple subclasses). How
can a class inherit from more than one superclass (multiple inheritances)?
Q-28: Create an applet program for Banner; banner text (Your Roll No.) should be
passed as parameter. This applet creates a thread that scrolls the message
contained in message right to left across the applet's window & also uses status
window.
Q-29: Create an applet program for Menu demonstration. Menu bar should contain
File, Edit, View and its submenus.
Q-30: Create Labels (One, Two & Three), add Buttons (Yes, No, Undecided) when
user click any button show message regarding user click, add
Checkboxes(Windows 98/XP, Windows NT/2000) when user chose any
checkbox show message regarding user choice & add text boxes (name,
password) and text on these textboxes should be displayed on Panel.
Q-31: Draw colour lines, Rectangle, Filled Rectangle, Rounded Rectangle, Filled
Rounded Rectangle, Oval, Filled oval, arc, fill arc, & polygon every drawing
shape should be in different colour, Write a text “hello everyone” at the center.
Q-32: Create an applet program for key events it should recognize normal as well as
special keys & should be displayed on the panel.
Q-33: Create an applet program for mouse events it should recognize mouse entry, exit,
and its coordinates.
Tip: When a web page is to be developed, the following are to be planned:
1. Content of the page
2. Appearance of the page
Appearance of the page is coded in HTML using HTML tags.
Q-34: Design a HTML page (web page) describing your profile in one paragraph.
Design in such a way that it has a heading, a horizontal rule, three links and a
photo of your institution. Also, write three HTML documents for the links.
Q-35: Prepare a HTML page listing popular car companies. For each company prepare
a sub-list showing various brands of cars it offers.
Q-36: Write a HTML document to draw the following table.
Prices of flats in Chennai 2006
Area Type of house Rate in
rupees/sq. ft.
Annanagar
Ordinary 1800
Delux 1950
Adyar
Ordinary 2450
Delux 2775
Egmore
Ordinary 2000
Delux 2125
Q-37: Write a HTML document/page that has 3 frames. The window must be row
wise divided into two frames first and the bottom frame is divided into two
frames column wise.
Q-38: Write a HTML document showing a password field. When password is
entered, the asterisk symbols must be displayed in place of password in the
input field.
Q-39: Design the following form using HTML.
Q-40: Write HTML/Javascript code for the page showing check boxes, text box and
submit button. The user selects the check box(es) and once the user clicks
submit button the selected check box items appear in the text box.
Q-41: Write HTML/Javascript code for the page showing currency conversion. The
user enters the amount in rupees in the text box and selects a patrticular radio
button for the currency conversion. On checking it must display the amount
in the corresponding currency.
Q-42: Write HTML/Javascript code for the page showing a select box and a text box.
The select box contains a list of names. When the user selects a name from
the select box the corresponding phone number appears in the phone number
Application for Admission
Name
DOB
O Male
O Female
SUBMIT
input box.
Q-43: Write HTML/Javascript code for the page having three text boxes and a
submit button. The three text boxes are email id, age and name. The email id
text box has to contain @ symbol, age should be greater than 1 and less than
or equal to 100 and name should not exceed 10 characters. If the email id
doesnot contain @ symbol an alert message is fired. Similarly for age and
name the corresponfing alert message is fired.
JAVA Assignment
1. Create a new Java class named Car that has the following fields
o year - The year field is an int that holds a car's year model (e.g.
2010)
o make - The make field is a String object that holds the make of
the car (e.g. "Porsche")
o speed - The speed field is an double that holds a car's current
speed (e.g. 25.0)
In addition, the Car class should have the following methods.
o Constructor - The constructor should accept the car's year, make,
and beginning speed as arguments
 These values should be used to initialize the Car's year,
make, and speed fields
o Getter Methods - Write three accessor (getter) methods to get the
values stored in an object's fields
 getYear(), getMake(), getSpeed()
o accelerate - Write an accelerate method that has no arguments
(parameters) passed to it and adds 1 to the speed field each time it
is called
 For example: if the car was going 3 mph, accelerate would set
the speed to 4 mph
Write a main method that uses your Car class
1. Write a separate Java class RaceTrack in file RaceTrack.java with
a main method that uses your Car class
o Save the class in file RaceTrack.java in folder U:labslab5
2. Inside RaceTrack class' main method
o Create a new Car object (using the Car constructor method), passing
in the year, make, and speed
o Display the current status of the car object using
the getter methods getYear(), getMake(), and getSpeed()
o Call the car's accelerate method and then re-display the car's speed
using getSpeed()
o
3. Create a new Java file named Pay.java with following variables
double hoursWorked,double hourlyPayRate,double grossPay;
calculate gross salary as below
hoursworked <=40 then calculate
hoursWorked * hourlyPayRate
otherwise calculated as below
hoursWorked) * (1.5 * hourlyPayRate));
While the Pay program may now calculate gross pay correctly, in the real
world, nothing can be said to be certain except death and taxes. Assume
that the tax man takes a flat 33% of gross wages as taxes.
4. Write a program that calculates how much a person would earn over a
period of time if his or her yearly salary begins at $1,000.00 the first
year, $2,000.00 the second year, and continues to double each
year.Add a running total to your program to keep track of their total
pay received over the years.Display the total pay and average salary
received
5 . Create a class as per the requirement whih Convert the starting time in
hours and minutes to the equivalent total_minutes
o For example: 2 hours and 30 minutes would be 150 total minutes
o For example: 5 hours and 15 minutes would be 315 total minutes
o Hint: use multiplication and addition
Write down the math formula needed to calculate the ending time (in total
minutes) given the starting time (in total minutes) and the duration (in
minutes).
endingTime (in total minutes) = write out the formula
Convert the ending time in total minutes back to hours and minutes
with / and % integer operators and the fact that one hour is 60 minutes
o For example, 63 minutes is 1 hour and 3 minutes
o For example, 125 minutes is 2 hours and 5 minutes
o For example, 325 minutes is 5 hours and 25 minutes
On the Lab 3 assignment sheet, write down the math formula needed to
calculate the ending hour and minutes given the ending time (in total minutes).
Note: at this point, assume simple military time for the end hours. So
12:50 plus 30 minutes would be 13:20
endingHour = write out the formula
endingMinutes = write out the formula
EndingTime.java
Write the Java program EndingTime.java that calculates the ending time (in
hours and minutes), given a starting time (in hours and minutes) and a
duration (in minutes).
Sample Session
Enter the starting time (in hours and minutes): 2 30
Enter the duration (in minutes): 125
Ending hour is 4
Ending minute is 35
6. Write a Java program named NameMaker.java with the String
variables firstName, middleName, lastName, and fullName. Prompt the user
to enter their first, middle, and last names and read the names from
the keyboard. Use string concatenation to set and display their fullName as
firstName + a blank char + middleName + a blank char + lastName
Also Use String methods to
o Display their initials
o Display their full name in all uppercase letters
o Display their full name in all lowercase letters
o Display the number of characters in their full name, including
blank spaces
7. Write a LandTract Java class that holds a tract's length and width (as
doubles)
• Write the class constructor method that accepts two double
arguments, one for the track's length and one for the width
• Write the getArea method that returns the tract's area
o area = length * width
• Write an equals method that accepts a LandTract object as the
parameter and returns true if the two tracks have the same area,
otherwise false
8. Body mass index (BMI) is a measure of body fat based on height and weight
that applies to adult men and women. BMI can be used to indicate if you are
overweight, obese, underweight or normal.
Women tend to believe they look their best at BMI values between 20 to 22
and men are usually satisfied with a BMI of 23 to 25.
If your BMI is 30 or more, that's not good. However, the simple BMI calculation
tends to overestimate BMI in people who are muscular or athletic. Therefore, if
your BMI score seems too high, you're not too fat, your just too athletic.
BMI is calculated based on a person's weight and height. The math formula for
calculating BMI is shown at right
Simple BMI categories include
• Underweight when BMI is less than 18.5
• Normal weight when BMI is between 18.5 and 25
• Overweight when BMI is between 25 and 30
• Too Muscular (Obese) when BMI is 30 or greater
Now Write the Java program that
o Declares variables used in the program
o Creates a Scanner object
o Gets the user's weight (in pounds) and height (in inches)
o Calculates their Body Mass Index (BMI)
o Displays the results

More Related Content

What's hot (20)

PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
Parthipan Parthi
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
Vaishnavee Sharma
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kengatharaiyer Sarveswaran
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
Aamir Sohail
 
Pointer in c
Pointer in cPointer in c
Pointer in c
lavanya marichamy
 
Dictionary
DictionaryDictionary
Dictionary
Pooja B S
 
Python PPT
Python PPTPython PPT
Python PPT
Edureka!
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
Sajid Marwat
 
머신러닝과 사이킷런의 이해
머신러닝과 사이킷런의 이해머신러닝과 사이킷런의 이해
머신러닝과 사이킷런의 이해
철민 권
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Namespaces
NamespacesNamespaces
Namespaces
Sangeetha S
 
Data warehouse architecture
Data warehouse architecture Data warehouse architecture
Data warehouse architecture
janani thirupathi
 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
 
Data Structure - Elementary Data Organization
Data Structure - Elementary  Data Organization Data Structure - Elementary  Data Organization
Data Structure - Elementary Data Organization
Uma mohan
 
Xml databases
Xml databasesXml databases
Xml databases
Srinivasan R
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
sana mateen
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
Vaishnavee Sharma
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
Aamir Sohail
 
Python PPT
Python PPTPython PPT
Python PPT
Edureka!
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
Sajid Marwat
 
머신러닝과 사이킷런의 이해
머신러닝과 사이킷런의 이해머신러닝과 사이킷런의 이해
머신러닝과 사이킷런의 이해
철민 권
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Data warehouse architecture
Data warehouse architecture Data warehouse architecture
Data warehouse architecture
janani thirupathi
 
Data Structure - Elementary Data Organization
Data Structure - Elementary  Data Organization Data Structure - Elementary  Data Organization
Data Structure - Elementary Data Organization
Uma mohan
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
sana mateen
 

Viewers also liked (20)

Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
Mumbai Academisc
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
Java Notes
Java NotesJava Notes
Java Notes
Abhishek Khune
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)
akmalfahmi
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
trupti1976
 
Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]
Abdullah khawar
 
Apclass
ApclassApclass
Apclass
geishaannealagos
 
Apclass (2)
Apclass (2)Apclass (2)
Apclass (2)
geishaannealagos
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ Program
Deepak Singh
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo Bergavera
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 
Loop c++
Loop c++Loop c++
Loop c++
Mood Mood
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
Appili Vamsi Krishna
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
Structure in c
Structure in cStructure in c
Structure in c
baabtra.com - No. 1 supplier of quality freshers
 
Ad

Similar to Java programming lab assignments (20)

Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
heyenyestey1s
 
Object oriented programming -QuestionBank
Object oriented programming -QuestionBankObject oriented programming -QuestionBank
Object oriented programming -QuestionBank
Parameshwar Maddela
 
Java codes
Java codesJava codes
Java codes
Hussain Sherwani
 
Lab exam question_paper
Lab exam question_paperLab exam question_paper
Lab exam question_paper
Kuntal Bhowmick
 
CBSE 12 ip 2018 sample paper
CBSE 12 ip 2018 sample paperCBSE 12 ip 2018 sample paper
CBSE 12 ip 2018 sample paper
Knowledge Center Computer
 
Practical java
Practical javaPractical java
Practical java
nirmit
 
JAVA practical Exam Questions (1).docx
JAVA practical Exam Questions (1).docxJAVA practical Exam Questions (1).docx
JAVA practical Exam Questions (1).docx
Lucky Ally
 
Week 5
Week 5Week 5
Week 5
EasyStudy3
 
Week 5
Week 5Week 5
Week 5
EasyStudy3
 
Exercise 1 [10 points]Write a static method named numUniq.docx
Exercise 1 [10 points]Write a static method named numUniq.docxExercise 1 [10 points]Write a static method named numUniq.docx
Exercise 1 [10 points]Write a static method named numUniq.docx
rhetttrevannion
 
Lab exam question_paper
Lab exam question_paperLab exam question_paper
Lab exam question_paper
Kuntal Bhowmick
 
Exercise1 java
Exercise1 javaExercise1 java
Exercise1 java
NguynMinh294
 
202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.
sukeshsuresh189
 
22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...
sukeshsuresh189
 
17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...
sukeshsuresh189
 
7: Assume the following class declaration.
7: Assume the following class declaration.7: Assume the following class declaration.
7: Assume the following class declaration.
sukeshsuresh189
 
3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.
sukeshsuresh189
 
10: In the Java graphics system, coordinate units are measured in ________.
10: In the Java graphics system, coordinate units are measured in ________.10: In the Java graphics system, coordinate units are measured in ________.
10: In the Java graphics system, coordinate units are measured in ________.
sukeshsuresh189
 
19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...
sukeshsuresh189
 
18: Which of the following does not generate an event?
18: Which of the following does not generate an event?18: Which of the following does not generate an event?
18: Which of the following does not generate an event?
sukeshsuresh189
 
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
heyenyestey1s
 
Object oriented programming -QuestionBank
Object oriented programming -QuestionBankObject oriented programming -QuestionBank
Object oriented programming -QuestionBank
Parameshwar Maddela
 
Practical java
Practical javaPractical java
Practical java
nirmit
 
JAVA practical Exam Questions (1).docx
JAVA practical Exam Questions (1).docxJAVA practical Exam Questions (1).docx
JAVA practical Exam Questions (1).docx
Lucky Ally
 
Exercise 1 [10 points]Write a static method named numUniq.docx
Exercise 1 [10 points]Write a static method named numUniq.docxExercise 1 [10 points]Write a static method named numUniq.docx
Exercise 1 [10 points]Write a static method named numUniq.docx
rhetttrevannion
 
202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.
sukeshsuresh189
 
22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...
sukeshsuresh189
 
17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...
sukeshsuresh189
 
7: Assume the following class declaration.
7: Assume the following class declaration.7: Assume the following class declaration.
7: Assume the following class declaration.
sukeshsuresh189
 
3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.
sukeshsuresh189
 
10: In the Java graphics system, coordinate units are measured in ________.
10: In the Java graphics system, coordinate units are measured in ________.10: In the Java graphics system, coordinate units are measured in ________.
10: In the Java graphics system, coordinate units are measured in ________.
sukeshsuresh189
 
19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...
sukeshsuresh189
 
18: Which of the following does not generate an event?
18: Which of the following does not generate an event?18: Which of the following does not generate an event?
18: Which of the following does not generate an event?
sukeshsuresh189
 
Ad

Recently uploaded (20)

How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
la storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglesela storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglese
LetiziaLucente
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
la storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglesela storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglese
LetiziaLucente
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 

Java programming lab assignments

  • 1. JAVA PROGRAMMING LAB ASSIGNMENTS Q-1 The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in. Q-2 Given two int values, return their sum. Unless the two values are the same, then return double their sum. Q-3 Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21. *Q-4 Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10. *Q-5 Given 2 int values, return true if one is negative and one is positive. Unless negative is true, then they both must be negative. Q-6 Given a string, return a new string where the first and last chars have been exchanged. frontBack("code") → "eodc" frontBack("a") → "a" frontBack("ab") → "ba" Q-7 Given a string, take the last char and return a new string with the last char added at the front and back, so "cat" yields "tcatt". The original string will be length 1 or more. backAround("cat") → "tcatt" backAround("Hello") → "oHelloo" backAround("a") → "aaa" *Q-8 Given a string, return true if the string starts with "hi" and false otherwise. Q-9 Given three int values, A B C, return the largest. Q-10 Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range. *Q-11 Given a string, return a new string where the last 3 chars are now in upper case. If the string has less than 3 chars, uppercase whatever is there. Note that str.toUpperCase() returns the uppercase version of a string. Q-12 Given n of 1 or more, return the factorial of n, which is n * (n-1) * (n-2) ... 1. Compute the result recursively (without loops). Q-13 The fibonacci sequence is a famous bit of mathematics, and it happens to have a recursive definition. The first two values in the sequence are 0 and 1 (essentially 2 base cases). Each subsequent value is the sum of the previous two values, so the whole sequence is: 0, 1, 1, 2, 3, 5, 8, 13, 21 and so on. Define a recursive fibonacci(n) method that returns the nth fibonacci number, with n=0 representing the start of the sequence.
  • 2. Q-14 Given a non-negative int n, return the sum of its digits recursively (no loops). Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12). *Q-15 Given a non-negative int n, return the count of the occurrences of 7 as a digit, so for example 717 yields 2. (no loops). Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12). Q-16 Write a program to find the number of and sum of all integers greater than 200 that are divisible by 7. *Q-17 Given any number, write a program using while loop to reverse the digits of the number. Q-18 Write a program to determine the sum of the following harmonic series for a given value of n: 1+1/2+1/3+ ----- +1/n The value of n should be given interactively through the keyboard. *Q-19 Write a program that computes the area of a triangle. The sides of triangle should be given interactively through the keyboard. *Q-20 Write a program to sort any list of given numbers. *Q-21 Write a program to add two 3 by 3 matrices. Day 4, 5, 6: Inheritance programming techniques Q-22 Write a java code to find the distance from Ranchi to major cities of India. Hint: Create an String array of major cities and integer array of distances. User gives the city name and the same is searched (use binary search) in the respective array and displays result. Q-23 Write a Patient class which inherits from the Person class. You may also need to use the Money class. The Patient class requires the following: • a variable to store the patient number for the patient • a variable to store the hospital • a variable to store the patient 's year of joining the hospital • a variable to store the patient 's address • a variable to store the medical fees that the patient pays • constructor methods, which initialise the variables • methods to set the hospital , year of joining and address • methods to get the hospital, year of joining and address • a method to calculate the medical fees : It should take a Money object (the basic fee per year) as a parameter and use it to return the basic fee for the patient. A patient should pay the basic fee for the year of R 1200, 50. • a toString method Q-24: a. Explain the difference between early and late/dynamic binding. b. Which keyword can be used to indicate that a method cannot be overridden with
  • 3. a new definition in a derived class? c. Give the code for an abstract method called getArea() that calculates and returns the area of a shape as a double. Q-25: A small company dealing with transportation has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program called ReservationSystem to assign seats on a vehicle. Your class also requires the following: a constructor method, which initialise the variables a method to assign the capacity of seating. a method for assigning seats. Use a 1-d array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all the seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available. Your program should, of course never assign a seat that has already been assigned. appropriate mutator and accessor methods The company also needs a program dealing especially with its only plane with each flight having a capacity of 10 seats. Name this class AirlineReservationSystem. This class is a type of ReservationSystem but the way it reserves seats are different. Your program should display the following menu of alternatives for reserving a seat on the flight: Please type 1 for “smoking” Please type 2 for “non-smoking” If the person types 1,then your program should assign a seat in the smoking section(seats 1-5) If the person types 2,then your program should assign a seat in the non-smoking section(seats 6-10). Your program should then print a boarding pass indicating the person’s seat number and whether it is in the smoking or non-smoking section of the plane. When the smoking section is full, your program should ask the person if it is acceptable to be placed in the non-smoking section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message “Next flight leaves in 3 hours.” Create a main() method to test the next scheduled flight. Q-26: • Create a superclass, Student, and two subclasses, Undergrad and Grad. • The superclass Student should have the following data members: name, ID, grade, age, and address. • The superclass, Student should have at least one method: boolean isPassed (double grade)
  • 4. The purpose of the isPassed method is to take one parameter, grade (value between 0 and 100) and check whether the grade has passed the requirement for passing a course. In the Student class this method should be empty as an abstract method. • The two subclasses, Grad and Undergrad, will inherit all data members of the Student class and override the method isPassed. For the UnderGrad class, if the grade is above 70.0, then isPassed returns true, otherwise it returns false. For the Grad class, if the grade is above 80.0, then isPassed returns true, otherwise returns false. • Create a test class for your three classes. In the test class, create one Grad object and one Undergrad object. For each object, provide a grade and display the results of the isPassed method. Q-27: a. How do you use the scope of class members and methods to hide information from other classes? b. When should you use inheritance programming techniques to solve problems? c. What are the benefits of using inheritance? To save time? Shorter programs? d. Java can deal with single inheritance (one superclass with multiple subclasses). How can a class inherit from more than one superclass (multiple inheritances)? Q-28: Create an applet program for Banner; banner text (Your Roll No.) should be passed as parameter. This applet creates a thread that scrolls the message contained in message right to left across the applet's window & also uses status window. Q-29: Create an applet program for Menu demonstration. Menu bar should contain File, Edit, View and its submenus. Q-30: Create Labels (One, Two & Three), add Buttons (Yes, No, Undecided) when user click any button show message regarding user click, add Checkboxes(Windows 98/XP, Windows NT/2000) when user chose any checkbox show message regarding user choice & add text boxes (name, password) and text on these textboxes should be displayed on Panel. Q-31: Draw colour lines, Rectangle, Filled Rectangle, Rounded Rectangle, Filled Rounded Rectangle, Oval, Filled oval, arc, fill arc, & polygon every drawing shape should be in different colour, Write a text “hello everyone” at the center. Q-32: Create an applet program for key events it should recognize normal as well as special keys & should be displayed on the panel. Q-33: Create an applet program for mouse events it should recognize mouse entry, exit, and its coordinates. Tip: When a web page is to be developed, the following are to be planned: 1. Content of the page 2. Appearance of the page Appearance of the page is coded in HTML using HTML tags.
  • 5. Q-34: Design a HTML page (web page) describing your profile in one paragraph. Design in such a way that it has a heading, a horizontal rule, three links and a photo of your institution. Also, write three HTML documents for the links. Q-35: Prepare a HTML page listing popular car companies. For each company prepare a sub-list showing various brands of cars it offers. Q-36: Write a HTML document to draw the following table. Prices of flats in Chennai 2006 Area Type of house Rate in rupees/sq. ft. Annanagar Ordinary 1800 Delux 1950 Adyar Ordinary 2450 Delux 2775 Egmore Ordinary 2000 Delux 2125 Q-37: Write a HTML document/page that has 3 frames. The window must be row wise divided into two frames first and the bottom frame is divided into two frames column wise. Q-38: Write a HTML document showing a password field. When password is entered, the asterisk symbols must be displayed in place of password in the input field. Q-39: Design the following form using HTML. Q-40: Write HTML/Javascript code for the page showing check boxes, text box and submit button. The user selects the check box(es) and once the user clicks submit button the selected check box items appear in the text box. Q-41: Write HTML/Javascript code for the page showing currency conversion. The user enters the amount in rupees in the text box and selects a patrticular radio button for the currency conversion. On checking it must display the amount in the corresponding currency. Q-42: Write HTML/Javascript code for the page showing a select box and a text box. The select box contains a list of names. When the user selects a name from the select box the corresponding phone number appears in the phone number Application for Admission Name DOB O Male O Female SUBMIT
  • 6. input box. Q-43: Write HTML/Javascript code for the page having three text boxes and a submit button. The three text boxes are email id, age and name. The email id text box has to contain @ symbol, age should be greater than 1 and less than or equal to 100 and name should not exceed 10 characters. If the email id doesnot contain @ symbol an alert message is fired. Similarly for age and name the corresponfing alert message is fired.
  • 7. JAVA Assignment 1. Create a new Java class named Car that has the following fields o year - The year field is an int that holds a car's year model (e.g. 2010) o make - The make field is a String object that holds the make of the car (e.g. "Porsche") o speed - The speed field is an double that holds a car's current speed (e.g. 25.0) In addition, the Car class should have the following methods. o Constructor - The constructor should accept the car's year, make, and beginning speed as arguments  These values should be used to initialize the Car's year, make, and speed fields o Getter Methods - Write three accessor (getter) methods to get the values stored in an object's fields  getYear(), getMake(), getSpeed() o accelerate - Write an accelerate method that has no arguments (parameters) passed to it and adds 1 to the speed field each time it is called  For example: if the car was going 3 mph, accelerate would set the speed to 4 mph Write a main method that uses your Car class 1. Write a separate Java class RaceTrack in file RaceTrack.java with a main method that uses your Car class o Save the class in file RaceTrack.java in folder U:labslab5 2. Inside RaceTrack class' main method o Create a new Car object (using the Car constructor method), passing in the year, make, and speed o Display the current status of the car object using the getter methods getYear(), getMake(), and getSpeed() o Call the car's accelerate method and then re-display the car's speed using getSpeed() o 3. Create a new Java file named Pay.java with following variables double hoursWorked,double hourlyPayRate,double grossPay; calculate gross salary as below
  • 8. hoursworked <=40 then calculate hoursWorked * hourlyPayRate otherwise calculated as below hoursWorked) * (1.5 * hourlyPayRate)); While the Pay program may now calculate gross pay correctly, in the real world, nothing can be said to be certain except death and taxes. Assume that the tax man takes a flat 33% of gross wages as taxes. 4. Write a program that calculates how much a person would earn over a period of time if his or her yearly salary begins at $1,000.00 the first year, $2,000.00 the second year, and continues to double each year.Add a running total to your program to keep track of their total pay received over the years.Display the total pay and average salary received 5 . Create a class as per the requirement whih Convert the starting time in hours and minutes to the equivalent total_minutes o For example: 2 hours and 30 minutes would be 150 total minutes o For example: 5 hours and 15 minutes would be 315 total minutes o Hint: use multiplication and addition Write down the math formula needed to calculate the ending time (in total minutes) given the starting time (in total minutes) and the duration (in minutes). endingTime (in total minutes) = write out the formula Convert the ending time in total minutes back to hours and minutes with / and % integer operators and the fact that one hour is 60 minutes o For example, 63 minutes is 1 hour and 3 minutes o For example, 125 minutes is 2 hours and 5 minutes o For example, 325 minutes is 5 hours and 25 minutes On the Lab 3 assignment sheet, write down the math formula needed to calculate the ending hour and minutes given the ending time (in total minutes). Note: at this point, assume simple military time for the end hours. So 12:50 plus 30 minutes would be 13:20 endingHour = write out the formula
  • 9. endingMinutes = write out the formula EndingTime.java Write the Java program EndingTime.java that calculates the ending time (in hours and minutes), given a starting time (in hours and minutes) and a duration (in minutes). Sample Session Enter the starting time (in hours and minutes): 2 30 Enter the duration (in minutes): 125 Ending hour is 4 Ending minute is 35 6. Write a Java program named NameMaker.java with the String variables firstName, middleName, lastName, and fullName. Prompt the user to enter their first, middle, and last names and read the names from the keyboard. Use string concatenation to set and display their fullName as firstName + a blank char + middleName + a blank char + lastName Also Use String methods to o Display their initials o Display their full name in all uppercase letters o Display their full name in all lowercase letters o Display the number of characters in their full name, including blank spaces 7. Write a LandTract Java class that holds a tract's length and width (as doubles) • Write the class constructor method that accepts two double arguments, one for the track's length and one for the width • Write the getArea method that returns the tract's area o area = length * width • Write an equals method that accepts a LandTract object as the parameter and returns true if the two tracks have the same area, otherwise false
  • 10. 8. Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women. BMI can be used to indicate if you are overweight, obese, underweight or normal. Women tend to believe they look their best at BMI values between 20 to 22 and men are usually satisfied with a BMI of 23 to 25. If your BMI is 30 or more, that's not good. However, the simple BMI calculation tends to overestimate BMI in people who are muscular or athletic. Therefore, if your BMI score seems too high, you're not too fat, your just too athletic. BMI is calculated based on a person's weight and height. The math formula for calculating BMI is shown at right Simple BMI categories include • Underweight when BMI is less than 18.5 • Normal weight when BMI is between 18.5 and 25 • Overweight when BMI is between 25 and 30 • Too Muscular (Obese) when BMI is 30 or greater Now Write the Java program that o Declares variables used in the program o Creates a Scanner object o Gets the user's weight (in pounds) and height (in inches) o Calculates their Body Mass Index (BMI) o Displays the results