Questions
Room.java: public class Room { // fields private String roomNumber; private String buildingName; private int capacity;...

Room.java:

public class Room
{
// fields
private String roomNumber;
private String buildingName;
private int capacity;

public Room()
{
this.capacity = 0;
}
/**
* Constructor for objects of class Room
*
* @param rN the room number
* @param bN the building name
* @param c the room capacity
*/
public Room(String rN, String bN, int c)
{
setRoomNumber(rN);
setBuildingName(bN);
setCapacity(c);
}
  
/**
* Mutator method (setter) for room number.
*
* @param rN a new room number
*/
public void setRoomNumber(String rN)
{
this.roomNumber = rN;
}
  
/**
* Mutator method (setter) for building name.
*
* @param bN a new building name
*/
public void setBuildingName(String bN)
{
this.buildingName = bN;
}
  
/**
* Mutator method (setter) for capacity.
*
* @param c a new capacity
*/
public void setCapacity(int c)
{
this.capacity = c;
}
  
/**
* Accessor method (getter) for room number.
*
* @return the room number
*/
public String getRoomNumber()
{
return this.roomNumber;
}
  
/**
* Accessor method (getter) for building name.
*
* @return the building name
*/
public String getBuildingName()
{
return this.buildingName;
}
  
/**
* Accessor method (getter) for capacity.
*
* @return the capacity
*/
public int getCapacity()
{
return this.capacity;
}
}

Put the ideas into practice by extending the original Room class to create an AcademicRoom.java class.

  1. The AcademicRoom.java should store information about the building name, room number, capacity, academic department associated with the room (CPSC, MATH, BUAD, ...) and also whether or not the room contains a projector. Make sure to utilize inheritance (only add new fields to AcademicRoom).
  2. Include a constructor for the AcademicRoom class that takes advantage of the reserved word super. Also include appropriate getter/setter methods for the AcademicRoom.
  3. Add James Farmer B6 to your list as well as two or three other classrooms of your choosing.
  4. Implement a test program (TestAcademicRoom.java) with a main() that creates an ArrayList of AcademicRooms. After the list is created, allow the user to: (1) add another room to the list, and (2) search for rooms. The program should not add the room if it already exists in the list. The user should search by inputting a building name and optionally a room number. If a room number is not provided, the program should print all rooms in that building. If matches are found in the list, print all the data members associated with the AcademicRoom(s).

In: Computer Science

IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS...

IN jAVA Language PLEASE

Write a JAVA program that implements the following disk-scheduling algorithms:

a. FCFS

b. SSTF

c. SCAN

Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will generate a random series of 50 requests and service them according to each of the algorithms you chose.

The program will be passed the initial position of the disk head as a parameter on the command line and report the total amount of head movement required for each algorithm.

In: Computer Science

In Java: The n^th Harmonic number is the sum of the reciprocals of the first n...

In Java: The n^th Harmonic number is the sum of the reciprocals of the first n natural numbers:
H(n) = 1+ 1/2 + 1/3 +1/4 +... +1/n

Write a recursive method and an accompanying main method to compute the n^th Harmonic number.

I have tried but get a blank and would really apreciate a fully explained code.

In: Computer Science

use Python datetime module, strftime Write a program that processes the following textfile and prints the...

use Python datetime module, strftime

Write a program that processes the following textfile and prints the report shown below.

Textfile:

  • Ask the user for the filename and BE SURE TO CHECK THAT IT EXISTS.
  • The file will contain lines which each contain 2 strings (bookTitle and publicationDate) separated by a comma and a space. Note that the title of the book might contain spaces!
  • Example of the textfile:

Gone Girl, 5-24-2012
To Kill A Mockingbird, 7-11-1960
Harry Potter and the Sorcerer’s Stone, 6-26-1997

Output: print the title and the publication date formatted in two ways (using strftime)

Example output:

Title                                                     Publication Date           Alternate Date

Gone Girl                                             May 24, 2012                5/24/12
To Kill A Mockingbird                            July 11, 1960                 7/11/60
Harry Potter and the Sorcerer’s Stone    June 26, 1997               6/26/97

In: Computer Science

#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string...

#include <iostream>

#include <string>

#include <vector>

using namespace std;

class Song{

public:

Song(); //default constructor

Song(string t, string a, double d); //parametrized constructor

string getTitle()const; // return title

string getAuthor()const; // return author

double getDurationMin() const; // return duration in minutes

double getDurationSec() const; // return song's duration in seconds

void setTitle(string t); //set title to t

void setAuthor(string a); //set author to a

void setDurationMin(double d); //set durationMin to d

private:

string title; //title of the song

string author; //author of the song

double durationMin; //duration in minutes

};

Song::Song(){

title ="";

author = "";

durationMin = 0;

}

Song::Song(string t, string a, double d){

//complete your code here for Task2

//the parameter t is for title, a is for author and d is for durationMin

}

string Song::getTitle()const{

//complete your code here for Task3

}

string Song::getAuthor()const{

return author;

}

double Song::getDurationMin()const{

return durationMin;

}

double Song::getDurationSec()const{

//complete your code here for Task4

//return the duration of the song in seconds

}

//complete the code for three member functions for Task5

// void setTitle(string t); //set title to t

// void setAuthor(string a); //set author to a

// void setDurationMin(double d); //set durationMin to d


In: Computer Science

What are the permissions for your home directory set by your system administrator? What command did...

What are the permissions for your home directory set by your system administrator? What command did you use to answer the question? Show your session.

In: Computer Science

The first part of this lab is making your stack generic. Take the code from your...

The first part of this lab is making your stack generic. Take the code from your working StringStack class and paste it into the GenericStack class. Change the name of the constructors to match the new name of the class (this has been done to this point), then modify the whole class so it uses generics, and can store any type that a programmer asks for.

Until you successfully complete this, the main method will give you nasty compiler errors. Once they stop, you should be good to move on!

Numbers and Readers

To take advantage of polymorphism, Java has a lot of inheritance hierarchies built-in. You may not have known that simple numeric classes, like Integer and Float, are actually part of one! Java contains a generic number class creatively called Number, and pretty much any class in Java whose purpose is to store numbers inherits from this class. (Note that this does not include the primitive int, float, and so on, since there are not classes)

Deep within Java's I/O packages, there's another interesting hierarchy of classes; the Reader and its many children. There are many types of Readers that can extract characters from different things, such as Strings, Files, and arrays. A function that takes in a Reader as a parameter, for example,

Scrolls of Numbers

A few years back, I bought a box of random numbers from an intrepid salesman who insisted they were special. I'd like to find out if that's really the the case. Unfortunately, I've stored the numbers in a bunch of different places - some of them are in Strings, others are in files, it's a bit of a mess.

So I created a generic calculator that, using Readers, can read in a list of numbers from any source, put them into a stack, and then add them all up. Since I'm a good programmer, I put each of these steps in their own functions... but it looks like I accidentally erased some of them. Your next task in the lab is to repair my generic stack calculator by fixing the functions.

  1. makeStack is supposed to take in a Reader, of any kind, and return a stack of Numbers from the data in that Reader. Luckily, the only thing broken here is the function signature - fix it by specifying the appropriate return type, function name, and parameters, using generics if appropriate.
  2. evaluate is supposed to take a stack of Numbers and add all of the numbers together, returning the result as a double. At some point, it looks like I replaced this entire function with a single return 0.0. Whoops. You'll have to re-implement this function as well as re-write its signature, again using generics if appropriate.
    A tip for this function: the Number class can't be directly added to a primitive (like a double, int, etc.) However, a Number object can be converted into a primitive with the use of the doubleValue() function. You may need to use this!
  3. I use the parse function to help with makeStack, but I must have scuffed off the return type at some point. Find the right return type by looking at the function and how it is used in makeStack.

Wrapping up

You'll know when you've successfully completed this lab once you can compile and run the code without errors, and you get output that looks somewhat like this (exact numbers may vary due to floating point rounding):

76.4
76.39999961853027
4584425.0
15.324
-------------------------------------------

package src;

import java.util.*;

public class GenericStack<T> {

/* YOUR CODE HERE

   * Just like in the ArrayList lab, copy your StringStack code, excluding the

   * main method, here.

   * Then, modify it so it's generic!

   */

private String[] stack;

public int size;

public int top;

/* Puts the stack into a valid state, ready for us to call methods on.

* The size parameter tell the... well, size of the stack.

*/

public GenericStack(int size) {

this.top = -1;

this.size=size;

this.stack = new String[size];

}

/* If someone calls the constructor with no argument, they should get a

* stack with a default size of 10.

*/

public GenericStack() {

this.size=10;

this.stack = new String[this.size];

this.top = -1;

}

/* Return true if the stack has no elements, and false otherwise.

*/

public boolean empty() {

return this.top == -1;

}

/* Return the object at the top of the stack, WITHOUT removing it.

* If there are no elements to peek, throw a NoSuchElementException.

*/

public String peek() {

if(this.top == -1) {

throw new NoSuchElementException("Empty stack!");

}

return this.stack[this.top];

}

/* Return the object at the top of the stack, AND ALSO remove it.

* If there are no elements to pop, throw a NoSuchElementException.

*/

public String pop() {

if(this.top == -1) {

throw new NoSuchElementException("Empty stack!");

}

return this.stack[this.top--];

}

/* Add a new object to the top of the stack.

* If there is no room in the stack, throw a IllegalStateException.

*/

public void push(String s) {

if(this.top == this.size-1) {

throw new IllegalStateException("Stack is full!");

}

this.stack[++this.top] = s;

}

/* Return the position of an object on the stack. The position of an object

* is just its distance from the top of the stack. So, the topmost item is

* distance 0, the one below the topmost item is at distance 1, etc.

*/

public int search(String s) {

int distance = 0;

int top = this.top;

while (top >= 0) {

if(this.stack[top] == s) {

return distance;

}

distance++;

--top;

}

return -1;

}

public static void main(String[] args) {

// If any of these lines cause a compilation error, your stack hasn't

// been properly made generic.

GenericStack<Integer> intStack = new GenericStack<>();

GenericStack<String> stringStack = new GenericStack<>();

GenericStack<ArrayList<String>> listStack = new GenericStack<>();

}

}

---------------------------

package src;

import java.util.*;
import java.io.*;
import java.math.*;

public class Calculator {

public static void main(String[] args) throws FileNotFoundException, IOException {

String numbers = "56 3 7 2.0 8.4";
char[] moreNumbers = "1.0 2 3 4 5 0.324".toCharArray();

GenericStack<Number> stack1 = makeStack(new StringReader(numbers));
System.out.println(evaluate(stack1));

GenericStack<Float> stack2 = new GenericStack<>();
for (String token : numbers.split(" ")) {
stack2.push(Float.parseFloat(token));
}
System.out.println(evaluate(stack2));

GenericStack<Number> stack3 = makeStack(new FileReader("numbers.txt"));
System.out.println(evaluate(stack3));

GenericStack<Number> stack4 = makeStack(new CharArrayReader(moreNumbers));
System.out.println(evaluate(stack4));
}
  
/* This function is meant to take in a Reader called "reader" and return a
* stack of Numbers.
*
* Remember: don't change anything that's already there. Just add your new
* code where the comment is to fix the function's signature.
*/
public static /* ??? */ throws IOException {
GenericStack<Number> stack = new GenericStack<>(64);
char[] data = new char[64];
reader.read(data);
String tokens = new String(data);
for (String token : tokens.split(" ")) {
stack.push(parse(token));
}
return stack;
}

/* This function is meant to take in a stack of ANY KIND of Number
* called "stack", and return the double you get if you add all of the
* numbers together.
* The function must be able to accept a stack of ANY KIND of Number!
*
* Hint: use wildcard generics!
*/
public static /* ??? */ {
/* implement me! */
return 0.0;
}

/* This function is missing a return type.
* Examine it, and see if you can tell what type it should return.
* (Spoiler: it's probably what you think it is.)
*/
public static /* ??? */ parse(String s) {
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) { }

try {
return Double.parseDouble(s);
} catch (NumberFormatException e) { }

return new BigDecimal(s);
}

}

In: Computer Science

Compare Hyper-V to virtualization offerings from Amazon, VMware, and Citrix, and others What are some of...

Compare Hyper-V to virtualization offerings from Amazon, VMware, and Citrix, and others What are some of the differences?

Which solution would you recommend to a manager?

In: Computer Science

List three different digital artifacts contained within a Windows operating system and how they can be...

List three different digital artifacts contained within a Windows operating system and how they can be used by a forensics analyst during a digital forensics investigation.

In: Computer Science

Write a function in C# that takes an array of double as the parameter, and return...

Write a function in C# that takes an array of double as the parameter, and return the average

In: Computer Science

Write a C++ code to perform the following steps: 1. Ask the user to enter two...

Write a C++ code to perform the following steps:

1. Ask the user to enter two whole numbers number1 and number2 (Number1 should be less than number2)

2. Calculate and print the sum of all even numbers between Number1 and Number2

3. Find and print all even numbers between Number1 and Number2

4. Find and print all odd numbers between Number1 and Number2

5. Calculate and print the numbers and their squares between 1 and 20 (inclusive)

6. Calculate and print the sum of the square of the odd numbers between Number1 and Number2

*(USE WHILE; Do not use For)

In: Computer Science

Exploring Websites COLLAPSE Complete both Part A and Part B to complete this discussion post. Part...

