In: Computer Science
I would like to see a java language example using classes customer() and animal() which get user input and return the information to class database().
class customer() should return user input for firstName, lastName, address, phoneNum, customerNum.
class animal() should return information for animalName, animalType, gender, animalLocation.
Code:
import java.util.Scanner;
class customer {
private String firstName, lastName, address, phoneNum;
private int customerNum;
Scanner s = new Scanner(System.in);
void getCustomerData() {
System.out.println("Enter the first name : ");
firstName = s.nextLine();
System.out.println("Enter the last name : ");
lastName = s.nextLine();
System.out.println("Enter the address : ");
address = s.nextLine();
System.out.println("Enter the phone number : ");
phoneNum = s.nextLine();
System.out.println("Enter the customer number : ");
customerNum = s.nextInt();
}
void displayCustomerData() {
System.out.println("First name : " + firstName);
System.out.println("Last name : " + lastName);
System.out.println("Address : " + address);
System.out.println("Phone number : " + phoneNum);
System.out.println("Customer number : " + customerNum);
}
}
class animal {
private String animalName, animalType, gender,
animalLocation;
Scanner s = new Scanner(System.in);
void getAnimalData() {
System.out.println("Enter the animal name : ");
animalName = s.nextLine();
System.out.println("Enter the animal type : ");
animalType = s.nextLine();
System.out.println("Enter the gender : ");
gender = s.nextLine();
System.out.println("Enter the animal location : ");
animalLocation = s.nextLine();
}
void displayAnimalData() {
System.out.println("Animal name : " + animalName);
System.out.println("Animal Type : " + animalType);
System.out.println("Gender : " + gender);
System.out.println("Animal location : " + animalLocation);
}
}
public class database {
public static void main(String []args) {
customer c = new customer();
animal a = new animal();
c.getCustomerData();
a.getAnimalData();
c.displayCustomerData();
a.displayAnimalData();
}
}
Enter the first name :
Jon
Enter the last name :
Rem
Enter the address :
USA
Enter the phone number :
123999555
Enter the customer number :
1
Enter the animal name :
dog
Enter the animal type :
lhasa
Enter the gender :
female
Enter the animal location :
usa
First name : Jon
Last name : Rem
Address : USA
Phone number : 123999555
Customer number : 1
Animal name : dog
Animal Type : lhasa
Gender : malfemale
Animal location : usa