
In Java. How would this class look?
Program: In this program, we create the class Trail, which has three variables - ID(String), type(String), rank(int). The constructor takes two string parameters - ID and type and initializes the class's ID and type. Based on the type value, we assign a value to the variable rank. The mutators and accessors (getters and setters), help in getting the data and setting the data. The toString() mathod returns rank of the class in string format.a
To test our Trail class we create another class TrailDriver which creates an object of class Trail and tests its methods inside its Main() method.
Below is the implementation:
Code:
public class Trail {
//Class attributes/variables
private String ID;
private String type;
private int rank;
//Constructor
public Trail(String ID,String type){
this.ID = ID;
this.type = type;
//Set rank based on type
if(type.equals("ice")){
this.rank = 4;
}
else if(type.equals("trees")){
this.rank = 3;
}
else if(type.equals("rocks")){
this.rank = 2;
}
else if(type.equals("slalom")){
this.rank = 1;
}
else{
this.rank = 0;
}
}
//Method to get rank
public int getRank() {
return rank;
}
//Method to set rank
public void setRank(int rank) {
this.rank = rank;
}
//Method to get type
public String getType() {
return type;
}
//Method to set type
public void setType(String type) {
this.type = type;
}
//Method to get ID
public String getID() {
return ID;
}
//Method to set ID
public void setID(String ID) {
this.ID = ID;
}
//toString() method to display rank
@Override
public String toString() {
return "Rank: " + String.valueOf(rank);
}
}


TrailDriver.java:
![public class TrailDriver { public static void main(String[] args) { //Create Trail class object and test methods Trail trail](http://img.homeworklib.com/questions/8b051640-014a-11eb-abee-7f982403dc2e.png?x-oss-process=image/resize,w_560)
Output:

In Java. How would this class look? Trail.java This class represents an individual leg of the...
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...
I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank; public Student() { this.name = this.major = this.status = ""; this.rank = 0; } public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; } public int...
Here is the code from the previous three steps:
#include <iostream>
using namespace std;
class Student
{
private:
//class variables
int ID;
string firstName,lastName;
public:
Student(int ID,string firstName,string lastName)
//constructor
{
this->ID=ID;
this->firstName=firstName;
this->lastName=lastName;
}
int getID() //getter method
{
return ID;
}
virtual string getType() = 0; //pure virtual function
virtual void printInfo() //virtual function to print basic details
of a student
{
cout << "Student type: " << getType() <<
endl;
cout << "Student ID: " << ID...
create a programn in C++ that creates a class that represents a manufactured part on a bill of material (BOM). with the following attributes: identifier (The parts identifier as an alpha numeric string), drawing (The AutoCAD drawing file that represents the part), quantity (The number of parts that are required). implement the functions for the Part class in the file Part.cpp. The file main.cpp will only be used for testing purposes, no code should be written in main.cpp. -part.cpp file:...
In Java. How would this method look?
LinkedBinaryTree.java
import java.util.Iterator;
public class LinkedBinaryTree implements BinaryTreeADT {
private BinaryTreeNode root;
/**
* Creates an empty binary tree.
*/
public LinkedBinaryTree() {
root = null;
}
/**
* Creates a binary tree from an existing root.
*/
public LinkedBinaryTree(BinaryTreeNode root) {
this.root = root;
}
/**
* Creates a binary tree with the specified element...
Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...
HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...
HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...
How would I test this code thoroughly in a main.cpp file. Locomotive is an abstract base class. steam and dieselElectric are the derived classes. #ifndef COMMODITY_H #define COMMODITY_H #include <iostream> #include <string> using namespace std; class commodity { private: string name; int quantity; public: commodity(commodity *c); commodity(string name,int quantity); ~commodity(); string getName() const; int getQuantity() const; }; #endif #include "commodity.h" commodity::commodity(commodity *c) { this->name=c->getName(); this->quantity=c->getQuantity(); } commodity::commodity(string name,int quantity) { this->name=name; ...
Hi, I am having trouble solving the constructor, it requires to ArrayList marks to be a deep copy of the instance variable. I have also provided the J-Unit test I have been provided. import java.util.*; public class GradebookEntry { private String name; private int id; private ArrayList<Double> marks; /** * DO NOT MODIFY */ public String toString() { String result = name+" (ID "+id+")\t"; for(int i=0; i < marks.size(); i++) { /** * display every mark rounded off to two...