Category : DAA LAB

2 B – Write a Java class called Customer to store their name and date_of_birth. The date_of_birth format should be dd/mm/yyyy. Write methods to read customer data as <name, dd/mm/yyyy> and display as <name, dd, mm, yyyy> using StringTokenizer class considering the delimiter character as “/”.import java.util.Scanner;import java.util.StringTokenizer;class Customer{ private String name; private String date_of_birth; ..

Read more

3 A – Write a Java program to read two integers a and b. Compute a/b and print, when b is not zero. Raise an exception when b is equal to zero.import java.util.Scanner;public class lab3a { lab3a() { int a,b; float c; Scanner sc=new Scanner(System.in); try { System.out.println(“Enter the value of a”); a=sc.nextInt(); System.out.println(“Enter the value ..

Read more

6 – Implement in Java, the 0/1 Knapsack problem using (b) Greedy method.import java.util.Scanner;public class lab6b{ public static void main(String[] args)  { int i,j=0,max_qty,m,n; float sum=0,max; Scanner sc = new Scanner(System.in); int array[][]=new int[2][20]; System.out.println(“Enter no of items”); n=sc.nextInt(); System.out.println(“Enter the weights of each items”); for(i=0;i<n;i++) array[0][i]=sc.nextInt(); System.out.println(“Enter the values of each items”); for(i=0;i<n;i++) array[1][i]=sc.nextInt(); System.out.println(“Enter ..

Read more

11 – Design and implement in Java to find a subset of a given set S = {Sl, S2,…..,Sn} of n positive integers whose SUM is equal to a given positive integer d. For example, if S ={1, 2, 5, 6, 8} and d= 9, there are two solutions {1,2,6}and {1,8}. Display a suitable message, ..

Read more

1 A – Create a Java class called Student with the following details as variables within it. (i) USN (ii) Name (iii) Branch (iv) Phone Write a Java program to create n Student objects and print the USN, Name, Branch, and Phone of these objects with suitable headings.class student { String USN,NAME,BRANCH,PH; student(String U,String N,String b,String ..

Read more

3 B – Write a Java program that implements a multi-thread application that has three threads. First thread generates a random integer for every 1 second; second thread computes the square of the number and prints; third thread will print the value of cube of the number.import java.util.*;class second implements Runnable{ public int x; public ..

Read more

7 – From a given vertex in a weighted connected graph, find shortest paths to other vertices using Dijkstra’s algorithm. Write the program in Java.import java.util.*;public class lab7{ public  int distance[] = new int[10]; public  int cost[][] = new int[10][10]; public void calc(int n,int s) { int flag[] = new int[n+1]; int i,minpos=1,k,c,minimum; for(i=1;i<=n;i++) {   ..

Read more

10 – Write Java programs to (a) Implement All-Pairs Shortest Paths problem using Floyd’s algorithm.import java.util.Scanner;public class lab10a{ void flyd(int[][] w,int n) { int i,j,k; for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j=1;j<=n;j++) w[i][j]=Math.min(w[i][j], w[i][k]+w[k][j]); } public static void main(String[] args)  { int a[][]=new int[10][10]; int n,i,j; System.out.println(“enter the number of vertices”); Scanner sc=new Scanner(System.in); n=sc.nextInt(); System.out.println(“Enter the weighted matrix”); for(i=1;i<=n;i++) ..

Read more