Question

In: Computer Science

I would like to see a java language example using classes customer() and animal() which get...

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.

Solutions

Expert Solution

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


Related Solutions

Hi I would like to see an example in c++ of Stack As Linked List I...
Hi I would like to see an example in c++ of Stack As Linked List I need a seek() function which receives a double number X and which returns in which position in the stack is X. If the value X is not in the stack, the function should return -1
I need to see a working example using inheritance and the classes (below) The person class...
I need to see a working example using inheritance and the classes (below) The person class has first name last name age hometown a method called getInfo() that returns all attributes from person as a String The student class is a person with an id and a major and a GPA student has to call super passing the parameters for the super class constructor a method called getInfo() that returns all attributes from student as a String this methods has...
Based on Chandler’s logic of managerial enterprise,I would like to get the explanation and brief example...
Based on Chandler’s logic of managerial enterprise,I would like to get the explanation and brief example of Managerial Enterprise: Large industrial concerns operating and investment decisions are made by a hierarchy of salaried managers managers governed by a board of directors
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
in java language. There are three classes for the project, and two inner classes defined in...
in java language. There are three classes for the project, and two inner classes defined in the Cuboid class. Create the following classes: •   Shape. It’s an abstract class with two abstract methods, area and perimeter. •   Rectangle. It’s a concrete class that extends Shape. Implement area() and perimeter(). Implement the compareTo(object) method to sort rectangles by area in ascending order. •   Cuboid. It’s a concrete class that extends Rectangle. A cuboid is a 3D rectangle. The shape has a...
Java Programming: Can I get an example of a program that will allow 4 options? Example...
Java Programming: Can I get an example of a program that will allow 4 options? Example Output: Choose on of the options below: 1. Display all items in CSV file. (CSV file includes for example brand of phone, size, price) 2. Pick an item by linear searching 3. Pick an item by bineary searching 4. Quit Program
How would I get this java code to work and with a main class that would...
How would I get this java code to work and with a main class that would demo the rat class? class rat { private String name; private String specialAbility; private int TotalHealth; private int shieldedHealth; private int cooldown; public rat() { } public rat(String n,String SA,int TH,int SH,int cd) { name=n; specialAbility=SA; TotalHealth=TH; shieldedHealth=SH; cooldown=cd; } public void setname(String n) { name=n; } public String getname() { return name; } public void setability(String SA) { specialAbility=SA; } public String getability()...
I would like to see a proof of the Central Limit Theorem that applies to a...
I would like to see a proof of the Central Limit Theorem that applies to a simple probability dice scenerio, say rolling a 6 x amount of times. The goal is to help me understand the theorem with a simple example. Thanks!
Objective: Using Java coding language, complete each "TO-DO" section for the following classes. Shape code (for...
Objective: Using Java coding language, complete each "TO-DO" section for the following classes. Shape code (for reference, nothing to complete here): import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import java.io.RandomAccessFile; public abstract class Shape extends Rectangle {    public int id;    public Color color;    public int xSpeed, ySpeed;       public Shape(int id, int x, int y, int width, int height, Color color, int xSpeed, int ySpeed) {        super(x,y,width,height);        this.id = id;        this.color...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT