21. Update the FrequencyDistributionQuantitative class defined...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
22. Create a class called Stem and Leaf, which should have a...
package Gtu; import java.io.*; import java.util.Formatter; /* this is stamp_leaf.csv file data that we have create manually.....(SV) 12,112,72,69,97,107,73,126,82,92,115,95,84,68,100,92,128,104,108,76,141,119,98,85,76,118,132,96,91,81,113,115,94,86,127,134,100,102,80,98,106,106,73,124,83,92,81,106,75,95,119 */ class StemAndLeaf { int data[]=null; StemAndLeaf() { data=new int[50]; } void loadFromCSV(FileInputStream fin) throws IOException { int ch,i,j=0,num=0; do { i = fin.read(); if(i != -1) { if(i == 44) { data[j]=num; j++; num=0; } else { num*=10; ch=i-48; num+=ch; } } } while(i != -1); data[j]=num; fin.close(); } void display() { Formatter f; boolean flag=true; int stm[]=new int[9]; // 9 means no of stamp value int lf[][]=new int[9][11]; // 11 means no leaf in per stamp int k=0,m=0; for(int i=0;istm[j]) { int temp=stm[i]; stm[i]=stm[j]; stm[j]=temp; } } } for(k=0;klf[k][j]) { int temp=lf[k][i]; lf[k][i]=lf[k][j]; lf[k][j]=temp; } } } } for(k=0;k
23. Create a class called Pie Canvas, which subclasses from...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
24. Create a class called Statistical Data, which has capability...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; class StatisticalData { int v1[],v2[]; String v1name,v2name; public StatisticalData() { v1name=new String("str1"); v2name=new String(); v1=new int[5]; v2=new int[5]; v2name="str2"; } public void get() { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i; System.out.println("Enter First variable name and its values: "); try{ v1name = br.readLine(); for(i=0;i<5;i++) v2name =" br.readLine();" i="0;i<5;i++)" m1="0,m2=" tatb="0,sab,ta2=" tb2="0,sa,sb,cor_coef;" i="0;i<5;i++)" i="0;i<5;i++)" m1="m1+v1[i];" m2="m2+v2[i];" m1="m1/5;" m2="m2/5;" i="0;i<5;i++)" tatb="tatb+(v1[i]-m1)*(v2[i]-m2);" ta2="ta2+(v1[i]-m1)*(v1[i]-m1);" tb2="tb2+(v2[i]-m2)*(v2[i]-m2);" sab="tatb/4;" sa="ta2/5;" sb="tb2/5;" sa="Math.sqrt(sa);" sb="Math.sqrt(sb);" cor_coef="sab/sa*sb;" x="new">
25. Simple random sampling uses a sample of size n from...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
26. Dasher is an information-efficient text-entry interface,...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
27. Write a class in Java to plot a Histogram for the data...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
28. Write a class in Java to plot a Scatter diagram for the...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
29. Define a class which implements the Table Model...
//Prof.Swati Patel(SSIT Gandhinagar) import java.awt.*; import java.awt.event.*; import javax.swing.*; class StatisticalData { int v1[],v2[]; String v1name,v2name; public StatisticalData() { v1=new int[5]; v2=new int[5]; v2name="str2"; } public void get() { int i; for(i=0;i<5;i++) i="0;i<5;i++)" i="0;i<5;i++)" m1="0,m2=" tatb="0,sab,ta2=" tb2="0,sa,sb,cor_coef;" i="0;i<5;i++)" m1="m1+v1[i];" m2="m2+v2[i];" m1="m1/5;" m2="m2/5;" i="0;i<5;i++)" tatb="tatb+(v1[i]-m1)*(v2[i]-m2);" ta2="ta2+(v1[i]-m1)*(v1[i]-m1);" tb2="tb2+(v2[i]-m2)*(v2[i]-m2);" sab="tatb/4;" sa="ta2/5;" sb="tb2/5;" sa="Math.sqrt(sa);" sb="Math.sqrt(sb);" cor_coef="sab/sa*sb;" i="0;i<5;i++)" x="new" jf =" new" c =" jf.getContentPane();" colnames =" {" data="new" i="0;i<5;i++)" temp="x.correl_coeff(i);" i="0;i<5;i++)" temp="x.correl_coeff2(i);" ans="x.correl_ans();" jt =" new" scrollabletable =" new">
30. Create an applet which has a Text Field to accept a...
11. Make the class Cartesian Point, belong to a package called edu. gtu....
download link:http://www.megaupload.com/?d=1CUR491F
12. Update the classes Triangle and Rectangle, to throw an exception...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
13. Define a class called Polygon Manager, which manages a...
import java.io.*; interface input { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); } abstract class polygon_manager implements input { int x[]; int i; int size; int y[]; polygon_manager() { } polygon_manager(int xy) { x=new int[xy]; y=new int[xy]; size=xy; i=0; } abstract void display(); } class triangle extends polygon_manager { triangle() { } triangle(int xy) { super(xy); } void add()throws IOException { System.out.println("\nEnter the Three Co-Ordinates :"); for(i=0;i<3;i++)>"); x[i]=Integer.parseInt(br.readLine()); y[i]=Integer.parseInt(br.readLine()); } } void display() { System.out.print("\n\tTriangle :- {"); for(i=0;i<3;i++) i="0;i<4;i++)">"); x[i]=Integer.parseInt(br.readLine()); y[i]=Integer.parseInt(br.readLine()); } } void display() { System.out.print("\n\tRectangle :- {"); for(i=0;i<4;i++) i="0;i<5;i++)">"); x[i]=Integer.parseInt(br.readLine()); y[i]=Integer.parseInt(br.readLine()); } } void display() { System.out.print("\n\tPantagon :- {"); for(i=0;i<5;i++) i="0;i<6;i++)">"); x[i]=Integer.parseInt(br.readLine()); y[i]=Integer.parseInt(br.readLine()); } } void display() { System.out.print("\n\tHexagon :- {"); for(i=0;i<6;i++) i="0;i<8;i++)">"); x[i]=Integer.parseInt(br.readLine()); System.out.println(); y[i]=Integer.parseInt(br.readLine()); } } void display() { System.out.print("\n\tOctagon :- {"); for(i=0;i<8;i++) len="0,j=" choice ="-">"); ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: menuformat(); ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: triangle t=new triangle(3); t.add(); p[len]=t; len++; break; case 2: rectangle r=new rectangle(4); r.add(); p[len]=r; len++; break; case 3: pantagon pa=new pantagon(5); pa.add(); p[len]=pa; len++; break; case 4: hexagon h=new hexagon(6); h.add(); p[len]=h; len++; break; case 5: octagon o=new octagon(8); o.add(); p[len]=o; len++; break; case 6: break; default : System.out.println("\nPlz Enter 1 To 6 ................."); break; } break; case 2 : if(len<1) j="0;j"); pos=Integer.parseInt(br.readLine()); if(pos"); pos=Integer.parseInt(br.readLine()); if(pos"); pos=Integer.parseInt(br.readLine()); if(pos"); pos=Integer.parseInt(br.readLine()); if(pos"); pos=Integer.parseInt(br.readLine()); if(pos"); } }
14. Define a class called Statistical Data which manages...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; class StatisticalData { int v[],N; String vname; public StatisticalData() { N=0; vname=""; } public void setData() { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i; System.out.printf("How many values You want to Enter? "); try{ N=Integer.parseInt(br.readLine()); } catch(IOException e) { System.out.println("Error while Reading from console"); } v=new int[N]; System.out.printf("Enter variable Name and its values: "); try{ vname = br.readLine(); for(i=0;i temp[j+1]) { x=temp[j]; temp[j]=temp[j+1]; temp[j+1]=x; } } } if(N%2 == 0) { x=N/2; m=temp[x]; x--; m=m+temp[x]; m=m/2; } else { x=N/2; System.out.println("IND: " + x); m=temp[x]; } return m; } public double Mode() { double M,x,m; M=Median(); x=Mean(); m=3*M-2*x; return m; } public double Variance() { double var=0,m; int i; m=Mean(); for(i=0;i temp[j+1]) { x=temp[j]; temp[j]=temp[j+1]; temp[j+1]=x; } } } if(p==100) return temp[N-1]; else { P=p; n=N; n=P*n/100; P=Math.ceil(n); if(P-n > 0) { i=(int)P; P=temp[i-1]; } else { i=(int)P; P=temp[i]+temp[i-1]; P=P/2; } return P; } } } class P14 { public static void main(String args[]) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StatisticalData s=new StatisticalData(); int ch=10,ch1=1,p=-1; double result,Q3; s.setData(); do { do { System.out.println("1. Set Data"); System.out.println("2. Mean"); System.out.println("3. Median"); System.out.println("4. Mode"); System.out.println("5. Variance"); System.out.println("6. Standard Deviation"); System.out.println("7. Percentile (between 0 - 100)"); System.out.println("8. Quartile (between 1 - 3)"); System.out.println("9. Interquartile Range"); System.out.println("10. Exit"); System.out.print("Enter Your Choice: "); try{ ch=Integer.parseInt(br.readLine()); } catch(IOException e) { System.out.println("Error while Reading from console"); } }while(ch<1>10); switch(ch) { case 1: s.setData(); break; case 2: result=s.Mean(); System.out.println("Mean: " + result); break; case 3: result=s.Median(); System.out.println("Median: " + result); break; case 4: result=s.Mode(); System.out.println("Mode: " + result); break; case 5: result=s.Variance(); System.out.println("Variance: " + result); break; case 6: result=s.StdDev(); System.out.println("Standard Deviation: " + result); break; case 7: do { System.out.print("Which Percentile you want to calculate? "); try{ p=Integer.parseInt(br.readLine()); } catch(IOException e) { System.out.println("Error while Reading from console"); } }while(p<0>100); result=s.Percentile(p); System.out.println("Percentile: " + result); break; case 8: do { System.out.println("1. First "); System.out.println("2. Second "); System.out.println("3. Third "); System.out.print("Enter Your Choice: "); try{ ch1=Integer.parseInt(br.readLine()); } catch(IOException e) { System.out.println("Error while Reading from console"); } }while(ch1<1>3); switch(ch1) { case 1: result=s.Percentile(25); System.out.println("First Quartile: " + result); break; case 2: result=s.Percentile(50); System.out.println("Second Quartile: " + result); break; case 3: result=s.Percentile(75); System.out.println("Third Quartile: " + result); } break; case 9: Q3=s.Percentile(75); result=s.Percentile(25); result=Q3-result; System.out.println("Inter Quartile Range: " + result); } }while(ch != 10); } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication4; import java.io.*; class p14 { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StatisticalData s=new StatisticalData(); int ch=1; while(ch!=0) { /*float f1=2234.34534427f; System.out.format("%1$.2f",f1);*/ System.out.println("\n\n\n\n\n\nMain Menu"); System.out.println("1. Insert Mark"); System.out.println("2. Mean"); System.out.println("3. Median"); System.out.println("4. Mode"); System.out.println("5. Variance"); System.out.println("6. Standard Deviation"); System.out.println("7. Specified Percentile"); System.out.println("8. Specified Quarlite"); System.out.println("9. Interquartile Range"); System.out.println("0. Exit"); System.out.print("Enter your choice :"); try { ch=Integer.parseInt(br.readLine()); } catch(NumberFormatException nfx) { System.out.println("You can not enter the string.... OR can not leave it blank....."); ch=13; } if(s.get_size()==0 && ch!=1) { if(ch>10) { System.out.println("System can't recognize your choice, re-enter your selection...."); } else if( ch != 0) { System.out.println("Enter the mark of student first....."); } } else { switch(ch) { case 1: String ch1="Y"; while(ch1.compareToIgnoreCase("N")!=0) { if(ch1.equalsIgnoreCase("Y") || ch1.equalsIgnoreCase("N")) { s.add(); } else { System.out.println("Enter Y (for Yes) \nEnter N (for No)... Otherwise System can't recognize...."); } System.out.print("Want to add more ? (Y/N) :"); ch1=br.readLine(); } break; case 2: System.out.println("Mean : "+s.mean()); break; case 3: System.out.println("Median : "+s.median()); break; case 4: System.out.println("Mode : "+s.mode()); break; case 5: System.out.println("Variance : "+s.variance()); break; case 6: System.out.println("Standard Deviation : "+s.standard_deviation()); break; case 7: System.out.println("Enter value for Specified Percentile (0-100) :"); int p=Integer.parseInt(br.readLine()); if( p > 100 || p < q="Integer.parseInt(br.readLine());"> 3 || q < br="new" marks="new" n="0;" n="=" temp="Integer.parseInt(br.readLine());">100 || temp<0) sum="0;" i="0;itemp) { temp=count[k]; temp1=k; System.out.println(temp1); } } if(temp1==-1) { //f m=(2*median())+(3*mean()); } else { m=marks[temp1]; } return m; } float variance() { float mean=mean(); float sum=0; for(int i=0;imarks[j]) { int temp=marks[i]; marks[i]=marks[j]; marks[j]=temp; } } } } void display() { for(int i=0;i
15. Update the class Statistical Data, and define a method...
import java.util.*; import java.io.*; class StatisticalData { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int marks[]; int n; StatisticalData(){ marks=new int[60]; n=0; } void add()throws IOException{ if(n==60) { System.out.println("There is 60 student in the class..."); System.out.println("You can't enter any more marks....."); } else{ System.out.print("Enter Mark of Student : "+(n+1)+" : "); try{ int temp=Integer.parseInt(br.readLine()); if(temp>100 || temp<0) sum="0;" i="0;itemp) { temp=count[k]; temp1=k; } } System.out.println("Mode is/are ....."); if(temp1==-1) { m=(3.0f*median())-(2.0f*mean()); System.out.println(m); } else{ for(int i=0;i100 || t<0) temp2="">=48 && asc<=57) { str[0]=(char)asc; String temp3=new String(str); temp2=temp2.concat(temp3); } } } System.out.println("Your meaningfull data from CSV file found as follow...."); for (int j=0;jmarks[j]) { int temp=marks[i]; marks[i]=marks[j]; marks[j]=temp; } } } } void display(){ System.out.println("\n Your Data is .....\n"); for(int i=0;i11) { System.out.println("System can't recognize your choice,re-enter your selection...."); } else if( ch != 0 ) { System.out.println("Enter the mark of student first....."); } } else{ switch(ch) { case 1: String ch1="Y"; while(ch1.compareToIgnoreCase("N")!=0){ if(ch1.equalsIgnoreCase("Y") || ch1.equalsIgnoreCase("N")){ s.add(); } else{ System.out.println("Enter Y (for Yes) \nEnter N (for No)... Otherwise System can't recognize...."); } System.out.print("Want to add more ? (Y/N) :"); ch1=br.readLine(); } break; case 2: System.out.println("Mean : "+s.mean()); break; case 3: System.out.println("Median : "+s.median()); break; case 4: s.mode(); break; case 5: System.out.println("Variance : "+s.variance()); break; case 6: System.out.println("Standard Deviation : "+s.standard_deviation()); break; case 7: int flag=0; while(flag==0) { try{ System.out.print("Enter value for Specified Percentile (0-100) :"); int p=Integer.parseInt(br.readLine()); if( p > 100 || p < flag="1;" flag="0;" flag="=" q="Integer.parseInt(br.readLine());"> 3 || q < flag="1;" flag="0;" path="" flag="=" path="br.readLine();" ext="path.substring(path.length()-4);" istr="new" flag="1;" flag="0;" path="" flag="=" ext="" path="br.readLine();" ext="path.substring(path.length()-4);" f="new" flag="1;">
import java.util.*; import java.io.*; class p15{ public static void main(String args[]) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StatisticalData s=new StatisticalData(); int ch=1; while(ch!=0){ System.out.println("\n\n\n\n\n\nMain Menu"); System.out.println("01. Insert Mark"); System.out.println("02. Mean"); System.out.println("03. Median"); System.out.println("04. Mode"); System.out.println("05. Variance"); System.out.println("06. Standard Deviation"); System.out.println("07. Specified Percentile"); System.out.println("08. Specified Quarlite"); System.out.println("09. Interquartile Range"); System.out.println("10. Load Data from CSV file ( using Input Stream )"); System.out.println("11. Load Data from CSV file ( using File )"); System.out.println("0. Exit"); System.out.print("Enter your choice :"); try{ ch=Integer.parseInt(br.readLine()); } catch(NumberFormatException nfx) { System.out.println("You can not enter the string.... OR can not leave it blank....."); ch=13; } if(s.get_size()==0 && ch!=1 && ch!=10 && ch!=11) { if(ch>11) { System.out.println("System can't recognize your choice,re-enter your selection...."); } else if( ch != 0 ) { System.out.println("Enter the mark of student first....."); } } else{ switch(ch) { case 1: String ch1="Y"; while(ch1.compareToIgnoreCase("N")!=0){ if(ch1.equalsIgnoreCase("Y") || ch1.equalsIgnoreCase("N")){ s.add(); } else{ System.out.println("Enter Y (for Yes) \nEnter N (for No)... Otherwise System can't recognize...."); } System.out.print("Want to add more ? (Y/N) :"); ch1=br.readLine(); } break; case 2: System.out.println("Mean : "+s.mean()); break; case 3: System.out.println("Median : "+s.median()); break; case 4: s.mode(); break; case 5: System.out.println("Variance : "+s.variance()); break; case 6: System.out.println("Standard Deviation : "+s.standard_deviation()); break; case 7: int flag=0; while(flag==0) { try{ System.out.print("Enter value for Specified Percentile (0-100) :"); int p=Integer.parseInt(br.readLine()); if( p > 100 || p < flag="1;" flag="0;" flag="=" q="Integer.parseInt(br.readLine());"> 3 || q < flag="1;" flag="0;" path="" flag="=" path="br.readLine();" ext="path.substring(path.length()-4);" istr="new" flag="1;" flag="0;" path="" flag="=" ext="" path="br.readLine();" ext="path.substring(path.length()-4);" f="new" flag="1;" br="new" marks="new" n="0;" n="=" temp="Integer.parseInt(br.readLine());">100 || temp<0) sum="0;" i="0;itemp) { temp=count[k]; temp1=k; } } System.out.println("Mode is/are ....."); if(temp1==-1) { m=(3.0f*median())-(2.0f*mean()); System.out.println(m); } else{ for(int i=0;i100 || t<0) temp2="">=48 && asc<=57) { str[0]=(char)asc; String temp3=new String(str); temp2=temp2.concat(temp3); } } } System.out.println("Your meaningfull data from CSV file found as follow...."); for (int j=0;jmarks[j]) { int temp=marks[i]; marks[i]=marks[j]; marks[j]=temp; } } } } void display(){ System.out.println("\n Your Data is .....\n"); for(int i=0;i
16. A college maintains the information about the marks of...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
17. In the above exercise, use multithreading, to compute the...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
18. In the class Statistics defined earlier add method to find the...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
19. A Frequency Distribution is a tabular summary of data showing...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
20. Create subclass of the Frequency Distribution class called...
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
Home >> Sem 3 >> 630006 - Programming Skills-IV (Java/SM)
1. Observe the interactions involved in the process of booking a railway ticket....
Share this program... Send it to gtumca@gmail.com with your Name - College name.. and share what you want ... at same mail id... Thanx in advance... Be connected... D_i_Z
2. Write a simple java application to print a pyramid with 5 lines...
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROGRM DEFINATION :- Write a simple java application to print a pyramid with 5 lines. The first line has one character, 2nd line has two characters and so on. The character to be used in the pyramid is taken as a commandline argument. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ class pyramid { public static void main(String str[]) { int i,j,n; n= Integer.parseInt(str[1]); //convert string to integer if(str[0].length() != 1 ) //check length of first argument System.out.println("Operation failed !! "); else { //First solution for(i=0;ii;j--) //for displaying space System.out.print(' '); for(j=0;j<=i;j++) //for displaying character System.out.print( str[0] +' '); System.out.println(); // Newline } /*second solution ..... j=1; for(;n>0;n--) // Loop for no of line { for(i=1;i
class P2 { public static void main(String args[]) { int i,j; String ch; ch=args[0]; if(ch.length() != 1) System.out.println("Enter Only 1 character as Command Line Argument..."); else { for(i=0;i<5;i++) j="5-i;j">0;j--) System.out.printf(" "); for(j=0;j<=i;j++) { System.out.printf(" "); System.out.printf(ch); } System.out.println(); } } } }
3. Write a Java application which takes several command line arguments,...
/* PROBLEM NO :- 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROGRM DEFINATION :- Write a Java application which takes several command line arguments, which are supposed to be names of students and prints output as given below: (Suppose we enter 3 names then output should be as follows): Number of arguments = 3 1: First Student Name is =Tom 2: Second Student Name is =Dick 3: Third Student Name is =Harry Hint: An array may be used for converting from numeric values from 1 to 20 into String. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ //..............................FIRST SOLUTION USING ARRAY........................ class student { public static void main(String str[]) { int n,i=0; n=str.length;// store no of argumnet //string array fo display numbers in words String [] s={"FIRST","SECOND","THIRD","FOURTH","FIFTH","SIXTH","SEVENTH", "EIGHTH","NINETH","TENTH","ELEVENTH","TWELVETH","THIRTEENTH", "FOURTEENTH","FIFTEENTH","SIXTEENTH","SEVENTEENTH","EIGHTEENTH", "NINETEENTH","TWENTEENTH" }; //check no of arguments if(n >= 1 && n <=20 ) { System.out.println("\nNo of arguments are := " +n); System.out.println(); for (i=0;i= 1 && n <=20 ) //check no of argumnet { System.out.println("\nNo of arguments are := " +n); System.out.println(); for (words wd : words.values()) // vaues fetched from enum { if(i
//change coding as per your requirement... class prog3 { public static void main(String arg[]) { int a; a=arg.length; String str[]={"First","Second","Third","four","five","six","seven","eight","nine","ten"}; for(int i=0;i
class P3 { public static void main(String args[]) { int i,j; String[] s=new String[10]; s[0]="First"; s[1]="Second"; s[2]="Third"; s[3]="Fourth"; s[4]="Fifth"; s[5]="Sixth"; s[6]="Seventh"; s[7]="Eighth"; s[8]="Ninth"; s[9]="Tenth"; if(args.length > 10) System.out.println("Too many Command Line Arguments..."); else { System.out.println("Number of Arguments=" + args.length); for(i=0;i
4. Write a class, with main method, which declares floating point...
class prog4 { public static void main(String arg[]) { double a=123456789123.4; double b; b=a/0; int c; c=(int)a; System.out.println(a+" "+c +" " +b); } }
class P4 { public static void main(String args[]) { float f=123.45f; int i; System.out.println("Float Value: " + f); System.out.println("Float Value divide By 0: " + f/0); f=12345678; System.out.println("Int Value in Float Variable: " + f); i=(int)f; System.out.println("Float Value in Int Variable: " + i); } }
5. Write a class called Statistics, which has a static method called...
//Prog no 5... class state { public static void avg(double d[]) { double tot=0; for(int i=0;i
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; class Statistics { public static void average(double d[]) { double avg=0; int i; for(i=0;i<7;i++) avg =" avg" tempreture = " + avg/7); } } class P5 extends Statistics { public static void main(String args[]) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); double tempr[][]=new double[4][7]; double wk[]=new double[7]; int i,j; String s; try{ for(i=0;i<4;i++) { for(j=0;j<7;j++) { System.out.println(" s="br.readLine();" i="0;i<4;i++)" j="0;j<7;j++)">
class state { public static void avg(double a[]) { static double sumt=0; static double avg=0; for(int i=0;i
6. Define a class called Product, each product has a name, a product...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; class Product { int Pid; String Pname,Mname; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public Product() { this.Pid = 0; this.Pname = null; this.Mname = null; } public Product(int i,String s1,String s2) { this.Pid = i; this.Pname = s1; this.Mname = s2; } public void getDetail() throws IOException { String t; System.out.printf("Enter Product ID: "); t = br.readLine(); this.Pid=Integer.parseInt(t); System.out.printf("Enter Product Name: "); this.Pname = br.readLine(); System.out.printf("Enter Manufacturer Name: "); this.Mname = br.readLine(); } public void Display() { System.out.println("Product ID: " + this.Pid); System.out.println("Product Name: " + this.Pname); System.out.println("Manufacturer Name: " + this.Mname); } } class P6 extends Product { public static void main(String args[]) { Product p = new Product(); try{ p.getDetail(); } catch(IOException e) { System.out.println("Error occured while Reading from console"); } p.Display(); } }
class product { int p_code; String p_name; String m_name; product() { p_code=1; p_name="Pendrive"; m_name="Transcand"; } product(int i,String s1,String s2) { p_code=i; p_name=s1; m_name=s2; } void print_data() { System.out.println("Product code is="+p_code); System.out.println("Product name is="+p_name); System.out.println("Manufature name is="+m_name); } } class p6 { public static void main(String args[]) { product p=new product(); product p1=new product(2,"Card reader","iball"); p.print_data(); p1.print_data(); } }
7. Define a class called Cartesian Point, which has two instance ...
class product { int p_code; String p_name; String m_name; product() { p_code=1; p_name="Pendrive"; m_name="Transcand"; } product(int i,String s1,String s2) { p_code=i; p_name=s1; m_name=s2; } void print_data() { System.out.println("Product code is="+p_code); System.out.println("Product name is="+p_name); System.out.println("Manufature name is="+m_name); } } class p6 { public static void main(String args[]) { product p=new product(); product p1=new product(2,"Card reader","iball"); p.print_data(); p1.print_data(); } }
/*7. Define a class called Cartesian Point, which has two instance variables, x and y. Provide the methods get X() and get Y() to return the values of the x and y values respectively, a method called move() which would take two integers as parameters and change the values of x and y respectively, a method called display() which would display the current values of x and y. Now overload the method move() to work with single parameter, which would set both x and y to the same values, . Provide constructors with two parameters and overload to work with one parameter as well. Now define a class called Test Cartesian Point, with the main method to test the various methods in the Cartesian Point class. */ import java.lang.*; class CP { int x,y; public CP(int x,int y) { this.x=x; this.y=y; } public CP(int a) { x=y=a; } int getx() { return x; } int gety() { return y; } void move(int x,int y) { this.x=x; this.y=y; } void display() { System.out.println("Current value of x : "+getx()); System.out.println("Current value of y : "+gety()); } void move(int a) { x=y=a; } } class p7 { public static void main(String arg[]) { CP cp1 = new CP(5,25); System.out.println("\n\nDefault Values with "+5+" And "+25); cp1.display(); System.out.println("After Function move with two arguments is called,"); cp1.move(11,25); cp1.display(); System.out.println("After Function move with one arguments is called,"); cp1.move(95); cp1.display(); System.out.println("-------------------------------------"); CP cp2 = new CP(15); System.out.println("\n\nDefault Values with"+15); cp2.display(); System.out.println("After Function move with two arguments is called,"); cp2.move(35,65); cp2.display(); System.out.println("After Function move with one arguments is called,"); cp2.move(105); cp2.display(); } }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; class CartesianPoint { private int x,y; public CartesianPoint(int a) { x=y=a; } public CartesianPoint(int a,int b) { x=a; y=b; } public int getX() { return x; } public int getY() { return y; } public void move(int a,int b) { x=a; y=b; } public void move(int a) { x=y=a; } public void Display() { System.out.printf("(" + x + "," + y + ")"); } } class P7 { public static void main(String args[]) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); CartesianPoint c=new CartesianPoint(0,0); int ch=5,a=0,b=0; do { do { System.out.println("\n1. Get value of X"); System.out.println("2. Get value of Y"); System.out.println("3. Change value of X and Y"); System.out.println("4. Display the Point"); System.out.println("5. Exit"); System.out.println("Enter Your Chopice: "); try { ch = Integer.parseInt(br.readLine()); } catch(IOException e) { System.out.println("Error occurs while taking Input"); } }while(ch<1>5); switch(ch) { case 1: System.out.println("Value of X is " + c.getX()); break; case 2: System.out.println("Value of Y is " + c.getY()); break; case 3: System.out.println("Enter 2 Points"); try { a = Integer.parseInt(br.readLine()); b = Integer.parseInt(br.readLine()); } catch(IOException e) { System.out.println("Error occurs while taking Input"); break; } if(a == b) c.move(a); else c.move(a,b); System.out.println("Value of X and Y Point is changed..."); break; case 4: System.out.printf("Point is "); c.Display(); } }while(ch != 5); } }
8. Define a class called Triangle, which has constructor with three...
download this prog in one file-=>link::http://www.megaupload.com/?d=KJ7YUYU7 OR | | v Package MyPackage ------------------------------------------------------------------------------ package MyPack; public class CP { public float x,y; public CP(float x,float y) { this.x=x; this.y=y; } public CP(float a) { x=y=a; } public float getx() { return x; } public float gety() { return y; } public void move(float x,float y) { this.x=x; this.y=y; } public void display() { System.out.println("Current value of x : "+getx()); System.out.println("Current value of y : "+gety()); } public void move(float a) { x=y=a; } } --------------------------------------------------------------------------------- package MyPack; import MyPack.CP; import java.lang.Math; import java.util.Scanner; import java.lang.Double; public class Rectangle{ public CP a,b,c,d; public Rectangle(CP a,CP b,CP c,CP d){ this.a=a; this.b=b; this.c=c; this.d=d; System.out.println("Rectangle is Created..."); } public void Area(){ float Area; Area = ((a.x*(b.y - c.y)) + (b.x*(c.y-a.y)) + ((c.x*(a.y-b.y)))); System.out.println("The area of Triangle is "+Math.abs(Area)); } public void Display(){ System.out.println("\t\tA("+a.x+","+a.y+") # \t\t\t # B("+b.x+","+b.y+")\n\n\n\n"); System.out.println("\t\tD("+d.x+","+d.y+") # \t\t\t # C("+c.x+","+c.y+")"); } public void move(float x,float y){ float new_x=x-a.x,new_y=y-a.y; a.x=x; a.y=y; b.x=b.x+new_x; b.y=b.y+new_y; c.x=c.x+new_x; c.y=c.y+new_y; d.x=d.x+new_x; d.x=d.y+new_y; } public void rotate(CP A,float a){ double a1 = (A.x*Math.cos(a))-(A.y*Math.sin(a)); double b2 =(A.x*Math.sin(a))+(A.y*Math.cos(a)); A.x = (float) a1; A.y = (float) b2; } } ----------------------------------------------------------------------------------------------------- package MyPack; import MyPack.CP; import java.lang.Math; import java.util.Scanner; import java.lang.Double; public class Triangle{ public CP a,b,c; public Triangle(CP a,CP b,CP c){ this.a=a; this.b=b; this.c=c; System.out.println("Triangle is created.."); } public void Area(){ float Area; Area = ((a.x*(b.y - c.y)) + (b.x*(c.y-a.y)) + ((c.x*(a.y-b.y))))/2; System.out.println("The area of Triangle is "+Math.abs(Area)); } public void Display(){ System.out.println("\t\t\t\t # A("+a.x+","+a.y+")\n\n\n\n"); System.out.println("\t\tB("+b.x+","+b.y+") #\t\t # C("+c.x+","+c.y+")"); /*System.out.println("Point A = "+a.x+" : "+a.y); System.out.println("Point B = "+b.x+" : "+b.y); System.out.println("Point C = "+c.x+" : "+c.y);*/ } public void move(float x,float y){ float new_x=x-a.x,new_y=y-a.y; a.x=x; a.y=y; b.x=b.x+new_x; b.y=b.y+new_y; c.x=c.x+new_x; c.y=c.y+new_y; } public void rotate(CP A,float a){ double a1 = (A.x*Math.cos(a))-(A.y*Math.sin(a)); double b2 =(A.x*Math.sin(a))+(A.y*Math.cos(a)); A.x = (float) a1; A.y = (float) b2; } } ---------------------------------------------------------------------------------------------------- Package is Over ---------------------------------------------------------------------------------------------------- Main method in class p8 ---------------------------------------------------------------------------------------------------- /*Define a class called Triangle, which has constructor with three parameters, which are of type Cartesian Point, defined in the exercise 7. Provide methods to find the area and the perimeter of the Triangle, a method display() to display the three Cartesian Points separated by ':' character, a method move() to move the first Cartesian Point to the specified x, y location, the move should take care of relatively moving the other points as well, a method called rotate, which takes two arguments, one is the Cartesian Point and other is the angle in clockwise direction. Overload the move method to work with Cartesian Point as a parameter. Now define a class called Test Triangle to test the various methods defined in the Triangle class. Similarly also define a class called Rectangle which has four Cartesian Point. Triangle's Points a b c Rectangle a b c d */ import MyPack.CP; import MyPack.Triangle; import MyPack.Rectangle; import java.util.Scanner; class p8{ public static void main(String args[]){ Scanner s = new Scanner(System.in); float x,y; int n=0; while(true){ System.out.println("1. Triangle"); System.out.println("2. Rectangle"); System.out.println("3. Exit"); System.out.print("Enter your choice..."); n=s.nextInt(); switch(n){ case 1 : System.out.println("Create a Triangle. " ); System.out.print("Enter x for point A "); x=s.nextFloat(); System.out.print("Enter y for point A "); y=s.nextFloat(); CP A = new CP(x,y); System.out.print("Enter x for point B "); x=s.nextFloat(); System.out.print("Enter y for point B "); y=s.nextFloat(); CP B = new CP(x,y); System.out.print("Enter x for point C "); x=s.nextFloat(); System.out.print("Enter y for point C "); y=s.nextFloat(); CP C = new CP(x,y); Triangle T = new Triangle(A,B,C); while(true){ System.out.println("-------------------MENU-----------------------"); System.out.println("1. Display Current Points."); System.out.println("2. Calculate The Area." ); System.out.println("3. Move The Triangle."); System.out.println("4. Rotate The Triangle "); System.out.println("5. Exit"); System.out.println("Enter Your Choice..."); n=s.nextInt(); switch(n){ case 1 : System.out.println("The Current Points Are..."); T.Display(); break; case 2 : T.Area(); break; case 3 : System.out.print("Enter new x :"); x=s.nextFloat(); System.out.print("Enter new y :"); y=s.nextFloat(); T.move(x,y); System.out.println("Triangle has been replaced.."); break; case 4 : float degree; System.out.print("Enter a degree to rotate : "); degree=s.nextFloat(); T.rotate(T.a,degree); T.rotate(T.b,degree); T.rotate(T.c,degree); System.out.println("The triangle has been rotated with "+degree+" degree"); break; case 5 : System.exit(0); default : System.out.println("Invalid Input..."); } } case 2 : System.out.println("Create a Reactangle. " ); System.out.print("Enter x for point A "); x=s.nextFloat(); System.out.print("Enter y for point A and B"); y=s.nextFloat(); CP A2 = new CP(x,y); System.out.print("Enter x for point B "); x=s.nextFloat(); CP B2 = new CP(x,A2.y); System.out.print("Enter y for point C "); y=s.nextFloat(); CP C2 = new CP(B2.x,y); CP D2 = new CP(A2.x,C2.y); Rectangle R = new Rectangle(A2,B2,C2,D2); while(true){ System.out.println("-------------------MENU-----------------------"); System.out.println("1. Display Current Points."); System.out.println("2. Calculate The Area." ); System.out.println("3. Move The Rectangle."); System.out.println("4. Rotate The Rectangle "); System.out.println("5. Exit"); System.out.println("Enter Your Choice..."); n=s.nextInt(); switch(n){ case 1 : System.out.println("The Current Points Are..."); R.Display(); break; case 2 : R.Area(); break; case 3 : System.out.print("Enter new x :"); x=s.nextFloat(); System.out.print("Enter new y :"); y=s.nextFloat(); R.move(x,y); System.out.println("Rectangle has been replaced.."); break; case 4 : float degree; System.out.print("Enter a degree to rotate : "); degree=s.nextFloat(); R.rotate(R.a,degree); R.rotate(R.b,degree); R.rotate(R.c,degree); R.rotate(R.d,degree); System.out.println("The rectangle has been rotated with "+degree+" degree"); break; case 5 : System.exit(0); default : System.out.println("Invalid Input..."); } } case 3 : System.exit(0); default : System.out.println("Invalid Input..."); } } } } -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Thank you ::: Jani Anand.(09MCA11-SRIMCA) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9. Override the to String, equals and the hash Code methods of the...
Shared By : Divyang s Panchal
(Asst Professor College - D.L.Patel institute of mng & tec ,MCA College )
Show/Hide Program class Cartesianpoint { int x,y; Cartesianpoint(int x,int y) { this.x=x; this.y=y; } } public class p9 { Cartesianpoint a,b,c; p9(Cartesianpoint a,Cartesianpoint b,Cartesianpoint c) { this.a=a; this.b=b; this.c=c; } void display() { System.out.print(toString()); } public String toString() { return("For This Instance A(x,y) is ("+a.x+","+a.y+")\n For point B(x,y) is ("+b.x+","+b.y+")\n For point C(x,y) is ("+c.x+","+c.y+")\n\n"); } public boolean equals(p9 obj) { if(this.a.x==obj.a.x && this.a.y==obj.a.y) { if(this.b.x==obj.b.x && this.b.y==obj.b.y) { if(this.c.x==obj.c.x && this.c.y==obj.c.y) { return(true); } } } return(false); } public int hashCode() { int i=Integer.parseInt(""+a.x+""+a.y+""+""+b.x+""+b.y+""+""+c.x+""+c.y+""); return(i); } public static void main(String[] arg) { Cartesianpoint a,b,c; a=new Cartesianpoint(1,1); b=new Cartesianpoint(3,5); c=new Cartesianpoint(5,1); p9 p,q; p=new p9(a,b,c); a=new Cartesianpoint(1,1); b=new Cartesianpoint(3,5); c=new Cartesianpoint(5,1); q=new p9(a,b,c); p.display(); q.display(); System.out.print(p.equals(q)); System.out.println(p.hashCode()); System.out.println(q.hashCode()); } }
10. Define an abstract class called Polygon. Provide a constructor ...