Wednesday, January 31, 2007

Program:1 for noel

Hi friends here i added the first program for noel.
check noels requirements in here:
http://www.blogger.com/comment.g?blogID=5133484865049964130&postID=7557509313208084077



/*
Warning:
Handling year data also as string- not as an integer
when adding a new car.. we are not checking whether
same car already exists so there may be duplicates...
*/

import java.io.*;
import java.util.*;

public class fornoel{
ArrayList alcars;
fornoel(){
alcars=new ArrayList();
String[] soptions={ "1) Add a car", "2) View Car Details ",
"3) delete a car", "4) quit"
};
while(true){
for(int i=0;i<soptions.length;i++)
System.out.println(soptions[i]);
System.out.println("Enter your choice: ");
int choice=0;
Scanner scan=new Scanner(System.in);
choice=scan.nextInt();
switch(choice){
case 4:
return;
case 3:
if(alcars.isEmpty()){
System.out.println("There is nothing to delete..");
break;
}
System.out.println("Enter the make of the car :");
String make=scan.next();
if(!alcars.contains(make)){
System.out.println("No car exists in this make..");
break;
}
System.out.println("Enter the model of the car :");
String model=scan.next();
if(!alcars.contains(model)){
System.out.println("No car exists in this model..");
break;
}
System.out.println("Enter the year :");
String year=scan.next();
if(!alcars.contains(year)){
System.out.println("No record found at this year..");
break;
}
delete(make,model,year);
break;
case 2:
if(alcars.isEmpty()){
System.out.println("No record found ..");
break;
}
System.out.println("Enter the make of the car :");
make=scan.next();
showcars(make);
break;
case 1:
System.out.println("Enter the make of the car :");
make=scan.next();
System.out.println("Enter the model of the car :");
model=scan.next();
System.out.println("Enter the year :");
year=scan.next();
if(!alcars.isEmpty())alcars.trimToSize();
alcars.add(make);alcars.add(model);alcars.add(year);
break;
default:
System.out.println("Please enter a valid choice...");

}

}
}

void delete(String make,String model,String year){
boolean match=false;
if(alcars.isEmpty()) {
System.out.println("No records found..");
return;
}
Object[] objcars=alcars.toArray();
for(int i=0;i<objcars.length;objcars=alcars.toArray()){
boolean del=false;
if(objcars[i].equals(make)){
if(objcars[i+1].equals(model)){
if(objcars[i+2].equals(year)){
alcars.remove(i+2);alcars.remove(i+1);alcars.remove(i);
del=true;
match=true;
}
}
}
if(del==false) i+=3;
else{
if(alcars.isEmpty()) return;
if(!alcars.contains(make)) return;
i=0;
}
}
if(!match) System.out.println("No match found...");
}

void showcars(String make){
Object[] objcars=alcars.toArray();
for(int i=0;i<objcars.length;i+=3){
if(objcars[i].equals(make)){
System.out.println("make="+objcars[i]);
System.out.println("model="+objcars[i+1]);
System.out.println("year="+objcars[i+2]);
System.out.println("-------------------");
}
}
}

public static void main(String args[]){
new fornoel();
}
}

Thursday, December 14, 2006

Introduction

Hi Dear-all,
I am Pravinth. Am a graduate student.i want to tell you all why i have created this blog? Its beacuse of my passion about java and also i really want to do something, really want to contribute something to the society.So here i am to help others- So whom can i able to help? or who can get my help?.So what are my strengths? so that i can use it to help others? I am really good in core basic java-or at least i think so. but i am sure that i am not an expert in java still i have to learn more. So here i am to do some little java programs for you-who are totally new to it. So how am i going to do it? do i have enough time? Definitely not! so one way to do this is,-who are totally new to java send me your class programs or doubts in basic core java- if i know i will do the program and post it in here -in my blog with clear explanations.I have been greatly inspired by my friend Suleman. so let us start our work...so who is the first one going to finish his java program with our help in less time??? You can ask your doubt in XML also...