Use Java for the following;
Part 1
n!= n * (n –1)* (n–2)* ...* 3 * 2 * 1
For example, 5! = 5 * 4 * 3 * 2 * 1 = 120
Write a function called factorial that takes as input an integer. Your function should verify that the input is positive (i.e. it is greater than 0). Then, it should compute the value of the factorial using a for loop and return the value. In main, display a table of the integers from 0 to 30 along with their factorials. At some point around 15, you will probably see that the answers are not correct anymore. Think about why this is happening.
In: Computer Science
Deck Class
public class Deck
{
private final String[] suits = {"Spades", "Hearts", "Clubs",
"Diamonds"};
private final String[] faces = {"Ace", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "Jack", "Queen", "King"};
private Card[] cards;
private int topCard;
/**
* Construct a deck of cards and initialize the topCard to -1.
*/
public Deck()
{
}
/**
* deal() returns the next card or null if the deck is empty.
* @return next Card in the deck.
*/
public Card deal()
{
topCard++;// set topCard to the next card
if(topCard < 52)
{
return cards[topCard];
}
else
{
return null;
}
}
/**
* shuffle() randomly generates a sequence of cards for the card
array
*/
public void shuffle()
{
topCard = -1;// reset the top card
int nextNumber;
boolean[] available = new boolean[52];// used to select random #'s
between 0 and 51 without replacement
for(int i = 0; i < 52; i++)
{
available[i] = true;//all #'s between 0 and 51 are available
}
for(int i = 0; i < 52; i++)
{
nextNumber = (int)(Math.random()*52);// select a # from 0 to
51
while(!available[nextNumber])//while nextNumber is not available
(i.e. this number has already been used)
{
nextNumber = (int)(Math.random()*52);//try a different number until
you find an unused one
}
available[nextNumber] = false;// this number is taken
cards[i] = new Card(suits[nextNumber/13],
faces[nextNumber%13]);
}
}
/**
* Print out the entire deck for testing purposes.
*/
public void testDeck()
{
}
/*
Write a method called "testDeck" that uses a loop (whichever
type of loop you think is appropriate) to print out all cards
in the deck (Card array) in four NEAT columns.
When "testDeck" is called on a brand new deck each COLUMN
should
contain one suit with that suit's cards in order. For
example: the first column should contain all of the
spades in order: Ace Spades, 2 Spades, 3 Spades, ..., King
Spades.
The second column should contain all of the clubs in
order:Ace Clubs, 2 Clubs, 3 Clubs, ... and so on.
When called on a shuffled deck cards will be random but still
in NEAT columns.
WHEN YOU ARE FINISHED WRITING THIS METHOD REMOVE THIS COMMENT
*/
/**
* Print out a subset of the deck to test the deal method.
*/
public void testDeal(int numberOfCards)
{
}
/*
Write a method called "testDeal" that takes a single integer
parameter called "numberOfCards". Create a local ArrayList of Cards
(i.e. ArrayList<Card>)
called "hand".
Use an index variable, a while loop, and the deal() method
to fill the "hand" with a number of cards equal to
numberOfCards.
Next use a loop (whichever type of loop you think is appropriate)
to go through the hand
and print out all of the cards in a single NEAT column.
(Note: this method uses an ArrayList of Cards, not an array. Pay
attention
to the difference.)
WHEN YOU ARE FINISHED WRITING THIS METHOD REMOVE THIS COMMENT
*/
Card Class
public class Card
{
private String suit;
private String face;
/**
* Constructor for objects of class Card.
*/
public Card(String suit, String face)
{
this.suit = suit;
this.face = face;
}
/**
* Returns the suit of the card
*/
public String getSuit()
{
return suit;
}
/**
* Returns the face of the card
*/
public String getFace()
{
return face;
}
/**
* Returns the suit and face of the card as a single String
*/
public String getCard()
{
return face + "\t" + suit;
}
}
In: Computer Science
Java Programming - please read the description I need this description.
Inside a do/ while loop (while choice !='x') , create a method call that calls a switch menu with 3 cases for variable choice and X for exit application.(this is a user input) Each case calls other methods.
One of those methods asks for user input float numbers to calculate addition. And the result return to another method that displays the result.
Thanks for your help!
Thanks for asking.
The other choices are:
One call for a method that changes the user input for other numbers using an array to store this information.
And the other method is similar to addiction(), however is a subtraction()
Thanks for your help!!
In: Computer Science
Assume you have two processes, P1 and P2. P1 has a high priority, P2 has a low priority. P1 and P2 have one shared semaphore (i.e., they both carry out waits and posts on the same semaphore). The processes can be interleaved in any arbitrary order (e.g. P2 could be started before P1).
i. Explain the problem with priority inversion
Briefly explain whether the processes could deadlock when:
ii. both processes run on a Linux system as time sharing tasks
iii. both processes run on a Windows 7 system as variable tasks
iv. both processes run on a Windows 7 system as real-time tasks.
In: Computer Science
what are the differences/similarity between the keyword "this" in java and the keyword "self" in python and why or when should we use these two keywords? if you could provide a code example side by side that would be great!
thank you!
In: Computer Science
Objectives
• To work with linked chains of nodes
• To create a component of score storage and update software used
in sporting software, or a computer game
Instructions
For this assignment, you will construct a list of scores
ScoreNode class
The ScoreNode class represents an individual score. This requires a
name of type String, and a score of type integer, and obviously a
reference to the next node in the chain.
ScoresList class
Method | Notes |
ScoresList | No-argument constructor. Sets the ScoreList's linked chain head node (front) to null |
ScoresList (ScoresList otherList) | A copy constructor. This constructor will perform a deep copy on the otherList, making an exact copy of it. |
add(String name, int score) | Add the name/score value to the linked chain in the correct order based on what is already in the chain (if anything). Remember, you must maintain the list in sorted order, descending. |
print() | The print method simply prints out the score list represented by the calling ScoreList object. Given a ScoreList object, mySL, the call to mySL will simply print out the scores by walking down the linked chain. Assume all printing is done to the console. |
File Input
The file scores.txt will contain, on each line, the name of the
player, followed by their high score, such as the following:
Bob 150
Dan 220
Samantha 70
Ksenia 175
Nathan 15
The files are, in general, not going to be in a sorted order. The ScoresList class should, as you add the names and corresponding scores from file, keep them in descending (largest to smallest) order in the linked chain of nodes.
Corresponding Console Output and User
Interaction
For the above file, the output will display the high scores in
sorted order from highest to lowest, and interaction with the user
might look like the following:
Dan 220
Ksenia 175
Bob 150
Samantha 70
Nathan 15
Would you like to add another (1) or quit the program (2)?
1
Write the name followed by score
Ali 190
The new scores are:
Dan 220
Ali 190
Ksenia 175
Bob 150
Samantha 70
Nathan 15
Would you like to add another (1) or quit the program (2)?
2
Thanks for using the program! Goodbye!
The output, including additions made by the user, do not affect the
original file. They only change the in-memory copy of the
ScoreList. You continue asking the user if they’d like to add
another or quit the program until they ask to quit the program.
The answer needs to be in Java.
In: Computer Science
WRITE CODE IN JAVA
it is now your turn to create a program of your choosing. If you are not sure where to begin, think of a task that you repeat often in your major that would benefit from a program. For example, chemistry unit conversions, finding the area for geometric shapes, etc. You can also create an interactive story that changes based on the user input/decisions. The possibilities are endless.
The program must include instructions for the user. Be in the mindset that the program you develop will be used by anyone. You will not receive any assistance from the instructor. It is up to you to figure out your program.
Your program must include (but not limited to) the following:
•Comments•Input(s) and output(s)
•Decision structures
•Loops
Create whatever program of your liking
In: Computer Science
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it.
The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels.
Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong.
Class vehicle should have constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which will reuse their parents constructor and provide additional code for initializing their specific data.
Class Vehicle should have toString method that returns string representation of all vehicle data. Classes Car, Bus, and Truck will override inherited toString method from class vehicle in order to provide apropriate string representation of all data for their classes which includes inherited data from Vehicle class and their own data.
Class Tester will instantiate 1-2 objects from those four classes (7 total) and it will display the information about those objects by invoking their toString methods.
In: Computer Science
javaScript
html receives an entry of a character string in a text box, when a button is clicked, the count of vowels in the string stored in the textbox is displayed. The html file contains one function: vowelcount().
vowelcount(): returns the number of uppercase and lowercase English language vowel letter that occurs in the string entry in the textbox.
//html:
<!--
YOUR ID
YOUR NAME
-->
<html>
<head>
<script>
function vowelcount()
{
/* YOUR CODE HERE */
}
</script>
</head>
<body>
<input type="text" name="numbers" id="numbers">
<input type="button" name="button" value="click"
onclick="vowelcount();">
<p id="result"> </p>
</body>
</html>
In: Computer Science
Match the concept with its definition and characteristics.
(not all options are used)
|
|
In: Computer Science
message = 'youcannotdecodemyciphertexttoday'
def transposition_cipher_encode(plain_text, key):
# the input, key should be a permutation of integers 0 to some
number
# your code here
return
need code in PYTHON
In: Computer Science
1. Implement the graph ADT using the adjacency list structure.
2. Implement the graph ADT using the adjacency matrix structure.
LANGUAGE IS IN JAVA
Comment for any questions
Data structures and algorithms
In: Computer Science
To do our analysis, let's look at one of the giants
Please read these online resources.
Walmart. Read and explore these online resources pertaining to Walmart's history and Information System usage.
write an informal paragraph or two on why you think Walmart has become so successful. Using chapter 7, "DOES IT MATTER," read, think about what technology gave Walmart a competitive advantage. Do you think they needed to manage any of Porter's Five Forces? Provide your own insight.
In: Computer Science
In: Computer Science
You will write Stack class in c++ that will be integrated into a larger software product provided by the instructor. This Stack class uses a dynamically allocated array to store data values (integers) that have been pushed onto the stack object. When the client code attempts to push another integer onto a full stack, your Push operation should invoke the Resize() function which attempts to double the capacity of the stack and then add the new data value to the resized stack array. In Resize() a new array (that holds twice as many integers) is dynamically allocated, data from the old stack array is copied into the new larger stack array, the old stack array is deallocated, and the new data value is pushed onto the new array.
In: Computer Science