In: Computer Science
Use Context-Free Pumping Lemma to prove that that following languages over the alphabet {'x', 'y', 'z'} are NOT context-free
(a) {xjy2jzj : j > 0}
(b) { xmynzk : m, n, k ≥ 0 and k = min(m,n) }
In: Computer Science
in this code I have used array two times .
I need a way to make the program functional using a string to store the results and print it again later .
this game should be array free.
import java.util.Scanner;
import java.util.Random;//starter code provided
public class inputLap
{
public static char roller;
public static String playerName;
public static int printed=0;
public static int rounds=8,lives=0,randy;
public static int tries[]=new int[4];//use arrays to store number
of tries in each life
public static int res[]=new int[4];
public static String getName(String aString){
Scanner sc= new Scanner(System.in);
System.out.println("enter player's Name:");aString=sc.next();
playerName=aString;
return playerName;
}
public static void menu()
{
Scanner sc= new Scanner(System.in);
if(lives<=4){
System.out.println("Do you want to continue?(y/Y):\n (x/X) to exit.
");roller=sc.next().charAt(0);
}
}
public static int getGame() {
Scanner sc = new Scanner(System.in);
System.out.println("make a guess from 1-20");
int Guessed = sc.nextInt();
return Guessed;
}
public static void main(String[] args) {
String name=getName(playerName);
Random r = new Random();
int answer=0;
int f=0;
while(true) {
randy=r.nextInt(20);
for (int i=0;i<=7;i++)
{
answer=getGame();
rounds--;
if(answer==randy)
{
lives++;
System.out.println("congratulation you are right");
tries[lives-1]=8-rounds;
res[lives-1]=1;
rounds=8;
break;
}
else
{
System.out.println("you have "+(rounds)+" remaining");
}
if(rounds==0){
if(lives!=4){
tries[lives]=8;
lives++;
System.out.println("hard luck\nyou have "+(4-lives)+" lives
left");
f=1;
}
}
if(f==1){
f=0;
break;
}
}
menu();
switch( roller)
{
case 'y':
case 'Y':rounds=8;break;
case'x':
case 'X':
lives=5;
System.out.println("Game No Game 1 Game 2 Game 3 Game 4");
System.out.print("Number of tries ");
printed=1;
for(int i=0;i<4;i++)
System.out.print(tries[i]+" ");
System.out.println();
System.out.print("Result \t");
for(int i=0;i<4;i++){
if(res[i]==1)
System.out.print("Success ");
else
System.out.print("Fail");
}
System.out.println("\nbye bye "+playerName+" !!");
break;
}
if(lives>4)
break;
}
if(printed!=1){
System.out.println("Game No Game 1 Game 2 Game 3 Game 4");
System.out.print("Number of tries ");
for(int i=0;i<4;i++)
System.out.print(tries[i]+" ");
System.out.println();
System.out.print("Result\t");
for(int i=0;i<4;i++){
if(res[i]==1)
System.out.print("Success ");
else
System.out.print("Fail");
}
System.out.println("\nbye bye "+playerName+" !!");
}
}
}
implementing it
In: Computer Science
import java.util.ArrayList;
/*
Lab-08: BinarySearchTree Implementation
Rules:
1. Allow Tester to iterate
through all nodes using the in-order traversal as the
default.
This
means, in Tester the following code should work for an instance of
this class
called bst
that is storing Student objects for the data:
BinarySearchTree_Lab08<String> bst = new
BinarySearchTree_Lab08<String>();
bst.add("Man");
bst.add("Soda"); bst.add("Flag");
bst.add("Home");
bst.add("Today"); bst.add("Jack");
for(String s : bst)
System.out.println(s);
2. You can not
use a size variable to keep track of the number of nodes
*/
/**
* Lab-08: BinarySearchTree Implementation
*
* @author
*
*/
public class BinarySearchTree_Lab08<T> {
//======================================================================================
Properties
private Node root;
//======================================================================================
Constructors
public BinarySearchTree_Lab08() {
}
// Constructor that takes an array of items and
populates the tree
public BinarySearchTree_Lab08(T[] items) {
}
//======================================================================================
Methods
public void add(T data) { // Implement
recursively and do NOT allow duplicates
}
// Returns the traversal of this tree as an
array
public ArrayList<T> preOrder_Traversal()
{
ArrayList<T> data = new
ArrayList<T>();
preOrder_Traversal(root,
data);
return data;
}
private void preOrder_Traversal(Node n,
ArrayList<T> data) {
}
public ArrayList<T> inOrder_Traversal()
{
ArrayList<T> data = new
ArrayList<T>();
inOrder_Traversal(root,
data);
return data;
}
private void inOrder_Traversal(Node n,
ArrayList<T> data) {
}
public ArrayList<T> postOrder_Traversal()
{
ArrayList<T> data = new
ArrayList<T>();
postOrder_Traversal(root,
data);
return data;
}
private void postOrder_Traversal(Node n,
ArrayList<T> data) {
}
public ArrayList<T> breadthFirst_Traversal()
{
return null;
}
// Since this is a binary SEARCH tree, you should
write
// an efficient solution to this that takes advantage
of the order
// of the nodes in a BST. Your algorithm should be, on
average,
// O(h) where h is the height of the BST.
public boolean contains(T data) {
return false;
}
// returns the smallest value in the tree
// or throws an IllegalStateException() if the
// tree is empty. Write the recursive version
public T min() { return min(root); }
// this method is done for you.
private T min(Node n) { // Write this
method.
return null;
}
// returns the largest value in the tree
// or throws an IllegalStateException() if the
// tree is empty. Write the recursive version
public T max() { return max(root); }
// this method is done for you.
private T max(Node n) { // Write this
method.
return null;
}
// Returns whether the tree is empty
public boolean isEmpty() {
return false;
}
// returns the height of this BST. If a BST is
empty, then
// consider its height to be -1.
public int getHeight() {
return -1;
}
// returns the largest value of all the leaves
// If the tree is empty, throw an
IllegalStateException()
// Note, this is different than max as this is the
max
// of all leaf nodes
public T maxLeaf() {
return null;
}
// counts the number of nodes in this BST
public int nodeCount() {
return -1;
}
// returns the "level" of the value in a
tree.
// the root is considered level 0
// the children of the root are level 1
// the children of the children of the root are level
2
// and so on. If a value does not appear in the tree,
return -1
// 15
// / \
// 10 28
// \ \
// 12 40
// /
// 30
// In the tree above:
// getLevel(15) would return 0
// getLevel(10) would return 1
// getLevel(30) would return 3
// getLevel(8) would return -1
public int getLevel(T n) {
return -1;
}
// A tree is height-balanced if at each node, the
heights
// of the node's two subtrees differs by no more than
1.
// Special note about null subtrees:
// 10
// \
// 20
// Notice in this example that 10's left subtree is
null,
// and its right subtree has height 0. We would
consider this
// to be a balanced tree. If the tree is empty, return
true;
public boolean isBalanced() {
return false;
}
//======================================================================================
Inner Node Class
private class Node {
private T data;
private Node left, right;
private Node(T data) {
this.data =
data;
left = right =
null;
}
}
}
In: Computer Science
List and explain in detail all the steps that will be performed to convert a logical address to physical address in the paging system?
In: Computer Science
(JAVA)
Create a program that creates a mini database of numbers that allows the user to: reset the database, print the database, add a number to the database, find the sum of the elements in the database, or quit.
In main, you will declare an array of 10 integers (this is a requirement). Then you will define the following methods: • printArray (int[ ] arr) – this takes in an array and prints it • initArray (int[ ] arr) – this initializes the array so that each cell is 0 • printSum (int[ ] arr) – this calculates the sum of the elements in the array and prints it • enterNum(int[ ] arr) – this asks the user for a slot number and value – putting the value into the array in the correct slot • printMenu (int[ ] arr) – prints the menu in the sample output (that’s it, nothing more)
In main, create an array of 10 integers and immediately call initArray( ). Then, continuously looping, print the menu and ask the user what they want to do – calling the appropriate methods based on the user’s choice. Note that every time you call a method, you must pass the array that was created in main. If it makes it easier, we used a do-while loop and a switch statement in main.
It should behave like the sample output below: (user input = bold)
Would you like to:
1) Enter a number
2) Print the array
3) Find the sum of the array
4) Reset the array
5) Quit
1
Enter the slot: 5
Enter the new value: 76
Would you like to:
1) Enter a number
2) Print the array
3) Find the sum of the array
4) Reset the array
5) Quit
1
Enter the slot: 2
Enter the new value: 33
Would you like to:
1) Enter a number
2) Print the array
3) Find the sum of the array
4) Reset the array
5) Quit
2
|0|0|33|0|0|76|0|0|0|0
Would you like to:
1) Enter a number
2) Print the array
3) Find the sum of the array
4) Reset the array
5) Quit
3
109
Would you like to:
1) Enter a number
2) Print the array
3) Find the sum of the array
4) Reset the array
5) Quit
4
Would you like to:
1) Enter a number
2) Print the array
3) Find the sum of the array
4) Reset the array
5) Quit
2
|0|0|0|0|0|0|0|0|0|0
Would you like to:
1) Enter a number
2) Print the array
3) Find the sum of the array
4) Reset the array
5) Quit
5
In: Computer Science
you are givena pair (a,b) .after eatch unit of time
pair(a,b)
getd changeed to (b-a,b+a).you are given the initial value of
pair and an integer n and you have to print the value of the pair
at the nth unit of time
In: Computer Science
Analyse the security of Lamport’s OLP algorithm with the properties of hash function.
In: Computer Science
By using javaFX, write and design the Towers of Hanoi game with Redo and Undo features with play and solve options.
In: Computer Science
In: Computer Science
Mr. Kent doesn't care about almost anything ... but himself and his money. So, when his power plant leaked radioactive goo that caused several species of wildlife to go extinct, he was only concerned with the public perception as it might affect his income and possible jail time.
Many rumors surfaced around the Springfield Nuclear Power Plant. One of them is high concern over the mutation rate of the rare Springfield molted platypus. With barely more than 500 left in the wild, the word "extinction" has been tossed around. So, to quell the media, Mr. Kent had 30 of them captured, dissected, and analyzed to check for signs of mutation. He found that the mutation rate is 2% each month, but when they do mutate, they become sterile and cannot reproduce. With this information, he wants to create one of those newfangled computer simulations that the press loves so much. That's where you come in!
Specifications:
In this assignment, you will create a class called Animal_Category.
Your Animal_Category class is to contain the following data members:
Your Animal_Category class is to contain the following member functions:
You will also create a class called Platypus. Below, we will describe what will define a platypus. You will also create a main function in which you will create objects of type platypus to test the functionality of your new user-defined type.
Your Platypus class is to contain the following data members:
Member functions:
Further, the platypus has a chance of becoming dead each time it ages. This chance is ten times the platypus' weight. A 5 pound platypus has a 50% chance of death. A 10 pound platypus (or heavier) has a 100% chance of death. Again here update the value of the corresponding data member when needed.
Think very carefully about writing the above functions and how they should be used. There are indeed circumstances when some functions should not execute. For example, a dead platypus shouldn't eat anything.
Your program should fully test your platypus class. It must call every member function in the platypus class. It must print to the screen what it is doing and show the changes that appear when the member functions are called. The fight function will require two platypuses: one to call the fight function and one to be a parameter in the fight function.
c++ language
In: Computer Science
What will the value of A represent at the end
of execution of the given procedure on the “Paragraph Words”
dataset?
Step 1. Arrange all cards in a single pile called Pile 1
Step 2. Maintain two variables A, B and initialize them
to 0
Step 3. If Pile 1 is empty then stop the iteration
Step 4. Read the top card in Pile 1
Step 5. Add Letter count to variable B
Step 6. If the word does not end with a full stop then execute step 9
Step 7. If the word ends with a full stop and B > A then store B in A
Step 8. Reset the variable B to 0
Step 9. Move the current card to another pile called Pile 2 and repeat from step 3
Select answer from the following options:
1. Length of the shortest sentence based on the number of words
2. Length of the longest sentence based on the number of words
3. Length of the longest sentence based on the number of characters
4. Length of the shortest sentence based on the number of characters
5. None of the above
In: Computer Science
Describe the ramifications of the virtualization of storage.
In: Computer Science
In: Computer Science
1- Paper evaluation scenario
a) Draw an ERD for the following relational schema:
STUDENT (STD_ID, STD_First_Name, STD_Last_Name,
STD_Admit_Semester,
STD_Admit_Year, STD_Enroll_Status)
PAPER (PP_ID, PP_Title, PP_Submit_Date, PP_Accepted, PP_Type)
The two entities are related with the following business
rule:
• Each student may write many papers
Explain your choice of minimum and maximum cardinalities.
b) Extend the existing ERD with an EVALUATOR entity. The job of
the evaluator is to
grade each paper. The following business rules apply:
• Each paper is evaluated by at least 3 evaluators
Add four attributes of your choice to the EVALUATOR entity and
extend the ERD. The
final solution must be an implementation ready ERD, which means you
may need to add
additional entities or attributes to your ERD. In case you add
additional entities, please
justify your choice of entities, primary keys, relationship types,
and cardinalities.
I need this answer in Visual Paradigm please and also a very good reasoning for the cardinalities and extra entities
In: Computer Science