import java.io.*;
class Player
{
int p_code,run;
String p_name;
int i_played;
int nooftime_notout;
float avg;
void accept()
{
DataInputStream din=new DataInputStream(System.in);
try
{
System.out.print("Enter the player code-");
p_code=Integer.parseInt(din.readLine());
System.out.print("Enter the player name-");
p_name=din.readLine();
System.out.print("Enter the player runs-");
run=Integer.parseInt(din.readLine());
System.out.print("Enter the player inning played-");
i_played=Integer.parseInt(din.readLine());
System.out.print("Enter the player no of time not out-");
nooftime_notout=Integer.parseInt(din.readLine());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void display()
{
avg=run/(i_played-nooftime_notout);
System.out.println(p_name+" "+avg);
}
void display(String nm)
{
if((nm.compareTo(p_name))==0)
{
avg=run/(i_played-nooftime_notout);
System.out.println(p_name+" "+avg);
}
}
}
class PlayerDemo
{
public static void main(String arg[])
{
Player p1[]=new Player[10];
//Player p=new Player();
int i,n,ch;
boolean flag=true;
String nm;
DataInputStream din=new DataInputStream(System.in);
try
{
System.out.print("How many record accept u want-");
n=Integer.parseInt(din.readLine());
for(i=0;i<n;i++)
{
p1[i]=new Player();
p1[i].accept();
}
while(true)
{
System.out.println("\n1.Display average of all player\n2.Display average run of single player \n3.Exit ");
System.out.print("Enter ur Choice-");
ch=Integer.parseInt(din.readLine());
switch(ch)
{
case 1:
System.out.println("Player name is "+" "+"Average is");
for(i=0;i<n;i++)
{
p1[i].display();
}
break;
case 2:
System.out.print("Enter player name whose display Average-");
nm=din.readLine();
System.out.println("\nPlayer name is "+" "+"Average is");
for(i=0;i<n;i++)
{
p1[i].display(nm);
}
break;
case 3:
System.exit(0);
break;
default:
System.out.println("invalid Choice");
}
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
/*Output
D:\javapro\Ass2>javac PlayerDemo.java
Note: PlayerDemo.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\javapro\Ass2>java PlayerDemo
How many record accept u want-2
Enter the player code-101
Enter the player name-sachin
Enter the player runs-5700
Enter the player inning played-45
Enter the player no of time not out-85
Enter the player code-102
Enter the player name-dhoni
Enter the player runs-4500
Enter the player inning played-86
Enter the player no of time not out-45
1.Display average of all player
2.Display average run of single player
3.Exit
Enter ur Choice-1
Player name is Average is
sachin -142.0
dhoni 109.0
1.Display average of all player
2.Display average run of single player
3.Exit
Enter ur Choice-2
Enter player name whose display Average-sachin
Player name is Average is
sachin -142.0
1.Display average of all player
2.Display average run of single player
3.Exit
Enter ur Choice-3
*/
Search
Blog Archive
-
▼
2015
(15)
-
▼
September
(13)
- WAP read charator form file and Display if charato...
- To copy the content one file into the another file...
- Count the Spaces in file
- Count the lines in file
- Count the Spaces,word,lines,space in file
- Simple copy one file to another file and Display o...
- Simple copy one file to another file
- WAP to accept n numbers from command line and stor...
- WAP to accept n numbers from command line and stor...
- Write a java program to accept n name of cities & ...
- Define abstract class Shape with abstract method a...
- Create an interface Shape with method area() Calcu...
- WAP to accept n cricket player, display average ru...
-
▼
September
(13)
Popular Posts
-
Emp.html <html> <body> <form method="POST" action="Lic.php"> Enter EMP No : <input ty...
-
class SortCity { public static void main(String arg[]) { String name[]=new Stri...
-
#include<stdio.h> #include<conio.h> main() { int num,rem=0,digit; clrscr(); printf("Enter number="...
-
Program to accept Book details of ‘n’ books as book_title, author, publisher and cost. Assign the accession number to each book in incre...
-
<?php interface Cyl { function area(); functi...
Categories
- BCA Sem VI Advance Java Slips Solution
- Ebooks
- FYBCA ( Sem–II) Assignment No.2 Decision making and looping.(solved assignment)
- FYBCA ( Sem–II) Assignment No.3 using function.(solved assignment)
- FYBCA ( Sem–II) Assignment No.4 Array program.(solved assignment)
- INFORMATION ABOUT TALLY.ERP 9
- RDBMS Assignment
- RDBMS ASSIGNMENT
- TYBCA (Sem IV) Java Programs
- TYBCA (Sem VI) Adv Java Programs
- TYBCA PHP Assignment