I am trying to create a getCounter() method which will count upwards each time the getCounter() method is called. For example if the method is called 10 times then the output should be: 1,2,3...10.
This is the current code I have:
Main class:
public class JavaLab5 {
public static final int DEBUG = 0;
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
Student s[] = new Student[10];
s[0] = new MathStudent("Smith");
s[1] = new MathStudent("Jack");
s[2] = new MathStudent("Victor");
s[3] = new MathStudent("Mike");
s[4] = new ScienceStudent("Dave");
s[5] = new ScienceStudent("Oscar");
s[6] = new ScienceStudent("Peter");
s[7] = new ComputerStudent("Philip");
s[8] = new ComputerStudent("Shaun");
s[9] = new ComputerStudent("Scott");
for (int loop = 0; loop < 10; loop++) {
System.out.print(loop);
System.out.println(s[loop].getSubjects());
}
}
}
Student class:
public class Student {
String name;
int count
public static int instances = 0;
//Getters
public String getName() {
return this.name;
}
// Setters
public void setName(String name) {
if (JavaLab5.DEBUG > 3) System.out.println("In Student.setName. Name = "+ name);
this.name = name;
}
/**
* Default constructor. Populates name,age and gender
* with defaults
*/
public Student() {
instances++;
this.name = "Not Set";
}
/**
* Constructor with parameters
* #param name String with the name
*/
public Student(String name) {
this.name = name;
}
/**
* Destructor
* #throws Throwable
*/
protected void finalize() throws Throwable {
//do finalization here
instances--;
super.finalize(); //not necessary if extending Object.
}
public void getCounter() {
for (int x = 0; x < 10; x++) {
count++;
System.out.println(count);
}
}
public String toString () {
return this.name;
}
public String getSubjects() {
return this.getSubjects();
}
}
My question is how I can implement such a method to call it from my Main class.
Two possibilities :
You wish to count every time you call the function and have a fresh counter for every object
public class Student {
String name;
int count =0; // every object of class Student will have its own `count`
//rest of the declrataions / functions
public void getCounter() {
System.out.println(++count);
}
}
You wish one counter that counts up every time you call getCounter irrespective of the number of objects you have of the class Student
public class Student {
String name;
static int count = 0; //static so that multiple object instances of the class share the same `int count`
//rest of the declrataions / functions
public void getCounter() {
System.out.println(++count);
}
}
If your question is how to implement such a method, try this:
private int myCounter = 0;
//Use this line instead if you want a global counter for all Studen-Objects
//private static int myCounter = 0;
public void getCounter() {
System.out.println(myCounter);
myCounter++;
}
You state you want to count how many times a method was called. In addition you want to print a sequence of all numbers starting from 1 to the number of counted method calls. Addressing concurrency, my solution would be:
public class CountTracker {
private static final AtomicInteger counter = new AtomicInteger();
public static int count() {
return counter.incrementAndGet();
}
public static void printCounter() {
int count = counter.get();
if (count == 0) return;
StringBuilder builder = new StringBuilder();
for (int i = 1; i <= count; i++) builder.append(i).append(",");
builder.deleteCharAt(builder.length() - 1);
System.out.println(builder);
}
}
The method count() represents the method you want to track. I have no idea why your solution does include a class Student.
simply remove for loop in getCounter method
change :
public void getCounter() {
for (int x = 0; x < 10; x++) {
count++;
System.out.println(count);
}
}
to :
public void getCounter() {
System.out.println(count);
count++;
}
Related
So i am trying to make a deal or no deal game the game is not finished yet but the biggest issue i am having is that when i am trying to assign an array list to a array of type cases it seems like it isn't getting assigned.
I tried to debug and after shuffle the output is correct but i am unable to assign the result to the case array so that i can use it in game
Below are my 3 classes upon assigning the outcome i am getting is
The line i am talking about is the method available cases
public class Case {
private int value = 0;
private String face;
/*
* Constructor for type Case
*/
public Case(int value)
{
this.value = value;
}
/*
* Getter and setter methods for instance data
*/
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public String getFace() {
return face;
}
public void setFace(String face) {
this.face = face;
}
}
public class Player {
private String name;
private int age;
private boolean canPlay = false;
private int money = 0;
/*
* Constructor for type Player
*/
public Player(String name, int age) {
super();
this.name = name;
this.age = age;
}
/*
* Getter and Setter methods for all instance Data
*/
public Player(boolean canPlay)
{
this.canPlay = canPlay;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public boolean isCanPlay() {
return canPlay;
}
public void setCanPlay(boolean canPlay) {
this.canPlay = canPlay;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
/*
* This method will check if the person playing is at least 18 years old or not
*/
public void checkAge()
{
if(age >= 18)
{
canPlay = true;
System.out.println("Seems like you are old enough to play!");
System.out.println("Let's get started");
}
else
{
canPlay = false;
System.out.println("OH NO! you aren't old enough sadly we won't be able to continue");
}
}
public String toString() {
return "Today's player is "+name+" who is "+age+" old";
}
public static void setupPlayer()throws InputMismatchException
{
String playerName;
int playerAge;
System.out.println("Welcome to the Deal or No Deal game!");
System.out.println("Please state your name:");
Scanner name = new Scanner(System.in);
playerName = name.nextLine();
System.out.println("Welcome "+playerName+" how old are you?");
Scanner age = new Scanner(System.in);
playerAge = age.nextInt();
Player gamePlayer = new Player(playerName, playerAge);
}
public static void Rules()
{
System.out.println("Below listed are the Game Rules\n");
System.out.println("-There are 12 Cases in the game");
System.out.println("-Each case contains a amount of money and you will be "
+ "offered these Cases 1 at a time");
System.out.println("-Upon picking a Case the game will end and you will have a "
+ "chance to walk away with that case");
System.out.println("-If No cases are picked you will get 2 option, to walk away"
+ " with the last Case or take the bankers offer");
System.out.println("-To accept the case type \"Y\" ,to decline it type \"N\"");
}
}
public class SetUpCases {
private Case[] cases = new Case[12];
/*
* This method initializes each object type with an amount which will be the Money in each Case
*/
public void settingUpCases()
{
ArrayList<Integer> myCase= new ArrayList<Integer>();
myCase.add(new Integer(1));
myCase.add(new Integer(50));
myCase.add(new Integer(100));
myCase.add(new Integer(250));
myCase.add(new Integer(500));
myCase.add(new Integer(1000));
myCase.add(new Integer(2500));
myCase.add(new Integer(5000));
myCase.add(new Integer(10000));
myCase.add(new Integer(25000));
myCase.add(new Integer(50000));
myCase.add(new Integer(100000));
/*
* The Shuffle changes which index has what value so game results are different each time played!
*/
Collections.shuffle(myCase);
for(int i = 0; i < cases.length; i++)
{
int value = myCase.get(i);
cases[i] = new Case (value);
System.out.println(cases[i]);
}
}
/*
* Shows which Cases are still available
*/
public void availableCases()
{
for (int k = 0; k < cases.length; k++)
{
System.out.println(cases[k]);
}
}
public void startGame()
{
settingUpCases();
}
}
You are printing case object instead of its value.. use getValue (or getFace) method to print the value (or face). For example
for (int k = 0; k < cases.length; k++)
{
System.out.println(cases[k].getValue());
}
If you want to print both value and face, the best way will be to override the toString method and print these variables there.
The reason you are getting those weird values is not because the assignments aren't working but because you aren't printing the string value of your values. Try the following.
for(int i = 0; i < cases.length; i++){
int value = myCase.get(i);
cases[i] = new Case (value);
System.out.println(Arrays.toString(cases[i]));
}
I'm learning java. I have trouble about arraylist in my java program. How can I remove a room in arraylist in Room and count the number of rooms has the size smaller than 40. I just coded 2 methods which were removeRoom and countRoomBySize in class MyRoom. My code has error in Net Beans. Anyone help me to check this code, please. Thank so much. Here is my code
My Main class
public class MyMain {
public static void main(String[] args) {
//create a list of rooms
MyRoom m = new MyRoom();
m.addRoom(new Room("HB201L",35));
m.addRoom(new Room("HB401R",45));
m.addRoom(new Room("211",30));
m.sort();
m.list();
//1.
m.removeRoom("211");
m.list();
//2.
int c = m.countRoomBySize(40);
System.out.println(c);//2
}
}
Class Room
public class Room implements Comparable<Room> {
#Override
public int compareTo(Room o) {
return o.name.compareToIgnoreCase(this.name);
}
//instanced variables
private int size;
private String name;
public Room() {
name = "";
size = 0;
}
public Room(String name, int size) {
this.name = name;
this.size = size;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Class MyRoom
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class MyRoom implements IRoom {
List<Room> rooms;
public MyRoom() {
rooms = new ArrayList();
}
#Override
public void addRoom(Room r) {
//append r to the end of list rooms
rooms.add(r);
}
#Override
public void list() {
for (int i = 0; i < rooms.size(); i++) {
Room r = rooms.get(i);
System.out.printf("%-20s%-10d\n",r.getName(),r.getSize());
}
}
#Override
public void removeRoom(){
for (int i = 0; i < rooms.size(); i++) {
if(rooms.get(i).getName() == "211")
rooms.remove(rooms);
}
}
#Override
public int countRoomBySize(){
int s,i,n;
n = rooms.size();
s = 0;
for(i=0;i<n;i++) {
if(rooms.get(i).getSize() > 40)
s++;
}
return(s);
}
public void sort() {
Collections.sort(rooms);
}
}
Interface IRoom
public interface IRoom {
//only contain public members: constants and method declaration
public final int MAX = 10;
public void addRoom(Room r);
public void list();
public void removeRoom();
public int countRoomBySize();
}
interface A {
void f();
}
interface B extends A {
void g();
}
interface C {}
First change your interface IRoom like this :
public void removeRoom(String name);
public int countRoomBySize(int size);
In the MyRoom class change removeRoom method like this :
#Override
public void removeRoom(String name){
for (int i = 0; i < rooms.size(); i++) {
if(name.equalsIgnoreCase(rooms.get(i).getName())){
rooms.removeIf(r -> r.getName().equals(name));
System.out.println("Removed !");
}
}
}
And the countRoomBySize method like this :
#Override
public int countRoomBySize( int size){
int s,i,n;
n = rooms.size();
s = 0;
for(i=0;i<n;i++) {
if(rooms.get(i).getSize() > size)
s++;
}
return(s);
}
Best of luck !
removeRoom can be shortened to: rooms.remove(rooms.indexOf("211")) or perhaps even rooms.remove("211");
Nice that you are starting to learn java.
The simplest solution here is to put your room in an Hashmap and store the room number as key;
public class MyMain {
public static void main(String[] args) {
Hashmap<String,Room> rooms = new Hashmap();
rooms.add("211",new Room("HB201L",35);
rooms.add("HB401R",new Room("HB401R",45);
rooms.remove("211");
int size = rooms.size();
int smallRooms = calculateSmallRooms(rooms.values(),30);
}
private int calculateSmallRooms(Collection<Room> rooms, int minimalSize) {
int smallRooms = 0;
for(Room room: rooms) {
if (room.size < minimalSize) {
smallRooms++;
}
return smallRooms;
}
I am making a multiplayer adventure game for my networking class. I have a client and a server, the server is multithreaded, and kicks off a new thread whenever it gets a new client connected. I have an array list that keeps track of the players to make sure that a new player isn't added. For some reason, when a new client connects, it takes the place of the old one as well as filling a new spot. Here is my code for this part
public class ClientHandler implements Runnable{
private AsynchronousSocketChannel clientChannel;
private static String command[];
private static String name;
private static GameCharacter character;
public ClientHandler(AsynchronousSocketChannel clientChannel)
{
this.clientChannel = clientChannel;
}
public void run(){
try{
System.out.println("Client Handler started for " + this.clientChannel);
System.out.println("Messages from Client: ");
while ((clientChannel != null) && clientChannel.isOpen()) {
ByteBuffer buffer = ByteBuffer.allocate(32);
Future result = clientChannel.read(buffer);
//Wait until buffer is ready
result.get();
buffer.flip();
String message = new String(buffer.array()).trim();
if(message == null || message.equals(""))
{
break;
}
System.out.println(message);
clientChannel.write(buffer);
try {
//Add the character to the routing table and the character table
if (message.contains("connect")) {
System.out.println("I'm here too?");
command = message.split(" ");
name = command[1];
AdventureServer.userInfo.put(name, this);
//Check to see if this game character exists
GameCharacter test;
boolean exists = false;
for(int i=0; i < AdventureServer.characters.size(); i++)
{
test = AdventureServer.characters.get(i);
System.out.println(test.getName());
System.out.println(this.name);
if(this.name.equals(test.getName()))
{
System.out.println("already Here");
exists = true;
}
}
if (exists == true)
{
//This person has connected to the server before
}
else {
//Create a game character
System.out.println("didn't exist before");
character = new GameCharacter(this.name, World.getRow(), World.getCol());
AdventureServer.characters.add(AdventureServer.userInfo.size() - 1, character);
System.out.println(AdventureServer.characters.get(0).getName() + " " +AdventureServer.characters.get(1).getName());
}
}
I understand that the print lines at the bottom will throw an error for the first client that connects, but that is not part of the issue.
And here is the declaration of the server
public class AdventureServer {
public static Map<String, ClientHandler> userInfo = new HashMap<>();
public static World world;
public static List<GameCharacter> characters = Collections.synchronizedList(new ArrayList<>());
public static void main(String args[]) {
//Create the games map that all of the users will exist on
world = new World(args[0]);
System.out.println("Asynchronous Chat Server Started");
try {
AsynchronousServerSocketChannel serverChannel = AsynchronousServerSocketChannel.open();
InetSocketAddress hostAddress = new InetSocketAddress("192.168.1.7", 5000);
serverChannel.bind(hostAddress);
while (true)
{
System.out.println("Waiting for client to connect");
Future acceptResult = serverChannel.accept();
AsynchronousSocketChannel clientChannel = (AsynchronousSocketChannel) acceptResult.get();
new Thread (new ClientHandler(clientChannel)).start();
}
} catch (Exception e) {
System.out.println("error interrupted");
e.printStackTrace();
System.exit(0);
}
}
}
Here is my constructor for game characters
public class GameCharacter {
public static int xpos;
public static int ypos;
private static String name;
private static int rowSize;
private static int columnSize;
static List<String> inventory = new ArrayList<>();
//Constructor
GameCharacter(String n, int rSize, int cSize)
{
xpos = 0;
ypos = 0;
name = n;
rowSize = rSize;
columnSize = cSize;
}
GameCharacter()
{
xpos = 0;
ypos = 0;
name = "billybob";
rowSize = 10;
columnSize = 10;
}
You can try:
public static volatile List<GameCharacter> characters = Collections.synchronizedList(new ArrayList<>());
Update:
The problem is that you are using a non synchronized HashMap userInfo.
Change that line from:
AdventureServer.characters.add(AdventureServer.userInfo.size() - 1, character);
To:
AdventureServer.characters.add(character);
Or make your HashMap Synchronized:
public static Map<String, ClientHandler> userInfo = Collections.synchronizedMap(new HashMap<>());
All those static declarations are making problems, you should remove them. In general you should avoid using static.
ClientHandler:
private static String command[];
private static String name;
private static GameCharacter character;
GameCharacter:
public static int xpos;
public static int ypos;
private static String name;
private static int rowSize;
private static int columnSize;
static List<String> inventory = new ArrayList<>();
Just a side note, this way your Class is more like Java code should look like:
import java.util.ArrayList;
import java.util.List;
public class GameCharacter {
private int xpos;
private int ypos;
private String name;
private int rowSize;
private int columnSize;
private List<String> inventory = new ArrayList<>();
// Constructor
GameCharacter(String n, int rSize, int cSize) {
this.xpos = 0;
this.ypos = 0;
this.name = n;
this.rowSize = rSize;
this.columnSize = cSize;
}
GameCharacter() {
this.xpos = 0;
this.ypos = 0;
this.name = "billybob";
this.rowSize = 10;
this.columnSize = 10;
}
public int getXpos() {
return xpos;
}
public void setXpos(int xpos) {
this.xpos = xpos;
}
public int getYpos() {
return ypos;
}
public void setYpos(int ypos) {
this.ypos = ypos;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRowSize() {
return rowSize;
}
public void setRowSize(int rowSize) {
this.rowSize = rowSize;
}
public int getColumnSize() {
return columnSize;
}
public void setColumnSize(int columnSize) {
this.columnSize = columnSize;
}
public List<String> getInventory() {
return inventory;
}
public void setInventory(List<String> inventory) {
this.inventory = inventory;
}
}
As a matter of readability, testability, and style, I would also recommend you not directly access data structures belonging to another class. Instead of
Adventureserver.characters.add(blah blah)
I would recommend making characters a private field of Adventureserver, and then creating a method to add or remove characters from it. In fact, I would be inclined not to make characters static -- there is no real advantage, and you might at some point want more than one Adventureserver running.
Sort of like so:
public class AdventureServer {
<...>
private List<GameCharacter> characters = Collections.synchronizedList(new ArrayList<>);
<...>
public void addCharacter(GameCharacter char) {
<... error checking ...>
characters.add(char);
}
public void removeCharacter(GameCharacter char) {
<... implementation ... >
}
public boolean isCharacterHere(GameCharacter char) {
}
public List<GameCharacter> getCharacters() {
<... you could either return characters here, or a copy of it,
depending upon how paranoid you want to be >
I am trying to write a program where I ask to the user how many persons he wants to implement in this world. Afterwards, I would like as many person objects as the user answered. I defined a person class with a person constructor containing all person variables ( + getters/setters). After this, I tried to create a loop to assign values to my variables (most of them happen random). Currently, I set the number of instances I want to create to 20 (arbitrary).
This is my person class
public class Person implements Item {
public static final int MAX_AGE = 70;
public static final int MAX_SEX_APPEAL = 10;
public static final int MAX_AGRESSION_LEVEL = 10;
public static final int MAX_STRENGTH = 10;
private int id;
private int age;
private boolean gender;
private int sexAppeal;
private int agressionLevel;
private int strength;
private boolean isAlive;
public Person (int id, int age, boolean gender, int sexAppeal, int agressionLevel, int strength, boolean isAlive){
this.setId(id);
this.setAge(age);
this.setGender(gender);
this.setSexAppeal(sexAppeal);
this.setAgressionLevel(agressionLevel);
this.setStrength(strength);
this.setAlive(isAlive);
}
void getBorn () {
isAlive = true;
age = 0;
// a new people is born
// age = 0
// other variables: random
}
void die () {
isAlive = false;
// people die when they reach the max age
// people die when being on the same cell as vulcanos
// people can be murdered
// setAlive = false
}
void murder () {
// when 2 people with min agression level on the same land ==> weakest one dies
}
void move () {
// method to make people move
// random (only to adjucant fields)
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean isGender() {
return gender;
}
public void setGender(boolean gender) {
this.gender = gender;
}
public int getSexAppeal() {
return sexAppeal;
}
public void setSexAppeal(int sexAppeal) {
this.sexAppeal = sexAppeal;
}
public int getAgressionLevel() {
return agressionLevel;
}
public void setAgressionLevel(int agressionLevel) {
this.agressionLevel = agressionLevel;
}
public int getStrength() {
return strength;
}
public void setStrength(int strength) {
this.strength = strength;
}
public boolean isAlive() {
return isAlive;
}
public void setAlive(boolean isAlive) {
this.isAlive = isAlive;
}
}
And this is my "test class" where I try to create 20 instances :
import java.util.concurrent.ThreadLocalRandom;
public class test {
public static void main(String[] args) {
for (int i = 0; i < 20; i ++) {
Person person(i) = new Person();
person.setId(i);
person.setAge(ThreadLocalRandom.current().nextInt(0, Person.MAX_AGE + 1));
person.setGender((Math.random() < 0.5));
person.setSexAppeal(ThreadLocalRandom.current().nextInt(0, Person.MAX_SEX_APPEAL + 1));
person.setAgressionLevel(ThreadLocalRandom.current().nextInt(0, Person.MAX_SEX_APPEAL + 1));
person.setStrength(ThreadLocalRandom.current().nextInt(0, Person.MAX_SEX_APPEAL + 1));
person.setAlive(true);
}
}
}
However, I am getting the following error at this line
Person person(i) = new Person();
The constructor Person () is undefined
Type mismatch: cannot convert from Person to int
I understand those errors but I don't know another way to become to the result I want to achieve
You should make a list and just add the created persons to it.
public class test {
public static void main(String[] args) {
List<Person> persons = new ArrayList<>(); // create a list to store the generated persons
for (int i = 0; i < 20; i++) {
Person person = new Person(); // generate a person
person.setId(i);
person.setAge(ThreadLocalRandom.current().nextInt(0, Person.MAX_AGE + 1));
person.setGender((Math.random() < 0.5));
person.setSexAppeal(ThreadLocalRandom.current().nextInt(0, Person.MAX_SEX_APPEAL + 1));
person.setAgressionLevel(ThreadLocalRandom.current().nextInt(0, Person.MAX_SEX_APPEAL + 1));
person.setStrength(ThreadLocalRandom.current().nextInt(0, Person.MAX_SEX_APPEAL + 1));
person.setAlive(true);
persons.add(person); /// add the generated person to the list
}
}
}
Also if you want to call the Person constructor without parameters the class must have a constructor that takes no parameters.
public Person() {}
I'm a bit confused
I created a class called person, that has an age and name attributes (and get set methods).
Then in another class I want to create an array of persons , where each person has a different age and name.
But some how in the end all of my persons end up with the last name and age.
If I manually create them then it is ok, but with a for loop I've got that problem.
What should I do to get different persons?
Here is the code of the person class:
public class person {
static String name;
static int age;
public person() {
name="name";
age=0;
}
public static String getName() {
return name;
}
public static void setName(String name) {
person.name = name;
}
public static int getAge() {
return age;
}
public static void setAge(int age) {
person.age = age;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
And here is the code where I want to create my array/matrix:
public class array {
static person[][] a;
public static void main(String[] args) {
a=new person[3][3];
//manual created person
person first=new person();
person second=new person();
person third=new person();
first.setAge(12);
first.setName("first");
second.setAge(20);
second.setName("second");
third.setAge(40);
third.setName("third");
//automatic (here I get the disired effect)
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
a[i][j]=new person();
a[i][j].setAge(10+j);
a[i][j].setName("Alia"+i);
System.out.println(i+" "+j+" "+a[i][j].getName()+" "+a[i][j].getAge());
}
}
// a[0][0]=first;
// a[0][1]=second;
// a[1][2]=third;
// System.out.println(a[0][0].getName()+" "+a[0][0].getAge());
//for checking , and it doesnt work anymore
System.out.println(a[0][0].getName()+" "+a[0][0].getAge());
// for (int i = 0; i < a.length; i++) {
// for (int j = 0; j < a.length; j++) {
// System.out.println(i+" "+j+" "+a[i][j].getName()+" "+a[i][j].getAge());
// }
//
// }
getname();
}
private static void getname() {
System.err.println("get name function");
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
System.out.println(a[i][j].getName());
}
}
}
}
Remove the static keyword from the persons attributes. If it is static it is used by all instances (all person objects).
But I would do it like this:
public class Person {
public final String name;
public final int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String toString() {
return name + " (" + age + ")";
}
public static void main(String... args) {
List<Person> people = new LinkedList<Person>();
people.add(new Person("David", 28));
people.add(new Person("Andreas", 27));
System.out.println(people);
}
}
Yes, your attributes are declared static. A static attribute "belongs" to the class, not the instances, so all instances see the same String and int. You should be fine just removing the static from everything but main(). Then, new Person() will allocate new separate variables for everybody.
Problem is the static fields. Last values assigned to them would be reflected in all the object.