Академический Документы
Профессиональный Документы
Культура Документы
Date: 24/8/2019
1. Write a program to demonstrate the knowledge of students in basic Java concepts.
Eg., Write a program to read the First name and Last name of a person, his weight and
height using command line arguments. Calculate the BMI Index which is defined as the
individual's body mass divided by the square of their height.
Category BMI Range-Kg/m2
Underweight <18.5
Normal (healthy weight) 18.5 to 25
Overweight 25 to 30
Obese Class Over 30
Display the name and display his category based on the BMI value thus calculated.
CODE:-
import java.io.*;
import java.util.Scanner;
class ct0{
float
bmi=Float.parseFloat(args[1])/Float.parseFloat(args[2])/Float.parseFloa
t(args[2]);
String c;
if (bmi<18.5)
c="Underweight";
else if (bmi<25)
c="Normal";
else if (bmi<30)
c="overweight";
else
c="obese";
System.out.println(args[0]+" "+c);
}
2. Write a program to demonstrate the knowledge of students in multidimensional arrays and
looping constructs.
Eg., If there are 4 batches in BTech(IT) learning ‘ITE2005’ course, read the count of the
slow learners (who have scored <25) in each batch. Tutors should be assigned in the ratio of
1:4 (For every 4 slow learners, there should be one tutor). Determine the number of tutors
for each batch. Create a 2-D jagged array with 4 rows to store the count of slow learners in
the 4 batches. The number of columns in each row should be equal to the number of groups
formed for that particular batch ( Eg., If there are 23 slow learners in a batch, then there
should be 6 tutors and in the jagged array, the corresponding row should store 4, 4, 4, 4, 4,3).
Use for-each loop to traverse the array and print the details. Also print the number of batches
in which all tutors have exactly 4 students.
CODE:-
import java.io.*;
import java.util.Scanner;
class ct1{
System.out.println(Integer.parseInt("10")+Integer.valueOf("10a"
));
int i,n,x,j;
x=in.nextInt();
n=(x/4)+((x/4)*4==x?0:1);
ja[i]=new int[n];
for(j=0;j<n;j++,x-=4) ja[i][j]=x>4?4:x;
System.out.println("");
System.out.println("batch "+(i+1));
for(j=0;j<ja[i].length;j++){
System.out.print(ja[i][j]+", ");
if(ja[i][j]==4) tot++;
CODE:-
import java.io.*;
import java.util.Scanner;
class ct2{
int i ;
System.out.print("Reactants are:");
System.out.print(p.substring(0,i));
System.out.print(p.substring(0,i));
System.out.print("\n");
O/P: TTT
GGGCGT
CODE:-
import java.io.*;
import java.util.Scanner;
class ct3{
boolean x = false;
for(String p : e.split("ATG")){
i=p.length();
a=p.split("TAG")[0];
b=p.split("TAA")[0];
c=p.split("TGA")[0];
if (i<p.length()) System.out.println(g);
}
}
}
5. Write a program to demonstrate the knowledge of students in working with classes and
objects.
Eg.,Create a class Film with string objects which stores name, language and lead_actor and
category (action/drama/fiction/comedy). Also include an integer data member that stores the
duration of the film. Include parameterized constructor, default constructor and accessory
functions to film class. Flim objects can be initialized either using a constructor or accessor
functions. Create a class FilmMain that includes a main function. In the main function create
a vector object that stores the information about the film as objects. Use the suitable methods
of vector class to iterate the vector object to display the following
a. The English film(s) that has Arnold as its lead actor and that runs for shortest
duration.
b. The Tamil film(s) with Rajini as lead actor.
c. All the comedy movies.
CODE:-
import java.io.*;
import java.util.Scanner;
import java.util.Vector;
import java.util.Iterator;
class Film{
public Film(){
name="";
lang="";
lead_actor="";
category="";
dur=0;
this.set(a,b,c,d,e);
lang=b;
lead_actor=c;
category=d;
dur=e;
v.add(new Film("Terminator","English","Arnold","action",123));
v.add(new Film("Apdi123","Tamil","Rajini","comedy",123));
v.add(new
Film("Terminator:outtakes","English","Arnold","comedy",11));
Iterator<Film> it1=v.iterator();
Iterator<Film> it2=v.iterator();
Iterator<Film> it3=v.iterator();
int s=999;
while(it1.hasNext()){
Film x=it1.next();
s=x.dur;
y=x;
y.prnt();
while(it2.hasNext()){
Film x=it2.next();
if (x.lead_actor.equalsIgnoreCase("rajini")) x.prnt();
Film x=it3.next();
if (x.category.equalsIgnoreCase("comedy")) x.prnt();
6 Write a program to demonstrate the knowledge of students in creation of abstract classes and
working with abstract methods.
Eg., Define an abstract class ‘Themepark’ and inherit 2 classes ‘Queensland’ and ‘Wonderla’
from the abstract class. In both the theme parks, the entrance fee for adults is Rs. 500 and for
children it is Rs. 300. If a family buys ‘n’ adult tickets and ‘m’ children tickets, define a
method in the abstract class to calculate the total cost. Also, declare an abstract method
playGame() which must be redefined in the subclasses.
In Queensland, there are a total of 30 games. Hence create a Boolean array named ‘Games’
of size 30 which initially stores false values for all the elements. If the player enters any game
code that has already been played, a warning message should be displayed and the user
should be asked for another choice. In Wonderla, there are a total of 40 different games.
Thus create an integer array with 40 elements. Here, the games can be replayed, until the
user wants to quit. Finally display the total count of games that were repeated and count of
the games which were not played at all.
CODE:-
import java.io.*;
import java.util.Scanner;
import java.util.Vector;
import java.util.Arrays;
import java.util.Iterator;
return 500*n+300*m;
Arrays.fill(Games, false);
boolean wtp=true;
while(wtp){
int x=in.nextInt();
if(x==0) wtp=false;
else{
Games[x]=true;
Arrays.fill(Games, 0);
boolean wtp=true;
while(wtp){
int x=in.nextInt();
if(x==0) wtp=false;
Games[x]++;
System.out.println("Games repeated=");
System.out.println("\n\nQueensland:");
new Queensland().playGame();
System.out.println("\n\nWonderla:");
new Wonderla().playGame();
}
}
CODE:-
import
java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
if(r.length() != 9){
System.out.println("Invalid");
throw new
IllegalArgumentException("Register Number does not
contain exactly 9 characters");
if(n.length() != 10){
System.out.println("Invalid");
}
String pattern = "^[6|7|8|9]{1}\\d{9}";
Pattern a = Pattern.compile(pattern);
Matcher m1 = a.matcher(n);
if(!m1.find()){
Pattern b = Pattern.compile(pattern2);
Matcher m2 = b.matcher(r);
if(!m2.find()){
throw new
NoSuchElementException("Registration Number cannot
contain any character other than digits and
alphabets");
String no = sc.nextLine();
sc.close();
validate(reg, no);
System.out.println("Valid");
}
}