import java.io.*;
import java.lang.*;
class Bank
{
double bal,damt,wamt;
String acct_type, acct_name;
int acctno;
void initial(int no, String type,String name,double balance)
{
acctno=no;
acct_type=type;
acct_name=name;
bal=balance;
}
void deposit(double amt)
{
damt=amt;
bal=bal+damt;
System.out.println("Amount Deposited: "+damt);
}
void withdraw(double at)
{
wamt=at;
if(bal>wamt)
{
bal=bal-wamt;
System.out.println("Amount Withdrawn: "+wamt);
}
else
{
System.out.println("Withdrawn Amount greater than balance \n Balance :"+bal);
}
}
void display()
{
System.out.println("Account Number: "+acctno);
System.out.println("Account Type: "+acct_type);
System.out.println("Account Name: "+acct_name);
System.out.println("Account Balance: "+bal);
}
}
class BankDemo
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String name,type;
int no,choice,i;
double ba,wa,da;
boolean baless=false;
i=0;
System.out.print("Enter account number: ");
no=Integer.parseInt(in.readLine());
System.out.print("Enter account type: ");
type=br.readLine();
System.out.print("Enter account name: ");
name=br.readLine();
do{
System.out.print("Enter account balance: ");
ba=Double.parseDouble(in.readLine());
if(ba<1000)
{
baless=true;
System.out.println("Minimum balance must be Rs.1000");
}
else
baless=false;
}while(baless==true);
Bank b1=new Bank();
b1.initial(no,type,name,ba);
while(i==0)
{
System.out.print("1.Deposit\n2.Withdraw\n3.Display\n4.Exit\nEnter Choice: ");
choice=Integer.parseInt(in.readLine());
switch(choice)
{
case 1:System.out.print("Enter amount to be deposited: ");
da=Double.parseDouble(in.readLine());
b1.deposit(da);
break;
case 2:System.out.print("Enter amount to be withdrawn: ");
wa=Double.parseDouble(in.readLine());
b1.withdraw(wa);
break;
case 3:b1.display();
break;
case 4:i=1;
break;
default: System.out.println("Not a vaild choice.");
}
}
}
}
Sunday, December 20, 2009
Software to add, delete and print an item in shopping list in java
import java.util.*;
import java.io.DataInputStream; // to load DataInputStream class
class P34
{
public static void main(String args[ ])
{
Vector v = new Vector(5,2);
int count=0,i,choice, position;
String str = new String();
boolean flag = false;
String ans = "yes";
DataInputStream in = new DataInputStream(System.in);
count =args.length;
for(i=0;i
v.addElement(args[i]);
try
{
System.out.println("\n*********** Super Market **********\n");
do
{
System.out.println("\nSelect Any option (1 to 5)");
System.out.println("\t1. Delete an item ");
System.out.println("\t2. Add an item at a specific location ");
System.out.println("\t3. Add an item at the end of the list ");
System.out.println("\t4. Display Shopping List ");
System.out.println("\t5. Exit ");
choice = Integer.parseInt(in.readLine());
System.out.println();
switch(choice)
{
case 1:
/* Delete an Item */
System.out.print("Enter the item which you want to delete from shopping list : ");
str = in.readLine();
flag = v.removeElement(str);
if(flag==false)
System.out.println(" Item is not in the shopping list");
break;
case 2:
/* Add an item at a specific location */
System.out.print("Enter the item which you want to add in shopping list : ");
str = in.readLine();
System.out.print("Enter a specific location where you want to add an item : ");
position = Integer.parseInt(in.readLine());
v.insertElementAt(str,position-1);
break;
case 3:
/* Add an item at the end of the list */
System.out.print("Enter the item which you want to add in shopping list : ");
str = in.readLine();
v.addElement(str);
break;
case 4:
/* Display Shopping List */
Enumeration vEnum = v.elements();
System.out.println("\nItems in Shopping list are:");
while(vEnum.hasMoreElements())
System.out.println("\t"+vEnum.nextElement() +" ");
//System.out.println();
break;
default:
System.exit(0);
}
System.out.print("Do you Want to continue ? (Yes/No) : ");
ans=in.readLine();
}while(ans.equalsIgnoreCase("yes"));
}
catch(Exception e) { System.out.println("I/O Error"); }
}
}
import java.io.DataInputStream; // to load DataInputStream class
class P34
{
public static void main(String args[ ])
{
Vector v = new Vector(5,2);
int count=0,i,choice, position;
String str = new String();
boolean flag = false;
String ans = "yes";
DataInputStream in = new DataInputStream(System.in);
count =args.length;
for(i=0;i
v.addElement(args[i]);
try
{
System.out.println("\n*********** Super Market **********\n");
do
{
System.out.println("\nSelect Any option (1 to 5)");
System.out.println("\t1. Delete an item ");
System.out.println("\t2. Add an item at a specific location ");
System.out.println("\t3. Add an item at the end of the list ");
System.out.println("\t4. Display Shopping List ");
System.out.println("\t5. Exit ");
choice = Integer.parseInt(in.readLine());
System.out.println();
switch(choice)
{
case 1:
/* Delete an Item */
System.out.print("Enter the item which you want to delete from shopping list : ");
str = in.readLine();
flag = v.removeElement(str);
if(flag==false)
System.out.println(" Item is not in the shopping list");
break;
case 2:
/* Add an item at a specific location */
System.out.print("Enter the item which you want to add in shopping list : ");
str = in.readLine();
System.out.print("Enter a specific location where you want to add an item : ");
position = Integer.parseInt(in.readLine());
v.insertElementAt(str,position-1);
break;
case 3:
/* Add an item at the end of the list */
System.out.print("Enter the item which you want to add in shopping list : ");
str = in.readLine();
v.addElement(str);
break;
case 4:
/* Display Shopping List */
Enumeration vEnum = v.elements();
System.out.println("\nItems in Shopping list are:");
while(vEnum.hasMoreElements())
System.out.println("\t"+vEnum.nextElement() +" ");
//System.out.println();
break;
default:
System.exit(0);
}
System.out.print("Do you Want to continue ? (Yes/No) : ");
ans=in.readLine();
}while(ans.equalsIgnoreCase("yes"));
}
catch(Exception e) { System.out.println("I/O Error"); }
}
}
To Develop a Java project for Server Test
import java.util.*;
import java.io.*;
import java.net.*;
public class servertest
{
final static int SERVER_PORT = 8001;
public static void main(String a[])
{
Server server;
String creq,sr;
BufferedReader reader,read;
PrintWriter writer,write;
server = new Server(SERVER_PORT);
reader = new BufferedReader(new InputStreamReader(server.in));
writer = new PrintWriter(new OutputStreamWriter(server.out),true);
read = new BufferedReader(new InputStreamReader(System.in));
write = new PrintWriter(new OutputStreamWriter(System.out),true);
writer.println("Java Test Server " + new Date());
while(true)
{
try {
creq = reader.readLine();
System.out.println("Client says : " + creq);
sr = read.readLine();
writer.println(sr);
/*if(creq.equals("hai"))
writer.println("i am venkatesh");*/
if(creq.equals("quit"))
System.exit(0);
}catch(IOException e) {
System.out.println("Exception caught");
}
}
}
}
class Server
{
private ServerSocket server;
private Socket socket;
public InputStream in;
public OutputStream out;
public Server(int port)
{
try {
server = new ServerSocket(port);
System.out.println("ServerSocket before accept : "+server);
System.out.println("Java test server on-line");
socket = server.accept();
System.out.println("ServerSocket after accept : "+server);
in = socket.getInputStream();
out = socket.getOutputStream();
}catch(IOException e) {
System.out.println("caught server constructor");
}
}
}
import java.io.*;
import java.net.*;
public class servertest
{
final static int SERVER_PORT = 8001;
public static void main(String a[])
{
Server server;
String creq,sr;
BufferedReader reader,read;
PrintWriter writer,write;
server = new Server(SERVER_PORT);
reader = new BufferedReader(new InputStreamReader(server.in));
writer = new PrintWriter(new OutputStreamWriter(server.out),true);
read = new BufferedReader(new InputStreamReader(System.in));
write = new PrintWriter(new OutputStreamWriter(System.out),true);
writer.println("Java Test Server " + new Date());
while(true)
{
try {
creq = reader.readLine();
System.out.println("Client says : " + creq);
sr = read.readLine();
writer.println(sr);
/*if(creq.equals("hai"))
writer.println("i am venkatesh");*/
if(creq.equals("quit"))
System.exit(0);
}catch(IOException e) {
System.out.println("Exception caught");
}
}
}
}
class Server
{
private ServerSocket server;
private Socket socket;
public InputStream in;
public OutputStream out;
public Server(int port)
{
try {
server = new ServerSocket(port);
System.out.println("ServerSocket before accept : "+server);
System.out.println("Java test server on-line");
socket = server.accept();
System.out.println("ServerSocket after accept : "+server);
in = socket.getInputStream();
out = socket.getOutputStream();
}catch(IOException e) {
System.out.println("caught server constructor");
}
}
}
Subscribe to:
Posts (Atom)