Site Wide Message: (current site time 9/9/2010 8:17:57 PM EDT)
  • We want your input! One of our sponsors wants to know your opinion about development related issues. Click here to tell us what you think.
  • Are you an emerging/young developer (aged 18-30)? If so, would you like the chance to affect future developer tools and products?
    If so, then click here to give your feedback.
 

JavaDBArray

Print
Email
VB icon
Submitted on: 6/17/2010 8:32:16 AM
By: Olga Varlamova 
Level: Beginner
User Rating: By 1 Users
Compatibility:Java (JDK 1.5)

Users have accessed this code  1086 times.
 
 
     For a Java assignment in College. Enter data into an array, edit data and display contents of the array - set up as a customer form
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: JavaDBArray
// Description:For a Java assignment in College. Enter data into an array, edit data and display contents of the array - set up as a customer form
// By: Olga Varlamova
//
//This code is copyrighted and has// limited warranties.Please see http://www.PlanetSourceCode.com/vb/scripts/ShowCode.asp?txtCodeId=6665&lngWId=2//for details.//**************************************

/* Author Details
Name: Olia Varlamova
Phone = "0404 352 546";
For Mr Singh
 * This program stores customer details in an array
 * The program is designed to create new customer records
 *then update or view them
 */
package javacustomerfinalversion;
import java.util.Scanner;
/**
 *
 * @author olia
 */
public class Main {
/**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
appCustomer mycus = new appCustomer();
 mycus.mainDisplay();
 }
}
class Customer {
public int ID;
public String FName;
public String LName;
public String Address;
public String City;
public String Phone;
public String Fax;
public static int i = 1;
public Customer(){
i++;
}
Customer(int i, String f, String l, String a, String c, String p, String x){
ID = i;
FName = f;
LName = l;
Address = a;
City = c;
Phone = p;
Fax = x;
}
public void setID(int i){
ID = i;
}
 public void setFName(String f){
FName = f;
}
 public void setLName(String l){
LName = l;
}
 public void setAddress(String a){
Address = a;
}
 public void setCity(String c){
 City = c;
}
 public void setPhone(String p){
 Phone = p;
}
 public void setFax(String x){
 Fax = x;
}
 public int getID(){
 return ID;
 }
 public String getFName(){
 return FName;
 }
 public String getLName(){
 return LName;
 }
 public String getAddress(){
 return Address;
 }
 public String getCity(){
 return City;
 }
 public String getPhone(){
 return Phone;
 }
 public String getFax(){
 return Fax;
 }
/**
 * @param args the command line arguments
 */
}
 class appCustomer {
 Scanner in = new Scanner(System.in);
 Customer[] cus = new Customer[20];
 public void mainDisplay(){
int ans;
 int z =0;
while (true){
System.out.println ("Enter 1 for NEW record: ");
System.out.println ("Enter 2 for NEW Update: ");
System.out.println ("Enter 3 for Display:");
System.out.println ("Enter 4 for Exit:");
ans = in.nextInt();
switch(ans){
case 1:
cusInput(z);
z++;// method get input into the Customer Array
break;
case 2:
cusEdit();//method to update records in array
break;
case 3:
 display:
 for ( int i=0; i < cus.length ; i++)
{
if (cus[i]==null)
break display;
System.out.print(cus[i].getID()+ " ");
System.out.print(cus[i].getFName()+ " ");
System.out.print(cus[i].getLName()+ " ");
System.out.print(cus[i].getAddress()+ " ") ;
System.out.print(cus[i].getCity()+ " ") ;
System.out.print(cus[i].getPhone()+ " ") ;
System.out.println(cus[i].getFax()+ " ") ;
}
break;
case 4:
in.close();
System.exit(0);
}// switch
}//while
 }//displaymethod
 public void cusInput(int z)
 {
 int cid;
 String cFname;
 String cLname;
 String cAddress;
 String cCity ;
 String cPhone;
 String cFax;
 System.out.print ("Enter ID: ");
 cid = in.nextInt();
 System.out.print ("Enter first name: ");
 cFname = in.next();
 System.out.print ("Enter last name: ");
 cLname = in.next();
 System.out.print ("Enter address: ");
 cAddress = in.next();
 System.out.print ("Enter city: ");
 cCity = in.next();
 System.out.print ("Enter phone number: ");
 cPhone = in.next();
 System.out.print ("Enter fax number: ");
 cFax = in.next();
 System.out.println ("Customer record number is " + z);
cus[z] = new Customer();
cus[z].setID(cid);
cus[z].setFName(cFname);
cus[z].setLName(cLname);
cus[z].setAddress(cAddress);
cus[z].setCity(cCity);
cus[z].setPhone(cPhone);
cus[z].setFax(cFax);
System.out.println (cus[z].getID()+ " "+ cus[z].getFName()+ " "+
cus[z].getLName()+ " "+ cus[z].getAddress()+ " "+ cus[z].getCity()+ " "+ cus[z].getPhone()+ " "+ cus[z]. getFax());
 }
 public void cusEdit()
 {
 String cFname= "";
 String cLname= "";
 String cAddress= "";
 String cCity= "";
 String cPhone= "";
 String cFax= "";
System.out.println("Please enter CustomerID to edit");
int ans;
ans = in.nextInt();
cusedit:
 for (int i=0; i<cus.length; i++){
if (cus[i]==null){
 break cusedit ;
}
else{
 if (cus[i].getID() == ans){
System.out.print ("Would you like to change the First Name (true/false)? ");
boolean yesno = false;
if (yesno = in.nextBoolean()== true ){
System.out.print ("Enter first name: " + cus[i].getFName());
cFname = in.next();
}
System.out.print ("Would you like to change the Last Name? (true/false) ");
if (yesno = in.nextBoolean()== true ){
System.out.print ("Enter last name: " + cus[i].getLName());
cLname = in.next();
}
System.out.print ("Would you like to change the Address? (true/false) ");
if (yesno = in.nextBoolean()== true ){
System.out.print ("Enter address: " + cus[i].getAddress());
cAddress = in.next();
}
 System.out.print ("Would you like to change the City? (true/false) ");
if (yesno = in.nextBoolean()== true ){
System.out.print ("Enter city: " + cus[i].getCity());
cCity = in.next();
}
System.out.print ("Would you like to change the Phone number? (true/false) ");
if (yesno = in.nextBoolean()== true ){
System.out.print ("Enter phone number: " + cus[i].getPhone());
cPhone= in.next();
}
System.out.print ("Would you like to change the Fax number? (true/false) ");
if (yesno = in.nextBoolean()== true ){
System.out.print ("Enter fax number: " + cus[i].getFax());
cFax= in.next();
}
cus[i].setFName(cFname) ;
cus[i].setLName(cLname) ;
cus[i].setAddress(cAddress) ;
cus[i].setCity(cCity);
cus[i].setPhone(cPhone);
cus[i].setFax(cFax);
break ;
 }
 }
 }
 }
 }

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
6/20/2010 6:42:43 AMOlga Varlamova

All comments and suggestions are welcome
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!

Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.