subject

Your task for this assignment is to re-write any programing assignment from the semester (again, pick a simple one) using a class from the Java Collections Framework, such as Queue, Stack, or LinkedList. This means you will use a JCF class in place of the class you wrote for the data structure. You might still need the class for the data object itself. For example, imagine that you wrote software for a stack of Car objects. You would still need the Car class, but instead of your Stack class you would instantiate your stack of Cars in the project class's main method using the JCF Stack class. You would also have to make sure that the method calls in your main method use the correct method names from the JCF Stack class, For example the method in the JFC Stack class to pop an element is:
pop()
which will remove and return the instance of the object from the top of the stack , so it would be used something like this:
if ( myStack. size() > 0 )
nextCar = myStack. pop();
else
// print an empty stack message
When you look at the documentation for a JCF class, be aware of inherited methods and methods specified in the Collection Interface, as well, since all JCF classes implement the Collection Interface. For example, size() is a method for all of the JCF classes.
Here is my code of "STACKS"
import java. util.*;
//stack class to define string array based push and pop methods
class Stack
{
int size;
int top;
String[] cities;
//function to check if stack is empty
boolean isEmpty()
{
return (top < 0);
}
Stack(int n)
{
top = -1;
size = n;
cities = new String[size];
}
//function to push element in Stack
boolean push(String x)
{
if (top >= size)
{
System. out. println("Stack Overflow");
return false;
}
else
{
cities[++top] = x;
return true;
}
}
//function to pop element from stack
String pop()
{
if (top < 0)
{
System. out. println("Stack Underflow");
return "0";
}
else
{
String x = cities[top--];
return x;
}
}
}
import java. util. Arrays;
//Driver code
class Driver
{
//function to reverse the string array implementing the stack class
public static void reverse(String cities[])
{
// Create a stack of capacity
// equal to length of cities array
int n = cities. length;
Stack obj = new Stack(n);
// Push all Strings into stack
for (int i = 0; i < n; i++)
obj. push(cities[i]);
//Pop all cities and put them back to str
for (int i = 0; i < n; i++)
{
String city = obj. pop();
cities[i]= city;
}
}
//driver function
public static void main(String args[])
{
//create the string array cities
String cities[] = { "Philadelphia, PA", "Harrisburg, PA", "Pittsburg, PA", "Cleveland, OH", "Toledo, OH", "Gary, IN", "Chicago, IL" };
//Printing the stack before reversing
System. out. println("Path from Philepedia to Chicago");
for(int i=0;i System. out. println(cities[i]);
//call reverse method
reverse(cities);
System. out. println();
//Printing the stack after reversing
System. out. println("Path from Chigago to Philipedia");
for(int i=0;i System. out. println(cities[i]);
}
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 14:00
Select the correct answer. andre was recently hired by an organization to check for system vulnerabilities. he is supposed to exploit these vulnerabilities and create a report on the extent of damage to which the system was susceptible. what position does andre hold in this organization? a. information security analyst b. information assurance manager c. penetration tester d. network security engineer e. chief information security officer
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. what does it indicate when a website displays https instead of http? a. the website is secure. b. there is no secure sockets layer. c. the secure sockets layer is hidden. d. the website is not secure.
Answers: 1
question
Computers and Technology, 24.06.2019 21:00
How does a vaccine prevent sickness and individual?
Answers: 2
question
Computers and Technology, 25.06.2019 15:10
Write a program to compute the ideal weight for both males and females in java. according to one study, the ideal weight for a female is 100 pounds plus 5 pounds for each inch in height over 5 feet. for example, the ideal weight for a female who is 5'3" would be 100 + 3*5 = 115 pounds. for a male, the ideal weight is 106 pounds plus 6 pounds for each inch in height over 5 feet. for example, the ideal weight for a male who is 5'3" would be 106 + 3*6 = 124 pounds. your program should ask the user to enter his/her height in feet and inches (both as integers—so a person 5'3" would enter the 5 and the 3). it should then compute and print both the ideal weight for a female and the ideal weight for a male. the general outline of your main function would be as follows: (1) declare your variables (think about what variables you need—you need to input two pieces of information, then you need some variables for your calculations (see the following steps) (2) get the input (height in feet and inches) from the user (3) compute the total number of inches of height (convert feet and inches to total inches (note: 1 foot equal 12 inches and hence 5 feet equal 60 inches. (4) compute the ideal weight for a female and the ideal weight for a male (5) print the answers.
Answers: 2
You know the right answer?
Your task for this assignment is to re-write any programing assignment from the semester (again, pic...
Questions
question
Geography, 27.10.2020 14:00
question
Physics, 27.10.2020 14:00
question
Chemistry, 27.10.2020 14:00
question
Mathematics, 27.10.2020 14:00