Professional Documents
Culture Documents
M.BHANU
21BCE3879
21B
CE
Q1
387
9
CODE:
import java.util.*;
import java.math.*;
public class Q1 {
rstName = input.next();
lastName = input.next();
height = input.nextFloat();
weight = input.nextFloat();
if(bmi<18.5)
fl
fi
fi
fi
fi
else if(bmi >= 25 && bmi <30)
else
OUTPUT:
21B
CE
387
9
Q2
CODE:
import java.util.*;
public class Q2 {
int[][] employeeHours =
{7, 3, 4, 3, 3, 4, 4},
{3, 3, 4, 3, 3, 2, 2},
{9, 3, 4, 7, 3, 4, 1},
{3, 5, 4, 3, 6, 3, 8}};
sortWhileKeepingIndices(totalHoursPerEmployee, indexList);
21B
for (int i = 0; i < totalHoursPerEmployee.length; i++) {
CE
totalHoursPerEmployee[i]);
387
System.out.println(java.util.Arrays.toString(indexList));
9
}
int sum = 0;
sum += hours[i][j];
totalHoursPerEmployee[i] = sum;
return totalHoursPerEmployee;
// ll indexList
indexList[i] = i;
int currentMaxIndex = i;
currentMax = totalHours[j];
fi
currentMaxIndex = j;
if (currentMaxIndex != i) {
totalHours[currentMaxIndex] = totalHours[i];
totalHours[i] = currentMax;
indexList[currentMaxIndex] = indexList[i];
indexList[i] = temp;
21B
java.util.Arrays.toString(totalHours));
CE
OUTPUT:
387
9
Q3
3. Develop a Java Program to count the number of votes voted for each candidate. Consider there
are three candidates represented by the digit (1,2,3) and 10 voters have to vote. The voting process
is simulated and automated through a random number generator method that will randomly select
the digit from 1-to 3 and vote for him. Note: Math.random() * (max - min + 1) + min
CODE:
import java.util.Scanner;
public class test
{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
nal int SIZE = 3;
String[] votes = new String[10];
String[] names = new String[SIZE];
int count1=0;
21B
int count2=0;
int count3=0;
CE
for (int i = 0; i < names.length; i++){
System.out.print("Enter candidate's name: ");
names[i] = input.next( );
387
}
for(int i = 0; i < votes.length; i++){
System.out.print("Enter your vote: ");
9
votes[i] = input.next( );
if(votes[i]==names[0]){
count1++;
}
else if(votes[i]==names[1]){
count2++;
}
else{
count3++;
}
}
OUTPUT
Q4
fi
21B
CE
387
4. Write a program to demonstrate the knowledge of students in advanced concepts of Java string
handling. Eg., (Bioinformatics: nding genes) Biologists use a sequence of letters A, C, T, and G to
model a genome. A gene is a substring of a genome that starts after a triplet ATG and ends before a
9
triplet TAG, TAA, or TGA. Furthermore, the length of a gene string is a multiple of 3 and the gene
does not contain any of the triplets ATG, TAG, TAA, and TGA. Write a program that prompts the
user to enter a genome and displays all genes in the genome. If no gene is found in the input
sequence, displays no gene. Here are the sample runs: Enter a genome string:
TTATGTTTTAAGGATGGGGCGTTAGTT O/P: TTT GGGCGT
CODE:
import java.util.*;
public class Q4 {
for(int i=0;i<len;i++) {
for(int j=i+1;j<=len;j++) {
String s = str.substring(i,j);
int t = s.length();
if(s.substring(t-3).equals("TAG") || s.substring(t-3).equals("TAA") ||
s.substring(t-3).equals("TGA")) {
if(temp.length()%3==0) {
System.out.println(temp);
fi
}
OUTPUT:
21B
CE
387
9
Q5
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/ ction/comedy). Also include an integer data member that stores the
duration of the lm. Include parameterized constructor, default constructor and accessory functions
to lm 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 lm as objects. Use the suitable methods of vector class to iterate
the vector object to display the following
a. The English lm(s) that has Arnold as its lead actor and that runs for shortest duration.
b. b. The Tamil lm(s) with Rajini as lead actor.
CODE:
import java.util.*;
fi
fi
fi
fi
fi
fi
class Film{
String name;
String language;
String lead_actor;
String category;
int duration;
Film(){
name = null;
language = null;
lead_actor = null;
category = null;
duration = 0;
21B
}
CE
name = n;
language = lang;
387
lead_actor = actor;
category = cat;
duration = dur;
9
}
public class Q5 {
Film lms;
lms.name = "Terminator";
lms.language = "English";
lms.lead_actor = "Arnold";
lms.duration = 10;
lms.category = "Action";
Films.add( lms);
lms.language = "English";
lms.lead_actor = "Arnold";
lms.duration = 20;
lms.category = "Action";
Films.add( lms);
lms.language = "Tamil";
lms.lead_actor = "Rajini";
lms.duration = 10;
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
lms.category = "Comedy";
Films.add( lms);
lms.language = "Tamil";
lms.lead_actor = "Rajini";
lms.duration = 30;
lms.category = "Comedy";
Films.add( lms);
int imin = 0;
21B
for(int i = 0; i < 4; i++){
lms = Films.get(i);
if( lms.lead_actor.equals("Arnold"))
CE
if( lms.duration < min){
min = lms.duration;
387
imin = i;
if( lms.category.equals("Comedy"))
9
System.out.println( lms.name + " is a Comedy movie");
lms = Films.get(imin);
OUTPUT:
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi