JAVA
Write code to define a Customer class, which has id and name attributes of String data type and points attribute of integer data type, without breaking encapsulation.
Encapsulation:-- Encapsulation is the Hiding concept of the data.It is used to wrap the data into a single unit so that any outer member can not access thes rights.Encapsulation is the most important feature of Object Oriented Progarming Language.Java is the one pof the pure Object Oriented Programming Language,It can Ptovide the most security of the data.
Here i have written a Customer class which has three Private attributes which can not accsess out side .It can be access only by using getter and setter method.
You have to save the Customer class as Customer.java and Encapsulation.java then run the Programe ,You will get this out/put
Customer Name : Sushil Points:120 Customer Id:120
Programe Code:
public class Customer{
private String id;
private String name;
private int points;
public String getId() {
return id;
}
public String getName() {
return name;
}
public int getPoints() {
return points;
}
public String setId(String id) {
id=id;
}
public String setName(String name) {
name=name;
}
public String setPoints(int points) {
points=points;
}
}
public class Encapsulation{
public static void main(String args[]) {
Customer c1 = new Customer();
c1.setName("Sushil");
c1.setId("C-001");
c1.setPoints(120);
System.out.print("Customer Name : " + c1.getName() + " Age : " + c1.getPoints() + "CUstomer ID :" + c1.getId() );
}
}
Benifits of Encapsulation:--
1. A class i having total controll what it has data or field or properties
2. Data or field or properties can be only read or right .
JAVA Write code to define a Customer class, which has id and name attributes of String...
in java
need to review
20) (1 point) Write the constructor for the class Customer, which has the name and the ID of the Customer and a reference to an Account object as its attributes. You do not need to write anything for Account class or declare the Customer class's attributes, just write the constructor.
Define a class Horse with two attributes, a string name and an integer numLegs. Write a two parameter constructor and a toString() method. *Write a class named Coll3 with a static method "updateName". There are three parameters to the method: a collection, an old name, and a new name. For every horse in the collection, if it has the same name as the parameter oldname, then replace the horse's name with the parameter new name. example: updateName({[X,4],[G,4],[X,3]}, X, Y) changes...
The object class should be a Student with the following attributes: id: integer first name: String last name: String write the accessors, mutators, constructor, and toString(). In your main test class you will write your main method and do the following things: Create an array of Student objects with at least 5 students in your array. Write a sort method that must be your original work and included in the main class. The sort method will sort based on student...
In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes (name, symbol, numberOfShares, currentPrice and boughtPrice)and one static private attribute (numberOfStocks). All attributes must be initialized (name and symbol to “No name/ symbol yet” and numberOfShares, currentPrice and boughtPrice to 0. Create two constructors, one with no arguments and the other with all the attributes. (However, remember to increase the numberOfStocks in both constructors. Write the necessary mutators and accessors (getters and setters) for...
IN JAVA Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method...
Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides the following. • Two attributes: lastName and first Name of type String. • Appropriate initialization, accessors/mutator methods. 2. (6 marks) Write a Student class that is a subclass of Person class (in the previous question) which provides the following. • Two attributes: A unique student ID of type String and GPA of type float; the student ID is initialized when a Student object gets...
Java Program: Design a class “Book” with the data attributes title - String, author - String, yearPublished - integer and price - double. Write a parameterized constructor that initializes the attributes. Write accessor and mutator methods, and a print method that prints all of the attributes. In the main method, create a single object and give it values of your choice. Call the print method to print the values. Sample Run: The Book is: The Art of Computer Programming Donald...
Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...
C++ In the code cell below, define a class named Student with an integer id and a string name. This class should have a constructor that takes two arguments: one for the id and the other for the name. Then Create another class named CollegeStudent that publicly inherits from Student. This class should have a protected member named major. It should also have a constructor that takes three arguments: id, name, and major. This constructor should delegate initializing the id...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class. HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...