Exploring Websites

COLLAPSE

Complete both Part A and Part B to complete this discussion post.

Part A:   Browse and find a website that you would like to use for this activity.  Pretend you are a customer that is considering buying the company's product or service. Browse the website and using the criteria and the information you learned in the lesson content, critique the website from a customer's perspective. When you are ready, click the "Reply" button (see below) and comment on the following information:

Is the site easy to navigate and find information about products/services you are interested in?

Indicate if there is a knowledge base and what type (ie. search box, live chat feature, FAQs, etc.).

A link to the website you chose.

Part B: After you have made your post from Part A, review some of the other student posts and the websites links they chose (if you are the first one to post in this thread, then check back later for other posts).

In: Computer Science

Show the first eight words of the AES key expansion for a 128-bit key of all...

Show the first eight words of the AES key expansion for a 128-bit key of all ONES

In: Computer Science

Hi there, please write code in Python 3 and show what input you used for the...

Hi there, please write code in Python 3 and show what input you used for the program. I've been stuck on this for hours!

(1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt)

Ex:

Enter a sample text:
we'll continue our quest in space.  there will be more shuttle flights and more shuttle crews and,  yes;  more volunteers, more civilians,  more teachers in space.  nothing ends here;  our hopes and our journeys continue!

You entered: we'll continue our quest in space.  there will be more shuttle flights and more shuttle crews and,  yes;  more volunteers, more civilians,  more teachers in space.  nothing ends here;  our hopes and our journeys continue!


(2) Implement a print_menu() function, which has a string as a parameter, outputs a menu of user options for analyzing/editing the string, and returns the user's entered menu option and the sample text string (which can be edited inside the print_menu() function). Each option is represented by a single character.

If an invalid character is entered, continue to prompt for a valid choice. Hint: Implement the Quit menu option before implementing other options. Call print_menu() in the main section of your code. Continue to call print_menu() until the user enters q to Quit. (3 pts)

Ex:

MENU
c - Number of non-whitespace characters
w - Number of words
f - Fix capitalization
r - Replace punctuation
s - Shorten spaces
q - Quit

Choose an option:


(3) Implement the get_num_of_non_WS_characters() function. get_num_of_non_WS_characters() has a string parameter and returns the number of characters in the string, excluding all whitespace. Call get_num_of_non_WS_characters() in the print_menu() function. (4 pts)

Ex:

Number of non-whitespace characters: 181


(4) Implement the get_num_of_words() function. get_num_of_words() has a string parameter and returns the number of words in the string. Hint: Words end when a space is reached except for the last word in a sentence. Call get_num_of_words() in the print_menu() function. (3 pts)

Ex:

Number of words: 35


(5) Implement the fix_capitalization() function. fix_capitalization() has a string parameter and returns an updated string, where lowercase letters at the beginning of sentences are replaced with uppercase letters. fix_capitalization() also returns the number of letters that have been capitalized. Call fix_capitalization() in the print_menu() function, and then output the the edited string followed by the number of letters capitalized. Hint 1: Look up and use Python functions .islower() and .upper() to complete this task. Hint 2: Create an empty string and use string concatenation to make edits to the string. (3 pts)

Ex:

Number of letters capitalized: 3
Edited text: We'll continue our quest in space.  There will be more shuttle flights and more shuttle crews and,  yes;  more volunteers, more civilians,  more teachers in space.  Nothing ends here;  our hopes and our journeys continue!


(6) Implement the replace_punctuation() function. replace_punctuation() has a string parameter and two keyword argument parameters exclamation_count and semicolon_count. replace_punctuation() updates the string by replacing each exclamation point (!) character with a period (.) and each semicolon (;) character with a comma (,). replace_punctuation() also counts the number of times each character is replaced and outputs those counts. Lastly, replace_punctuation() returns the updated string. Call replace_punctuation() in the print_menu() function, and then output the edited string. (3 pts)

Ex:

Punctuation replaced
exclamation_count: 1
semicolon_count: 2
Edited text: we'll continue our quest in space.  there will be more shuttle flights and more shuttle crews and,  yes,  more volunteers, more civilians,  more teachers in space.  nothing ends here,  our hopes and our journeys continue.


(7) Implement the shorten_space() function. shorten_space() has a string parameter and updates the string by replacing all sequences of 2 or more spaces with a single space. shorten_space() returns the string. Call shorten_space() in the print_menu() function, and then output the edited string. Hint: Look up and use Python function .isspace(). (3 pt)

Ex:

Edited text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue!

In: Computer Science

Write a program in Python where you can swap only two consecutive elements. You have to...

Write a program in Python where you can swap only two consecutive elements. You have to show all steps to convert a string into another string (both strings will be anagrams of each other). E.g. GUM to MUG GUM GMU MGU MUG

In: Computer Science