Académique Documents
Professionnel Documents
Culture Documents
CSE1007
NAME – MOHIT AJMERA
REG. NO. – 16BIT0156
SLOT – L41+L42
FACULTY – Prof. GUNDALA SWATHI
Assessment – 1
Display the name and display his category based on the BMI value thus calculated.
CODE –
import java.util.*;
import java.lang.*;
import java.io.*;
System.out.println("Enter the First and Last name of person (Sepreated by space) :");
String x = sc.next();
String p = sc.next();
double y = sc.nextDouble();
double z = sc.nextDouble();
double b = z/((y/100)*(y/100));
String a;
a = "Underweight";
a = "Overweight";
else
a = "Obese Class";
OUTPUT –
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.util.*;
import java.lang.*;
int i, j;
double t;
t = sc.nextDouble();
if(t >= 4)
arr[i][j] = 4;
else
arr[i][j] = (int)t;
t = t - 4;
int cf = 0;
for(int k:m)
if(k==4)
cf++;
System.out.println();
OUTPUT –
3. Write a program to demonstrate the knowledge of students in String handling.
Eg., Write a program to read a chemical equation and find out the count of the
reactants and the products. Also display the count of the number of molecules of
each reactant and product.
Eg., For the equation, 2NaOH + H2SO4 -> Na2SO4+ 2H2O, the O/P should be as
follows.
CODE –
import java.util.*;
import java.lang.*;
import java.io.*;
{
System.out.println("\n\t\tWelcome MOHIT AJMERA - 16BIT0156\n");
String a = sc.nextLine();
System.out.println("\r\n");
for(String i:b)
for(String j:c)
char x = j.charAt(0);
int m =0;
if(Character.isDigit(x)==true)
m = Character.getNumericValue(x);
else
m=1;
String z = y.substring(0,y.length()-2);
System.out.println(z+".");
y="";
OUTPUT –
4. Write a program to demonstrate the knowledge of students in advanced concepts of
Java string handling.
Eg., (Bioinformatics: finding 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 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:
O/P: TTT
GGGCGT
CODE –
import java.util.*;
import java.lang.*;
import java.io.*;
String a = sc.nextLine();
for(int i=0;i<a.length()-2;i++)
String b = a.substring(i,i+3);
if(b.equals("ATG"))
int x;
x = a.indexOf(b,i);
System.out.println(x);
aaa:
for(int j=i+3;j<a.length()-2;j++)
String c = a.substring(j,j+3);
int y;
y = a.indexOf(c,j);
System.out.println(y);
String z = a.substring(x+3,y);
if(y-x-3!=0)
for(int k=0;k<z.length()-2;k++)
String e = z.substring(k,k+3);
if(e.equals("ATG") || e.equals("TAG") || e.equals("TAA") ||
e.equals("TGA"))
break aaa;
System.out.println(z);
break aaa;
else
System.out.println("No Gene");
OUTPUT –
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.
CODE –
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;
language = l;
lead_actor = a;
category = c;
duration = d;
films[0].language = "Hindi";
films[0].lead_actor = "Ajay";
films[0].duration = 8000;
films[0].category = "Comedy";
films[1].name = "Terminator";
films[1].language = "English";
films[1].lead_actor = "Arnold";
films[1].duration = 6000;
films[1].category = "Action";
films[2].language = "Tamil";
films[2].lead_actor = "Rajini";
films[2].duration = 7000;
films[2].category = "Comedy";
films[3].language = "English";
films[3].lead_actor = "Arnold";
films[3].duration = 5000;
films[3].category = "Drama";
films[4].language = "Tamil";
films[4].lead_actor = "Rajini";
films[4].duration = 8888;
films[4].category = "fiction";
int jmin = 0;
System.out.println("\n");
System.out.println("(a):");
if(films[j].lead_actor.equals("Arnold"))
min = films[j].duration;
jmin = j;
System.out.println("Shortest Arnold film is " + films[jmin].name + " and duration is " + min + "
Seconds.");
System.out.println("\n");
System.out.println("(b):");
}
}
System.out.println("\n");
System.out.println("(c):");
if(films[j].category.equals("Comedy"))
OUTPUT –