Use VB.net to create a loop that posts the first 100 prime numbers. Then, write code to confirm the numbers are prime.
In: Computer Science
Pre-Assignment
hom
Before you start, create a new Eclipse project and create one package in that project. The package should be called “HW3”
Problem 1
Create a class called “Person”. This class should have, at minimum, the following members and methods. I advise you to add others as you see fit.
// Members
firstName (string)
lastName (string)
age (int)
pAddress (Address) // This is composition! I suggest using the Address class we defined earlier!
pDOB (Date) // This is composition! I suggest using the Date class we defined earlier!
// Constructors
Person() // Default with age = 0, names null, and DOB and Address default for those classes
Person(firstName, lastName, age) // Address and DOB will be default for those classes
Person( Person x) // Copy constructor that does a DEEP COPY of the person object.
// Setters
setFirstName(String firstName)
setLastName(String lastName)
SetName(String firstName, String lastName)
setAge(int newAge)
setAddress(String houseNum, String street, String city, String state, String zip)
setDOB (int day, int month, in year)
// Getters
toString() // Print out the name, age, dob, and address (use toString from DOB and Address)
getAge() // return the age
getFirstName() // return the first name
getLastName() // return the last name
getDOB() // Return a COPY OF the date object HINT: Use the date copy constructor!
getAddress() // Return a COPY OF the address object HINT: Use the Address copy constructor!
Problem 2
Test your Person class by creating a new class (in the same “HW3” package and then use the methods to make sure they work properly. I provide no guidance on this since all you need to do is test the methods to make sure they work. Call each and make sure they don’t report errors or fail to execute correctly. Fix any bugs you find. Ask for help if you need it!!!
Problem 3
Create a new class file and call it “Student”. This class will EXTEND on the Person class by adding new data members and methods. Note that students are, in fact, people. This extension makes sense!
// Data members
stuID (String)
major (string)
level (int) // 0 = first-year, 1 = sophomore, 2 = junior, 3 = senior, 4 = post-grad
// Constructors
Student(String id, String lastName, String firstName, String major, int level)
Student( Student x) // Copy constructor that makes a DEEP COPY of Student x object
// Setters
Provide one setter for major, one setter for stuID, and one setter for level. Note that the “level” method should check the input to make sure it makes sense. If something besides a 0, 1, 2, 3, or 4 is provided, the setter should write a warning to screen and refuse to make the change.
// Getters
Provide one getter for major, one getter for stuID, and one getter for level.
// Provide an overrided toString method and use super to also use the inherited toString
toString (String)
// This method should write to screen something like this:
// “Jones, Mary, 21, 544 S Winston St., Kemble, KY 00000, Computer Science, 3”
// Note that you want to use the inherited toString() method here by saying super.toString()
// somewhere in your returned expression.
Problem 4
Create a new class in “HW3” package and call it “testStudent”. Use this class to create multiple student objects and person objects. Test all the methods for accuracy. Make sure you have correct behavior for all of your methods/constructors. Watch out for the copy constructors!!!!
In: Computer Science
The MarsX Space Vehicles Company has been very successful. Due to an increase in demand for its STS’s, the company had to hire thousands of scientists, engineers and staff from all over the world. As we all know, not all countries use the same system of measurements. The U.S., Liberia and Burma use the English system; while the rest of the world uses the metric system. In addition scientists use specific scales for some of their applications. To avoid confusion among team members from different countries, the company has commissioned the development and deployment of conversion applications. Your job is to write a program that interchangeably converts between different temperature scales (Celsius, Fahrenheit and Kelvin).
Your job depends on the success of this application. Therefore, make sure you write clean code and test it thoroughly.
Your program must do the following:
Celsius |
Fahrenheit |
Kelvin |
-10.00 |
14.00 |
263.15 |
0.00 |
32.00 |
273.15 |
100.00 |
212.00 |
373.15 |
Fahrenheit |
Celsius |
Kelvin |
-10.00 |
-23.33 |
249.82 |
0.00 |
-17.78 |
255.37 |
100.00 |
37.78 |
310.93 |
Kelvin |
Fahrenheit |
Celsius |
0.00 |
-459.67 |
-273.15 |
100.00 |
-279.67 |
-173.15 |
1000.00 |
1340.33 |
726.85 |
Needed conversion formulas:
From |
To |
Formula |
Celsius |
Fahrenheit |
F = C * (9.0/5.0) + 32 |
Celsius |
Kelvin |
K = C + 273.15 |
Fahrenheit |
Celsius |
C = (F – 32) * (5.0/9.0) |
Fahrenheit |
Kelvin |
K = (F + 459.67) * (5.0 /9.0) |
Kelvin |
Fahrenheit |
F = K * (9.0/5.0) – 459.67 |
Kelvin |
Celsius |
C = K – 273.15 |
Your program must comply with the following constraints:
int getMenuSelection(); /*Displays menu and gets user selection*/
void convertFromCelsius(); /*From Celsius to the other scales*/
void convertFromFahrenheit(); /*From Fahrenheit to the other scales*/
void convertFromKelvin(); /*From Kelvin to the other scales*/
int main()
{
int menuSelection = 0;
do
{
system(“cls”);
menuSelection = getMenuSelection();
switch (menuSelection)
{
case 1: convertFromCelsius();
break;
case 2: convertFromFahrenheit();
break;
case 3: convertFromKelvin ();
break;
case 4: break; /*Do nothing. Exit Condition*/
default: printf(“Please enter a number between 1 and 4 \n”);
system(“pause”);
}
} while (menuSelection != 4);
system(“pause”);
return 0;
}
In: Computer Science
Scenario: Of The Month Club (OTMC)
Consider a System Request that has been received for the following proposed System:
• Of‐the‐Month Club (OTMC) is an innovative young firm that sells memberships to people who have an interest in certain products.
• People pay membership fees for 1 year and each month receive a product by mail. For example, OTMC has a coffee‐of‐the‐month club that sends members one pound of special coffee each month.
• OTMC currently has six memberships (coffee, wine, beer, cigars, flowers, and computer games), each of which costs a different amount.
• Customers usually belong to just one, but some belong to two or more. • When people join OTMC, the telephone operator records the name, mailing address, phone number, e‐mail address, credit card information, start date, and membership plan(s) (e.g., coffee). A new system would allow members to self-enroll via the web. • Some customers request a double or triple membership (e.g., 2 pounds of coffee, three cases of beer).
• The computer game membership operates a bit differently from the others. In this case, the member must also select the type of game (action, arcade, fantasy/science fiction, educational, etc.) and age level.
• OTMC is planning to greatly expand the number of memberships it offers (e.g., video games, movies, toys, cheese, fruit, vegetables), so the system needs to accommodate this future expansion.
• OTMC is also planning to offer 3‐month and 6‐month memberships.
Part 1:
Based on the scenario and the high-level requirements described above, create a set of use cases for an information system that would support OTMC operations as described above. Use the fully developed template available in Canvas
Recommendation: In building the major use cases, follow the four‐step process: identify the use cases, identify the steps within them, identify the elements within the steps, and confirm the use cases.
Part 2:
Draw a context diagram and a Level 0 DFD (Data Flow Diagram) for the use cases you developed in part 1.
In: Computer Science
Write a program called distance_square.c that reads an integer n from standard input, and prints an nxn pattern of integers. Each integer is the minimum number of steps required to reach the centre of the square. Steps can only be up, down, left or right (no diagonal movement). the question should be allowed to use only while loop
4 3 2 3 4 3 2 1 2 3 2 1 0 1 2 3 2 1 2 3 4 3 2 3 4
Observing the example above, each integer represents the minimum number of steps required to reach the centre of the square. For example, the top left corner contains the integer 4. The centre of the square can be reached in 4 steps (right, right, down, down).
You can assume n is odd and >= 3.
Make your program match the examples below exactly.
This exercise is designed to give you practice with while loops, if statements and some mathematical operators. Do not use arrays for this exercise!
Note: you are not permitted to use an array in this exercise. and you are suppose to use while loop only!!
./distance_square Enter square size: 3 2 1 2 1 0 1 2 1 2 ./distance_square Enter square size: 9 8 7 6 5 4 5 6 7 8 7 6 5 4 3 4 5 6 7 6 5 4 3 2 3 4 5 6 5 4 3 2 1 2 3 4 5 4 3 2 1 0 1 2 3 4 5 4 3 2 1 2 3 4 5 6 5 4 3 2 3 4 5 6 7 6 5 4 3 4 5 6 7 8 7 6 5 4 5 6 7 8 ./distance_square Enter square size: 15 14 13 12 11 10 9 8 7 8 9 10 11 12 13 14 13 12 11 10 9 8 7 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 7 8 9 10 11 12 13 14 13 12 11 10 9 8 7 8 9 10 11 12 13 14
In: Computer Science
Java Language:
Using program created in this lesson as a starting point, create a circular list with at least four nodes. A circular list is one where the last node is made to point to the first. Show that your list has a circular structure by printing its content using an iterative structure such as a while. This should cause your program to go into an infinite loop so you should include a conditional that limits the number of nodes to be printed to a specific value, for example 20.
Code:
class Node {
int value;
Node nextNode;
Node(int v, Node n)
{
value = v;
nextNode = n;
}
Node (int v)
{
this(v,null);
}
}
class Stack {
protected Node top;
Stack()
{
top = null;
}
boolean isEmpty()
{
return( top == null);
}
void push(int v)
{
Node tempPointer;
tempPointer = new Node(v);
tempPointer.nextNode = top;
top = tempPointer;
}
int pop()
{
int tempValue;
tempValue = top.value;
top = top.nextNode;
return tempValue;
}
void printStack()
{
Node aPointer = top;
String tempString = "";
while (aPointer != null)
{
tempString = tempString + aPointer.value + "\n";
aPointer = aPointer.nextNode;
System.out.println(tempString);
}
}
public class StackWithLinkedList{
public static void main(String[] args){
int popValue;
Stack myStack = new Stack();
myStack.push(5);
myStack.push(7);
myStack.push(9);
myStack.printStack();
popValue = myStack.pop();
popValue = myStack.pop();
myStack.printStack();
}
}
In: Computer Science
Describe the difference between making a class a
member of another class (object composition) and making a class a
friend of another class.
Explain why memberwise assignment can cause problems
with a class that contains a pointer member.
Explain why the parameter of a copy constructor must
be a reference.
In: Computer Science
Java- creat a method that takes two char parameters. Return a String containing all characters, in order, from the first char parameter (inclusive) to the last (inclusive). For instance, input('a', 'e'), and return "abcde".
In: Computer Science
In: Computer Science
Generate 5th order linear recursive sequence using shift registers using the primitive polynomial 1+X^2+x^5
In: Computer Science
In Java
An outlet store is having a sale in their Cabin brand sweaters.
There are two different pricing systems depending on if it is a
Cabin brand or not. Tax must be added on after the sweater charge
is computed.
You must have two classes using separate files.
Requirements for Sweater Class
Fields
1. sweater price (in dollars)
2. Boolean to indicate if it is a Cabin brand or not
3. number of sweaters purchased
Methods
1. One 3 parameter constructor- the constructor uses
three parameters representing the sweater price, whether it is a
Cabin Brand or not, and the number of sweaters purchased.
2. Getter and setter for each field
3. getTotalPurchase method
This method must call the appropriate getter member methods where
necessary. Do not access the fields directly.
This method calculates and returns the total amount of the
sweater.
If the sweater is Cabin brand, calculate the discount as
follows;
-If the customer purchases 1 sweater the discount is 20% of the
sweaters price.
-if the customer purchases 2 or more sweaters the discount is
30%
-the customer cannot purchase less than 1 sweater.
-compute the purchase subtotal by subtracting the appropriate
discount from the sweaters price.
Use a tax rate of 7% of the purchase subtotal to compute the sales
tax in dollars. Add the sales tax amount to the purchase subtotal
to determine the total purchase amount.
Return the total purchase amount to the calling code.
Requirements for the SweaterDriver Class
Main method
1. customer must be prompted appropriately
2. All values related to money may include values after
the decimal point. All values displayed to the screen must display
with 2 places after the decimal.
3. The customer must indicate whether the sweater is
Cabin brand or not by typing a single character (y for yes, n for
no) program must accept Upper and lower case, Y,y,N,n.
4. If the sweater is Cabin brand, prompt the customer
to enter the number of Cabin sweaters being purchased.
5. Instantiate a Sweater object using a three parameter
constructor.
Note that the parameter that indicates if the sweater is a Cabin
brand is a Boolean data type.
The customer must type a single character. You will have to use
selection to instantiate a Sweater object with the correct data
type foe this parameter.
6. Display the values in the output by calling the
appropriate method of the Sweater object. The output must line up
at the decimal point as in the sample runs.
Sample runs
1
Enter the price of the sweater: $50.00
Is the swear a Cabin(Y/N)? N
Price of sweater $50.00
Total purchase $53.50
Run 2
Enter the price of the sweater: $60.00
Is the sweater a Cabin(Y/N)? Y
Enter the number of sweaters being purchased: 2
Price of sweater $60.00
Total Purchase $89.88
Run 3
Enter price of sweater: $40.00
Is the sweater a Cabin(Y/N)? Y
Enter the number of sweaters being purchased: 1
Price of sweater $40.00
Total purchase $34.24
In: Computer Science
Task #1 The while Loop (8 pts) 1. Copy the file DiceSimulation.java as directed by your instructor. Correct syntax errors if any, and improve programming style when necessary (indents, newlines, etc.). DiceSimulation.java is incomplete. Since there is a large part of the program missing, the output will be incorrect if you run DiceSimulation.java. 2. We have declared all the variables. You need to add code to simulate rolling the dice and keeping track of the doubles. Convert the algorithm below into Java code and place it in the main method after the variable declarations, but before the output statements. You will be using several control structures: a while loop and an if-else-if statement nested inside another if statement. Use the indenting of the algorithm to help you decide what is included in the loop, what is included in the if statement, and what isincluded in the nested if-else-if statement. 3. To “roll” the dice, use the nextInt method of the random number generator to generate an integer from 1 to 6. Repeat while the number of dice rolls are less than the number of times the dice should be rolled. Get the value of the first die by “rolling” the first die Get the value of the second die by “rolling” the second die If the value of the first die is the same as the value of the second die If value of first die is 1 Increment the number of times snake eyes were rolled Else if value of the first die is 2 Increment the number of times twos were rolled Else if value of the first die is 3 Increment the number of times threes were rolled Else if value of the first die is 4 Increment the number of times fours were rolled Else if value of the first die is 5 Increment the number of times fives were rolled Else if value of the first die is 6 Increment the number of times sixes were rolled Page 3 of 3 Increment the number of times the dice were rolled 4. Compile and run. You should get numbers that are somewhat close to 278 for each of the different pairs of doubles. Run it several times. You should get different results than the first time, but again it should be somewhat close to 278. Task #2 Using Other Types of Loops: do-while (4 pts) 1. Change the while loop to a do-while loop. 2. Make other necessary changes to save your work as new file named DiceSimulation_Do.java. 3. Compile and run. You should get the same results as at Task #1. Task #3 Using Other Types of Loops: for (4 pts) 1. Change the do-while loop to a for loop. 2. Make other necessary changes to save your work as new file named DiceSimulation_For.java. 3. Compile and run. You should get the same results as at Task #1.
import java.util.Random; // Needed for the Random class /** This class simulates rolling a pair of dice 10,000 times and counts the number of times doubles of are rolled for each different pair of doubles. */ public class DiceSimulation { public static void main(String[] args) { final int NUMBER = 10000; // Number of dice rolls // A random number generator used in // simulating the rolling of dice Random generator = new Random(); int die1Value; // Value of the first die int die2Value; // Value of the second die int count = 0; // Total number of dice rolls int snakeEyes = 0; // Number of snake eyes rolls int twos = 0; // Number of double two rolls int threes = 0; // Number of double three rolls int fours = 0; // Number of double four rolls int fives = 0; // Number of double five rolls int sixes = 0; // Number of double six rolls // TASK #1 Enter your code for the algorithm here // Display the results System.out.println ("You rolled snake eyes " + snakeEyes + " out of " + count + " rolls."); System.out.println ("You rolled double twos " + twos + " out of " + count + " rolls."); System.out.println ("You rolled double threes " + threes + " out of " + count + " rolls."); System.out.println ("You rolled double fours " + fours + " out of " + count + " rolls."); System.out.println ("You rolled double fives " + fives + " out of " + count + " rolls."); System.out.println ("You rolled double sixes " + sixes + " out of " + count + " rolls."); } }
In: Computer Science
In: Computer Science
In 1-2 pages (a paragraph or so for each item), describe your top 3 security-related takeaways or security insights you noted while reading the book.(cuckoos egg.)
In: Computer Science
Can you assist me in understand and write the steps in this code?
Write a method named howMany that does not take in any arguments. Use the Scanner class to ask the user to enter a number between 1 and 5. Print One of the following based on their entry.
1 2 3 4 5 Anything Other Number
“Lonely Num” “Company” "Crowd" "Fun" "Party" "Only 1 to 5 Please"
In: Computer Science