Question 1: a. ) You are iven a class called Person. The person has two fields: id, and name. Please implement a non-sta

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Question 1: a. ) You are iven a class called Person. The person has two fields: id, and name. Please implement a non-sta

Post by answerhappygod »

Question 1:
a. ) You are iven a class called Person. The person has twofields: id, and name. Please implement a non-static PersonFactorythat has a createPerson() method that takes a person's name andreturns a new instance of Person. The id of the person returnedshould be set as a 0-based index of the object created by thatfactory. So, the first person the factory makes should have id=0,second id=1 and so on.
class Person
{
public int id;
public String name;
public Person(int id, String name)
{
this.id = id;
this.name = name;
}
class PersonFactory
{
public Person createPerson(String name)
{
}
}
b.)
Given the following class definitions, you are asked toimplement Line.deepCopy() to perform a deep copy of the currentLine object.
class Point
{
public int x, y; public Point(int x, int y {
this.x = x;
this.y = y;
}
}
class Line
{
public Point start, end;
public Line(Point start, Point end)
{
this.start = start;
this.end = end;
}
public Line deepCopy()
{
// todo
}
}
c.) Since implementing a singleton is easy, you have a differentchallenge: write a method called isSingleton(). This method takes afactory method that returns as object and its up to you todetermine whether or not that object is a singleton instance.
import java.util.function.Supplier;
class SingletonTester
{
public static boolean isSingleton(Supplier<Object>func)
{
// todo
}
}
{
public int id;
public String name;
public Person(int id, String name)
{
this.id = id;
this.name = name;
}
class PersonFactory
{
public Person createPerson(String name)
{
}
}
Question 2
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply