Question

I need to do the following to the program below: Problem formulation Following previous assignment (development...

I need to do the following to the program below:

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.

public static void main(String[] args) {
// List of company assets
Asset assetList[]=new Asset[7];

//assetList0 Server
assetList[0]=new Asset();
assetList[0].setType("Server");
assetList[0].setId(0);
assetList[0].setName("IBM Blade Center Hs22");
assetList[0].setSerial("CNU37569");
assetList[0].setPid(-1);

//assetList1 Switch
assetList[1]=new Asset();
assetList[1].setType("Switch");
assetList[1].setId(1);
assetList[1].setName("Cisco Catalyst 2960G");
assetList[1].setSerial("WY752059");
assetList[1].setPid(0);

//assetList2 PSU1
assetList[2]=new Asset();
assetList[2].setType("PSU1");
assetList[2].setId(2);
assetList[2].setName("IBM 39Y7408 2900 Watt PSU");
assetList[2].setSerial("JWI69839");
assetList[2].setPid(0);

//assetList3 PSU2
assetList[3]=new Asset();
assetList[3].setType("PSU2");
assetList[3].setId(3);
assetList[3].setName("IBM 39Y7408 2900 Watt PSU");
assetList[3].setSerial("JWI29849");
assetList[3].setPid(0);

//assetList4 NIC1
assetList[4]=new Asset();
assetList[4].setType("NIC1");
assetList[4].setId(4);
assetList[4].setName("Cisco EHWIC-4ESG 4 Port NIC");
assetList[4].setSerial("LWK76246");
assetList[4].setPid(1);

//assetList5 Nic2
assetList[5]=new Asset();
assetList[5].setType("NIC2");
assetList[5].setId(5);
assetList[5].setName("Cisco EHWIC-4ESG 4 Port NIC");
assetList[5].setSerial("LWK98352");
assetList[5].setPid(1);

//assetList6 Nic3
assetList[6]=new Asset();
assetList[6].setType("NIC3");
assetList[6].setId(6);
assetList[6].setName("Cisco EHWIC-4ESG 4 Port NIC");
assetList[6].setSerial("LWK56209");
assetList[6].setPid(1);

for (Asset asset : assetList) {
System.out.println(asset);
}
}
}

class Asset
{
//instance variables of asset
String type;
int id;
String name;
String serial;
int pid;
  
//default constructor
Asset()
{
type="";
id=0;
name="";
serial="";
pid=0;
}

//getters & setters
public void setType(String a)
{
type=a;
}
public String getType()
{
return type;
}

  
  
public void setId(int id)
{
this.id=id;
}
public int getId()
{
return id;
}
  
  
  
public void setName(String n)
{
name=n;
}
public String getName()
{
return name;
}
  
  
  
public void setSerial(String s)
{
serial=s;
}
public String getSerial()
{
return serial;
}
  
  
  
public void setPid(int pid)
{
this.pid=pid;
}
public int getPid()
{
return pid;
}
  
  
//toString() of asset
@Override
public String toString()
{
return "\n\n Type: " + getType() + " \n ID: " + getId() + " \n Name: " + getName() + " \n Serial: " + getSerial() + " \n PID: " + getPid() + " \n";
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is your code. I believe its just to show the concept of Inheritence. So I have not implemented PSU class as atributes were not provided. So let me know if you have any issues.

Asset.java

class Asset {

// instance variables of asset

String type;

int id;

String name;

String serial;

int pid;

// default constructor

Asset() {

type = "";

id = 0;

name = "";

serial = "";

pid = 0;

}

// getters & setters

public void setType(String a) {

type = a;

}

public String getType() {

return type;

}

public void setId(int id) {

this.id = id;

}

public int getId() {

return id;

}

public void setName(String n) {

name = n;

}

public String getName() {

return name;

}

public void setSerial(String s) {

serial = s;

}

public String getSerial() {

return serial;

}

public void setPid(int pid) {

this.pid = pid;

}

public int getPid() {

return pid;

}

// toString() of asset

@Override

public String toString() {

return "\n\n Type: " + getType() + " \n ID: " + getId() + " \n Name: " + getName() + " \n Serial: "

+ getSerial() + " \n PID: " + getPid() + " \n";

}

}

Driver.java

public class Driver {

public static void main(String[] args) {

// List of company assets

Asset assetList[] = new Asset[7];

// assetList0 Server

assetList[0] = new Server();

assetList[0].setId(0);

assetList[0].setName("IBM Blade Center Hs22");

assetList[0].setSerial("CNU37569");

assetList[0].setPid(-1);

// assetList1 Switch

assetList[1] = new Switch();

assetList[1].setId(1);

assetList[1].setName("Cisco Catalyst 2960G");

assetList[1].setSerial("WY752059");

assetList[1].setPid(0);

// assetList2 PSU1

assetList[2] = new Asset();

assetList[2].setType("PSU1");

assetList[2].setId(2);

assetList[2].setName("IBM 39Y7408 2900 Watt PSU");

assetList[2].setSerial("JWI69839");

assetList[2].setPid(0);

// assetList3 PSU2

assetList[3] = new Asset();

assetList[3].setType("PSU2");

assetList[3].setId(3);

assetList[3].setName("IBM 39Y7408 2900 Watt PSU");

assetList[3].setSerial("JWI29849");

assetList[3].setPid(0);

// assetList4 NIC1

assetList[4] = new Asset();

assetList[4].setType("NIC1");

assetList[4].setId(4);

assetList[4].setName("Cisco EHWIC-4ESG 4 Port NIC");

assetList[4].setSerial("LWK76246");

assetList[4].setPid(1);

// assetList5 Nic2

assetList[5] = new Asset();

assetList[5].setType("NIC2");

assetList[5].setId(5);

assetList[5].setName("Cisco EHWIC-4ESG 4 Port NIC");

assetList[5].setSerial("LWK98352");

assetList[5].setPid(1);

// assetList6 Nic3

assetList[6] = new Asset();

assetList[6].setType("NIC3");

assetList[6].setId(6);

assetList[6].setName("Cisco EHWIC-4ESG 4 Port NIC");

assetList[6].setSerial("LWK56209");

assetList[6].setPid(1);

for (Asset asset : assetList) {

System.out.println(asset);

}

// Stores Server1 asset

Asset server1 = new Server();

server1.setType("Data Server");

server1.setId(1002);

server1.setName("SkyWalker Server");

server1.setSerial("WF25D785FC");

// Prints Server1 asset

System.out.println(server1.toString());

// Stores Server2 asset

Asset server2 = new Server();

server2.setType("Web Server");

server2.setId(1003);

server2.setName("Juniper Server");

server2.setSerial("WF85G359IC");

// Prints Server2 asset

System.out.println(server2.toString());

// Stores NIC1 asset

Asset NIC1 = new Switch(4, 5, 6, 7, "Windows", "Level 7");

NIC1.setType("Ethernet NIC");

NIC1.setId(2125);

NIC1.setName("Gigabit Network Interface Card");

NIC1.setSerial("N254FG12");

NIC1.setPid(356984);

// Prints NIC1 asset

System.out.println(NIC1.toString());

// Stores NIC2 asset

Asset NIC2 = new Switch(22, 23, 4, 6, "iOS", "V.9.9");

NIC2.setType("E1000 NIC");

NIC2.setId(3285);

NIC2.setName("Emulated Gigabit Ethernet NIC");

NIC2.setSerial("N487CD45");

NIC2.setPid(235984);

// Prints NIC2 asset

System.out.println(NIC2.toString());

// Stores Router1 asset

Asset router1 = new Router();

router1.setType("Tri-Band Gigabit WiFi Router");

router1.setId(9864);

router1.setName("NETGEAR Nighthawk X6 AC3200");

router1.setSerial("SNR51OP362LK");

// Prints Router1 asset

System.out.println(router1.toString());

// Stores Router2 asset

Asset router2 = new Router();

router2.setType("Smart WiFi Dual Band Gigabit Router");

router2.setId(9856);

router2.setName("NETGEAR Nighthawk X4S - AC2600");

router2.setSerial("SNR25OP984NJ");

// Prints Router2 asset

System.out.println(router2.toString());

// Stores Switch asset

Asset Switch = new Switch();

Switch.setType("Fast Ethernet Smart Managed Switch");

Switch.setId(4823);

Switch.setName("NETGEAR ProSAFE FS526T");

Switch.setSerial("SNR57OC458GL");

// Prints Switch asset

System.out.println(Switch.toString());

}

}

Switch.java

public 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() {

super();

}

public Switch(int numOf_100M, int numOf_1G, int numOf_10G, int numOf_SFP, String oS, String level) {

super();

this.numOf_100M = numOf_100M;

this.numOf_1G = numOf_1G;

this.numOf_10G = numOf_10G;

this.numOf_SFP = numOf_SFP;

OS = oS;

this.level = level;

}

public int getNumOf_100M() {

return numOf_100M;

}

public void setNumOf_100M(int numOf_100M) {

this.numOf_100M = numOf_100M;

}

public int getNumOf_1G() {

return numOf_1G;

}

public void setNumOf_1G(int numOf_1G) {

this.numOf_1G = numOf_1G;

}

public int getNumOf_10G() {

return numOf_10G;

}

public void setNumOf_10G(int numOf_10G) {

this.numOf_10G = numOf_10G;

}

public int getNumOf_SFP() {

return numOf_SFP;

}

public void setNumOf_SFP(int numOf_SFP) {

this.numOf_SFP = numOf_SFP;

}

public String getOS() {

return OS;

}

public void setOS(String oS) {

OS = oS;

}

public String getLevel() {

return level;

}

public void setLevel(String level) {

this.level = level;

}

@Override

public String toString() {

return "Switch:\nnumOf_100M:" + numOf_100M + "\nnumOf_1G:" + numOf_1G + "\nnumOf_10G:" + numOf_10G

+ "\nnumOf_SFP:" + numOf_SFP + "\nOS:" + OS + "\nlevel:" + level + "\n" + super.toString();

}

}

Router.java

public class Router extends Asset {

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

public Router() {

super();

}

public Router(String application, int numOfNICs, String oS, boolean hasConsole) {

super();

this.application = application;

this.numOfNICs = numOfNICs;

OS = oS;

this.hasConsole = hasConsole;

}

public String getApplication() {

return application;

}

public void setApplication(String application) {

this.application = application;

}

public int getNumOfNICs() {

return numOfNICs;

}

public void setNumOfNICs(int numOfNICs) {

this.numOfNICs = numOfNICs;

}

public String getOS() {

return OS;

}

public void setOS(String oS) {

OS = oS;

}

public boolean isHasConsole() {

return hasConsole;

}

public void setHasConsole(boolean hasConsole) {

this.hasConsole = hasConsole;

}

@Override

public String toString() {

return "Router:\nApplication:" + application + "\nnumOfNICs:" + numOfNICs + "\nOS:" + OS + "\nhasConsole:"

+ hasConsole + "\n" + super.toString();

}

}

Server.java

public 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() {

super();

}

public Server(String oS, int numOfNICs, boolean isVirtualized) {

super();

OS = oS;

NumOfNICs = numOfNICs;

this.isVirtualized = isVirtualized;

}

public String getOS() {

return OS;

}

public void setOS(String oS) {

OS = oS;

}

public int getNumOfNICs() {

return NumOfNICs;

}

public void setNumOfNICs(int numOfNICs) {

NumOfNICs = numOfNICs;

}

public boolean isVirtualized() {

return isVirtualized;

}

public void setVirtualized(boolean isVirtualized) {

this.isVirtualized = isVirtualized;

}

@Override

public String toString() {

return "Server:\nOS:" + OS + "\nNumOfNICs:" + NumOfNICs + "\nisVirtualized:" + isVirtualized + "\n"

+ super.toString();

}

}

Output

Server:
OS:null
NumOfNICs:0
isVirtualized:false


Type:  
ID: 0
Name: IBM Blade Center Hs22
Serial: CNU37569
PID: -1

Switch:
numOf_100M:0
numOf_1G:0
numOf_10G:0
numOf_SFP:0
OS:null
level:null


Type:  
ID: 1
Name: Cisco Catalyst 2960G
Serial: WY752059
PID: 0

Type: PSU1
ID: 2
Name: IBM 39Y7408 2900 Watt PSU
Serial: JWI69839
PID: 0

Type: PSU2
ID: 3
Name: IBM 39Y7408 2900 Watt PSU
Serial: JWI29849
PID: 0

Type: NIC1
ID: 4
Name: Cisco EHWIC-4ESG 4 Port NIC
Serial: LWK76246
PID: 1

Type: NIC2
ID: 5
Name: Cisco EHWIC-4ESG 4 Port NIC
Serial: LWK98352
PID: 1

Type: NIC3
ID: 6
Name: Cisco EHWIC-4ESG 4 Port NIC
Serial: LWK56209
PID: 1

Server:
OS:null
NumOfNICs:0
isVirtualized:false


Type: Data Server
ID: 1002
Name: SkyWalker Server
Serial: WF25D785FC
PID: 0

Server:
OS:null
NumOfNICs:0
isVirtualized:false


Type: Web Server
ID: 1003
Name: Juniper Server
Serial: WF85G359IC
PID: 0

Switch:
numOf_100M:4
numOf_1G:5
numOf_10G:6
numOf_SFP:7
OS:Windows
level:Level 7


Type: Ethernet NIC
ID: 2125
Name: Gigabit Network Interface Card
Serial: N254FG12
PID: 356984

Switch:
numOf_100M:22
numOf_1G:23
numOf_10G:4
numOf_SFP:6
OS:iOS
level:V.9.9


Type: E1000 NIC
ID: 3285
Name: Emulated Gigabit Ethernet NIC
Serial: N487CD45
PID: 235984

Router:
Application:null
numOfNICs:0
OS:null
hasConsole:false


Type: Tri-Band Gigabit WiFi Router
ID: 9864
Name: NETGEAR Nighthawk X6 AC3200
Serial: SNR51OP362LK
PID: 0

Router:
Application:null
numOfNICs:0
OS:null
hasConsole:false


Type: Smart WiFi Dual Band Gigabit Router
ID: 9856
Name: NETGEAR Nighthawk X4S - AC2600
Serial: SNR25OP984NJ
PID: 0

Switch:
numOf_100M:0
numOf_1G:0
numOf_10G:0
numOf_SFP:0
OS:null
level:null


Type: Fast Ethernet Smart Managed Switch
ID: 4823
Name: NETGEAR ProSAFE FS526T
Serial: SNR57OC458GL
PID: 0

Add a comment
Know the answer?
Add Answer to:
I need to do the following to the program below: Problem formulation Following previous assignment (development...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • I need help converting the following two classes into one sql table package Practice.model; impor...

    I need help converting the following two classes into one sql table package Practice.model; import java.util.ArrayList; import java.util.List; import Practice.model.Comment; public class Students {          private Integer id;    private String name;    private String specialties;    private String presentation;    List<Comment> comment;       public Students() {}       public Students(Integer id,String name, String specialties, String presentation)    {        this.id= id;        this.name = name;        this.specialties = specialties;        this.presentation = presentation;        this.comment = new ArrayList<Commment>();                  }       public Students(Integer id,String name, String specialties, String presentation, List<Comment> comment)    {        this.id= id;        this.name...

  • I need help displaying two zeroes in hours:minutes:seconds. In Java. I need some help for the...

    I need help displaying two zeroes in hours:minutes:seconds. In Java. I need some help for the time to display correctly. I want it to display double zeroes. 06:00:00 and 12:00:00. public class Clock { String name; static int uid=100; int id; int hr; int min; int sec; public Clock() {   this.name="Default";   this.id=uid;   this.hr=00; this.min=00; this.sec=00; uid++; } public Clock(String name, int hr, int min, int sec) { if (hr<=24 && min <=60 && sec <=60) {   this.hr = hr; this.min...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • Below are the Car class and Dealership class that I created In the previous lab import...

    Below are the Car class and Dealership class that I created In the previous lab import java.util.ArrayList; class Car { private String make; private String model; private int year; private double transmission; private int seats; private int maxSpeed; private int wheels; private String type; public Car() { } public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) { this.make = make; this.model = model; this.year = year; this.transmission = transmission; this.seats =...

  • Java Do 68a, 68b, 68c, 68d. Show code & output. public class Employee { private int...

    Java Do 68a, 68b, 68c, 68d. Show code & output. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...

  • I have done a decent amount of coding... but I need you to help me understand...

    I have done a decent amount of coding... but I need you to help me understand what I do not. Please, post comments so that I can learn from you. Here are the instructions for this portion of the project: Create the Monkey class, using the specification document as a guide. The Monkey class must do the following: Inherit from the RescueAnimal class Implement all attributes with appropriate data structures Include accessors and mutators for all implemented attributes Here is...

  • C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employee...

    C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...

  • How can I solved my Java Program for DelivC

    //Graph Class: import java.util.ArrayList; //Graph is a class whose objects represent graphs.  public class Graph {     ArrayList<Node> nodeList;     ArrayList<Edge> edgeList;         public Graph() {         nodeList = new ArrayList<Node>();         edgeList = new ArrayList<Edge>();         }         public ArrayList<Node> getNodeList() {         return nodeList;    }    public ArrayList<Edge> getEdgeList() {         return edgeList;    }    public void addNode(Node n) {         nodeList.add(n);    }    public void addEdge(Edge e) {         edgeList.add(e);    }    public String toString() {         String s = "Graph g.\n";         if (nodeList.size() > 0) {             for (Node n : nodeList) {         // Print node info         String t = "\nNode " + n.getName() + ", abbrev " + n.getAbbrev() + ", value " + n.getVal() + "\n";         s = s.concat(t);         }         s = s.concat("\n");             }         return s;     }  } // Node Class: import java.util.ArrayList;  // Node is a class whose objects represent nodes (a.k.a., vertices) in the graph.  public class Node {    String name;     String val; // The value of the Node     String abbrev; // The abbreviation for the Node     ArrayList<Edge> outgoingEdges;     ArrayList<Edge> incomingEdges;             String color; //Create the color of the TYPE Node List     int start; //Create the Starting Time     int end; //Create the Ending Time             public Node( String theAbbrev ) {         setAbbrev( theAbbrev );         val = null;         name = null;         outgoingEdges = new ArrayList<Edge>();         incomingEdges = new ArrayList<Edge>();     }         public String getAbbrev() {         return abbrev;     }         public String getName() {         return name;     }         public String getVal() {         return val;     }         public ArrayList<Edge> getOutgoingEdges() {         return outgoingEdges;     }         public ArrayList<Edge> getIncomingEdges() {         return incomingEdges;...

  • How to solve this problem? Consider the following class : public class Store Public final double...

    How to solve this problem? Consider the following class : public class Store Public final double SALES TAX_RATE = 0.063B private String name; public Store(String newName) setName ( newName); public String getName () { return name; public void setName (String newName) { name = newName; public String toString() return "name: “ + name; Write a class encapsulating a web store, which inherits from Store. A web store has the following additional attributes: an Internet Address and the programming language in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT