)))))) THIS IS THE QUESTION )))))) Submission requirements: Submit one or more j
ID: 3708956 • Letter: #
Question
)))))) THIS IS THE QUESTION ))))))
Submission requirements:
Submit one or more java files representing required class hierarchy.
Problem formulation
Following previous assignment (development of the Asset class) you now need to extend it and create a few derivative classes, i.e. a Router, a Switch, a Server, a PSU (Power Supply Unit) etc. Each of those new classes has to be declared as extending the base Asset class and introduce new attributes and methods. For example, you may consider the following skeletons or add something that matches your expectations:
Router
String application; // one from the following list "Home", "Core", "Infrastructure", etc
int numOfNICs; // number of network interfaces
String OS; // operating system. including vendor, version, and other details
boolean hasConsole; // flag that indicates presence of management console
Switch
int numOf_100M; // number of 100Mb ethernet interfaces
int numOf_1G; // number of 1Gb ethernet interfaces
int numOf_10G; // number of 10Gb ethernet interfaces
int numOf_SFP; // number of SFP modules
String OS; // operating system. including vendor, version, and other details
String level; one from the following list "L2", "L3", "L4"
Server
String OS; // same as with the Router
int NumOfNICs; // same as with the Router
boolean isVirtualized; // flag that shows whether or not this server is a Virtual Machine running on some virtualization platform
You may add more types of assets, and more attributes into each asset to make it looking more realistic, but the grading decision will be based on whether or not inheritance is defined correctly. Inheritance should not be considered as only including keyword "extends" in the declaration of a class, but mainly as a proper set of methods that have to be either added or overridden. One of such methods would be the constructor, such that constructor of the Router class will be different than constructor of the Switch class, but both should call constructor of the Asset class by using super(); notation. You may also consider adding up getters/setters for the extended set of attributes.
Please also have in mind that a customized version of toString() method is needed for each derivative class in order to be able to "print" corresponding objects. Such method is about to return presentation of all valuable class attributes in form of a formatted String object.
Finally, your Driver program also needs to be revised to update the way how different assets are instantiated:
Previously:
Asset A1 = new Asset("server", "HP Proliant ML350 G6", "876245", ...);
Asset A2 = new Asset("switch", "Netgear GS108T", "782364", ...);
After introducing new sub-classes:
Asset A1 = new Server("server", "HP Proliant ML350 G6", "876245", ...);
Asset A2 = new Switch("switch", "Netgear GS108T", "782364", ...);
Despite both forms look alike, the latter is different as each object is now created by a dedicated constructor so a unique set of attributes is being used.
)))))) AND THIS IS THE PROGRAMM I MADE ON THE PREVIOUS ASSIGNMENT ))))))
)))))) I HAVE SUBMITTED 2 FILES FOR MY LAST ASSINGMENT (One is "Asset" and The other one is "Assignment7_main" ))))))
)))))) Assignment7_main File ))))))
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment7;
import java.util.*;
/**
*
*
*
*/
public class Assignment7_main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ArrayList<Asset> assets = new ArrayList<Asset>();
Asset Stereo = new Asset("Stereo",1234554321,"Cisco 28011082","ABCDEFGHIJKLLKJHGFDSA",-1);
System.out.println(Stereo);
Asset Television = new Asset("TV",12345,"Cisco 2801", "ABCDEFGHIJKA", -1);
System.out.println(Television);
Asset VCR = new Asset("VCR",54321,"Cisco 1082", "LKJHGFDSA", -1);
System.out.println(VCR);
}
}
)))))) This is my Asset File ))))))
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
*/
package assignment7;
import java.util.*;
public class Asset {
private String type;
private int id;
private String name;
private String serial;
private int pid;
public Asset(String type, int id, String name, String serial, int pid)
{
this.type = type;
this.id = id;
this. name = name;
this. serial = serial;
this. pid = pid;
}
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;
}
public String toString()
{
return " Type: " + getType() + " ID: " + getId() + " Name: " + getName() + " Serial: " + getSerial() + " PID: " + getPid() + " ";
}
}
Explanation / Answer
class Asset {
private String type;
private int id;
private String name;
private String serial;
private int pid;
public Asset(String type, int id, String name, String serial, int pid)
{
this.type = type;
this.id = id;
this. name = name;
this. serial = serial;
this. pid = pid;
}
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;
}
public String toString()
{
return " Type: " + getType() + " ID: " + getId() + " Name: " + getName() + " Serial: " + getSerial() + " PID: " + getPid() + " ";
}
}
class Router extends Asset
{
private String application; // one from the following list "Home", "Core", "Infrastructure", etc
private int numOfNICs; // number of network interfaces
private String OS; // operating system. including vendor, version, and other details
private boolean hasConsole; // flag that indicates presence of management console
public Router(String type, int id, String name, String serial, int pid,String application,int numOfNICs,String OS,boolean hasConsole)
{
super(type,id,name,serial,pid);
this.application = application;
this.numOfNICs = numOfNICs;
this.OS = OS;
this.hasConsole = hasConsole;
}
public String toString()
{
return super.toString()+" Application : "+application+" number of network interfaces : "+numOfNICs+" operating system"+OS + " presence of management console"+hasConsole;
}
}
class Switch extends Asset
{
int numOf_100M; // number of 100Mb ethernet interfaces
int numOf_1G; // number of 1Gb ethernet interfaces
int numOf_10G; // number of 10Gb ethernet interfaces
int numOf_SFP; // number of SFP modules
String OS; // operating system. including vendor, version, and other details
String level; //one from the following list "L2", "L3", "L4"
public Switch(String type, int id, String name, String serial, int pid,int numOf_100M, int numOf_1G,int numOf_10G,int numOf_SFP,String OS,String level )
{
super(type,id,name,serial,pid);
this.numOf_100M = numOf_100M;
this.numOf_1G = numOf_1G;
this.numOf_10G = numOf_10G;
this.numOf_SFP = numOf_SFP;
this.OS = OS;
this.level = level;
}
public String toString()
{
return super.toString()+" number of 100Mb ethernet interfaces :"+numOf_100M+
" number of 1Gb ethernet interfaces :"+numOf_1G+
" number of 10Gb ethernet interfaces :"+numOf_10G+
" number of SFP modules : "+numOf_SFP+
" operating system. including vendor, version, and other details: "+OS+
" level: "+level;
}
}
class Server extends Asset
{
String OS; // same as with the Router
int NumOfNICs; // same as with the Router
boolean isVirtualized; // flag that shows whether or not this server is a Virtual Machine running on some virtualization platform
public Server(String type, int id, String name, String serial, int pid,String OS,int numOfNICs,boolean isVirtualized)
{
super(type,id,name,serial,pid);
this.OS = OS;
this.NumOfNICs = NumOfNICs;
this.isVirtualized = isVirtualized;
}
public String toString()
{
return super.toString()+ " operating system : "+OS + " Number of NIC : "+NumOfNICs+" Virtual Machine Running : "+ isVirtualized;
}
}
class Assignment7_main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ArrayList<Asset> assets = new ArrayList<Asset>();
Asset A1 = new Server("server",10565, "HP Proliant ML350 G6", "876245", 1223,"Windows 12",7,true);
Asset A2 = new Switch("switch", 76868,"Netgear GS108T", "782364",2,4,1,2,1,"windows","l2");
assets.add(A1);
assets.add(A2);
for(Asset a : assets)
System.out.println(a);
}
}
Output:
Type: server
ID: 10565
Name: HP Proliant ML350 G6
Serial: 876245
PID: 1223
operating system : Windows 12
Number of NIC : 0
Virtual Machine Running : true
Type: switch
ID: 76868
Name: Netgear GS108T
Serial: 782364
PID: 2
number of 100Mb ethernet interfaces :4
number of 1Gb ethernet interfaces :1
number of 10Gb ethernet interfaces :2
number of SFP modules : 1
operating system. including vendor, version, and other details: windows
level: l2
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.