+ 3

JAVA Programming and Problem Solving

Seeking help for my study guide problem. Your task is to write a Java program that would represent an asset. Later on, you will be asked to extend this program and implement different types of assets as well as different types of applications and their relationship. As of now your program contain two classes: Asset Driver The former class, i.e. Asset, has to have the following attributes and methods: String Type. Can be one of the following: Server, Switch, Router, PSU (power supply unit), HDD, SSD, NIC (network interface card) int ID A unique number that identify any given asset. String Name General description of the asset including (if needed) vendor, hardware, model, etc. String serial Serial number of the asset which is a combination of characters usually found on a sticker affixed on some surface of the asset int PID Parent ID -- ID of the asset that appears to be "parent" to this one. For example Server asset is the "parent" of NIC asset because NIC is plugged into the server. In case when asset has no parent, this value has to be set to -1. "Getters" and "setters" for all attributes Default constructor (one that takes no parameters and uses default values of attributes) Method String toString() that returns textual presentation of an asset object. Values of all attributes must be used in compilation of that string. The latter class, i.e. Driver is used to host main() method that would instantiate a few objects of class Asset (use some illustrative cases like 1 server, 1 switch, 2 PSUs, 3 NICs, etc) and store references to those objects in an array. Then it would iterate through the array and for every asset it would print result returned by toString() method.

2nd Apr 2017, 11:35 PM
Terrence Donerson
Terrence Donerson - avatar
2 odpowiedzi
+ 6
You still need your Driver class And about the Asset class default constructor, does it means that you must set your own default value instead of leaving blank?
4th Apr 2017, 3:49 AM
Heng Jun Xi
Heng Jun Xi - avatar
+ 2
This is what I have so far, class Asset { private String type; private int id; private String name; private String serial; private int pid; public Asset() { type = ""; id = 0; name = ""; serial = ""; pid = -1; } public void setType(String type) { this.type = type; } public String getType() { return this.type; } public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setSerial(String serial) { this.serial = serial; } public String getSerial() { return this.serial; } public void setId(int id) { this.id = id; } public int getId() { return this.id; } public void setPid(int pid) { this.pid = pid; } public int getPid() { return this.pid; } @Override public String toString() { return "\n\n Type: " + getType() + " \n ID: " + getId() + " \n Name: " + getName() + " \n Serial: " + getSerial() + " \n PID: " + getPid() + " \n"; } }
2nd Apr 2017, 11:36 PM
Terrence Donerson
Terrence Donerson - avatar