In the second task, you will write a Java program that validates an input to see whether it matches a specified pattern. You will have to read a bit about regular expressions for this Lab.
1. Prompt the user to enter the email address.
2. Read the user input as a String.
3. A regular expression that specifies the pattern for an email address is given by “[a-zA-Z0- 9.]++@[a-zA-Z]++.(com|ca|biz)”. Use this as the input to the matches method in the String class and output the result returned by the method.
4. Prompt the user to enter the full name.
5. Full name should have First name, zero or Middle names and the Last name. For this purpose, we will assume a name (first, middle or last) is a set of characters without any spaces. Some examples are “John”, “McDonald”, “smiTh”. The names are separated by exactly one space. Write a regular expression to represent this pattern.
6. Use the matches method in the String class to validate the name entered by the user and output the result returned by the method.
A possible dialogue with the user might be;
Please enter the email address: [email protected]
true
Please enter the full name: Malaka Second Third Walpola
true
In: Computer Science
Question 1 (10)
Create a class Student with public member variables: Student name,
student number, contact number, ID number. The following
specifications are required:
Add init() method of the class that initializes string member
variables to empty strings and numeric values to 0. (2)
Add the method populate() to the class. The method is used to
assign values to the member variables of the class. (2)
Add the method display() to the class. The method is used to
display the member variables of the class. (2)
Create an instance StudentObj of the class Student in a main
program. (2)
The main program should prompt the user to enter values for five
students. The attributes should be assigned to the instance of
Student using its populate() method, and must be displayed using
the display() method of the instance of Student. (2)
Please make the answer simple and straightforward for a beginner intro to python . Thank you
In: Computer Science
JAVA PROGRAMMING
Part 1
Part 2
3. Create an integer attribute to student class, name it as studentScore. No getters and setters are needed for this attribute.
4. When you create the Student object using the constructor, assign a random number to score attribute – random number should be between, 50 and 100.
5. Create a new method in Student object, called getGrade(), that returns a String.
a. The output method should return the following
If the score is >91, the return should be A,
Likewise B for >81 , C > 71, D > 61, and F for all others.
6. Modify the StudentOperationsClient’s main program, to print the following.
First Name: XXXXXX , Last Name: XXXXXXXX Letter Grade: XX
Part 3
Use switch case control statements to return the following,
•&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ; and any other input as “INVALID”
First Name: XXXXXX , Last Name: XXXXXXXX Class Performance: <GradeDescription>
In: Computer Science
In the following code down below I am not getting my MatrixElementMult right. Could someone take a look at it and help fix it? Also, when I print out the matrices I don't want the decimals. I know it's a format thing but I'm new to C and not getting it. Thanks!
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define N 8
typedef struct _Matrix {
double element[N][N];
} Matrix;
void PrintMatrix(Matrix a){
int i,j;
for(i=0;i<N;i++){
for(j=0;j<N;j++){
printf(" %.1f ",a.element[i][j]);
}
printf("\n");
}
printf("\n\n");
}
float ComputeAverage(Matrix a){
int sum = 0, i,j , total = N*N;
for(i=0;i<N;i++){
for(j=0;j<N;j++){
sum += a.element[i][j];
}
}
return sum/total;
}
Matrix Add(Matrix a, int dc){
int i,j;
for(i=0;i<N;i++){
for(j=0;j<N;j++){
a.element[i][j] += dc;
}
}
return a ;
}
Matrix MatrixTranspose(Matrix a){
int i,j;
Matrix M = {{154, 123, 123, 123, 123, 123, 123, 136,
192, 180, 136, 154, 154, 154, 136, 110,
254, 198, 154, 154, 180, 154, 123, 123,
239, 180, 136, 180, 180, 166, 123, 123,
180, 154, 136, 167, 166, 149, 136, 136,
128, 136, 123, 136, 154, 180, 198, 154,
123, 105, 110, 149, 136, 136, 180, 166,
110, 136, 123, 123, 123, 136, 154, 136}};
for(i=0;i<N;i++){
for(j=0;j<N;j++){
M.element[i][j]=a.element[j][i];
}
}
return M;
}
Matrix MatrixElementDiv(Matrix a, Matrix b){
int i,j;
for(i=0;i<N;i++){
for(j=0;j<N;j++){
a.element[i][j] = a.element[i][j]/b.element[i][j];
}
}
return a;
}
Matrix MatrixElementMult(Matrix a, Matrix b){
int i,j;
for(i=0;i<N;i++){
for(j=0;j<N;j++){
a.element[i][j] = a.element[i][j]*b.element[i][j];
}
}
return b;
}
Matrix Q50 = {{16, 11, 10, 16, 24, 40, 51, 61,
12, 12, 14, 19, 26, 58, 60, 55,
14, 13, 16, 24, 40, 57, 69, 56,
14, 17, 22, 29, 51, 87, 80, 62,
18, 22, 37, 56, 68,109,103, 77,
24, 35, 55, 64, 81,104,113, 92,
49, 64, 78, 87,103,121,120,101,
72, 92, 95, 98,112,100,103, 99}
};
int main(int argc, const char * argv[])
{
Matrix M = {{154, 123, 123, 123, 123, 123, 123, 136,
192, 180, 136, 154, 154, 154, 136, 110,
254, 198, 154, 154, 180, 154, 123, 123,
239, 180, 136, 180, 180, 166, 123, 123,
180, 154, 136, 167, 166, 149, 136, 136,
128, 136, 123, 136, 154, 180, 198, 154,
123, 105, 110, 149, 136, 136, 180, 166,
110, 136, 123, 123, 123, 136, 154, 136}};
// need to implement PrintMatrix
PrintMatrix(M);
// need to implement ComputeAverage
float ave = ComputeAverage(M);
// need to implement round
int dc = round(ave);
printf("Ave = %d\n",dc);
// need to implement Add
Matrix M2 = Add(M, -dc);
// need to implement PrintMatrix
PrintMatrix(M2);
// need to implement MatrixTranspose
Matrix T2 = MatrixTranspose(M);
PrintMatrix(T2);
// need to implement MatrixElementMult
Matrix R = MatrixElementMult(Q50, M);
PrintMatrix(R);
// need to implement MatrixElementDiv
Matrix C = MatrixElementDiv(R, Q50);
PrintMatrix(C);
return EXIT_SUCCESS;
}
In: Computer Science
USING C#
Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below.
Sample run 2:
Enter number of quarters: 3
Enter number of dimes: 0
Enter number of nickels: 0
Enter number of pennies: 3
You entered 3 quarters
You entered 0 dimes
You entered 0 nickels
You entered 3 pennies
Your total is 0 Dollars and 78 Cents.
In: Computer Science
How do I create a backup and restore strategy for a web site and the database for the site?
In: Computer Science
Suppose you have algorithms with the five running times listed below.
(Assume these are the exact running times.)
How much slower (i.e., you need check the ratio) do each of
these algorithms get when
you (a) double the input size, (b) increase the input size by
one?
5nlog(n)
In: Computer Science
PLEASE ANSWER
USING C#
Is there a Prius version? Did you know that the average Boeing 747 airplane uses approximately 1 gallon of fuel per second? Given the speed of the airplane, that means it gets 5 gallons to the mile. No, not 5 miles to the gallon, 5 gallons to the mile. You may be questioning why such a horribly inefficient machine is allowed to exist, but you’ll be happy to find out that, because this airplane hold 568 people, it averages about 0.01 gallons per person – (100 miles per gallon per person). Your job is to design (pseudocode) and implement (source code) a program that asks the user for a distance the plane has to fly (i.e. the length of the trip) and also asks the cost of jet fuel (which is currently $1.80 per gallon). The program should then calculate the total fuel charges to make the trip. Next, ask the user how many people will fly, as well as the average cost of a ticket. Finally, print the total profit made (or lost) and the average gas mileage per person. Document your code and properly label the input prompts and the outputs as shown below.
Sample run 1:
Enter the flight distance: 1000
Enter the current cost of jet fuel: $2 The flight will cost $10000.0 in fuel.
Enter the number of passengers: 5
Enter the average cost of a ticket: 1000
You will make a profit of $-5000.0
You averaged 1.0 miles per person per gallon!
In: Computer Science
Write a program that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it tells the user how many divisors it has, (excluding 1 and the number itself). Each time the user makes a wrong guess, it displays "Wrong" and says if the guess was too low or too high, until the user gets it right, in which case it says "Right" and says how many trials it took to guess it. Then, the program asks the user if he or she wants to continue. If the answer is 'y' or 'Y', it generates another number between 1 and 50 and repeats the game. If not, it prints the average of all trials with one decimal place and ends.
Example:
I've picked a number between 1 and 50 that has 0 divisor(s).
Guess the number: 23
Too low!
Guess the number: 37
Too low!
Guess the number: 43
Too high!
Guess the number: 41
Right! It took you 4 trials.
Play again? [y/n]: y
I've picked a number between 1 and 50 that has 1 divisor(s).
Guess the number: 25
Too low!
Guess the number: 49
Right! It took you 2 trials.
Play again? [y/n]: y
I've picked a number between 1 and 50 that has 3 divisor(s).
Guess the number: 30
Too high!
Guess the number: 24
Right! It took you 2 trials.
Play again? [y/n]: n
You averaged 2.7 trials in 3 games.
Press any key to continue.
Im stuck with the loops and if you can explain the steps would be great. At the end I need to show the average in where the user guessed the correct number and how many games they played
In: Computer Science
The Instructor class consists of a firstname (String), lastname (String), office building (String) and room number (int). There is a no-arg constructor that initializes the properties to “Albert”, “Einstein”, “McNair”, 420. There is also a constructor with a parameter for each class property. Finally, there is a toString() method that returns each property separated by an asterisk * .
Problem 2 (5 points)
The Textbook class consists of a title (String), publisher (String) and edition (int). There is a no-arg constructor that initializes Strings to “” and numeric values to zero. A second constructor has formal parameters for each property. The class toString() method returns a String with each property separated by a System.lineSeparator() char.
Problem 3 (5 points)
The Course class consists of a name (String), semester (String), instructor (Instructor) and textbook (Textbook). As with the previous classes, there are two constructors: one no-arg constructor and one constructor with formal parameters for each property. The no-arg constructor initializes reference variables to null. The toString() method separates the name and semester by a comma (‘,’). There is a System.lineSeparator() char after the semester property and between the Instructor and Textbook properties. The Instructor and Textbook properties are formatted using the toString() method from their respective classes.
Problem 4 (5 points)
if you could show which part was based off of which problem, that would be helpful.
In: Computer Science
Create a Java class named ReadWriteCSV that reads the attached
cis425_io.txt file that you will save in your workspace as
src/cis425_io.txt and displays the following table:
--------------------------
| No | Month Name | Days |
--------------------------
| 1 | January | 31 |
| 2 | February | 28 |
| 3 | March | 31 |
| 4 | April | 30 |
| 5 | May | 31 |
| 6 | June | 30 |.
| 7 | July | 31 |
| 8 | August | 31 |
| 9 | September | 30 |
| 10 | October | 31 |
| 11 | November | 30 |
| 12 | December | 31 |
--------------------------
Write that file out in reverse order to a file named:
src/cis425_ior.txt
public class ReadWriteCSV {
// Put class properties here
// Add method, processInfile(), to open file and read here
void processInfile()
{
File filename = new File
("cis425_io.txt");
Scanner in = new
Scanner(System.in); // System.in is an InputStream
Scanner inFile = new
Scanner("cis425_io.txt");
}
// add method, displayTable(), here to display the table
void displayTable() {
}
// add method, writeOutfile(), here to open and write the data in
reverse order to the new file
void writeOutfile() {
}
// add main() method here
public static void main(String[] args) {
}
}
In: Computer Science
use C++
You will implement the following encryption and decryption functions/programs for the Caesar cipher. Provide the following inputs and outputs for each function/program:
EncryptCaesar
Two inputs:
A string of the plaintext to encrypt
A key (a number)
▪ For the Caesar cipher: This will indicate how many characters to shift (e.g. for a key=3, A=>D, B=>E, ..., X=>A, Y=>B, Z=>C). Note that the shift is circular.
One output:
◦ A string of the ciphertext or codeword
DecryptCaesar
Two inputs:
◦ A string of the ciphertext to decrypt ◦ The key (a number)
One output:
◦ A string of the plaintext
Obviously, for this assignment to be successful, the decryption function/program must decrypt the original message which was encrypted by the encryption function/program. Or, for a plaintext P and an encryption function E() and a decryption function D(), P = D( E(P, Key), Key)
In: Computer Science
Create the appropriate variables and algorithm to calculate the following. Choose your own values for the variables. Do not enter the code on this paper. Create a program that calculates and displays the calculation. Approximate pi (π) as 3.14159.
You do not need to create a new program for each question.
If certain math equations use the same variable name, then you only need to declare it once in your main function.
Separate each problem using comments, like seen in the example below.
Example 1: Area of a square/rectangle. Formula:
int main()
{
// Example 1
float area, length, width;
length = 20;
width = 5;
area = length * width;
cout << "The area of a square with length " << length << " and width "
<< width << " is " << area << " square units.";
// Problem 1
// Problem 2
return 0;
}
In: Computer Science
int a = 1;
int b = 2;
if (a<b)
a=a+1;
b = b + a;
printf("The value of b is: %d", b);
int a = 2;
int b = 2;
if (a<b)
a=a+1;
else
a=a-1;
b = b + a;
printf("The value of b is: %d", b);
In: Computer Science
Suggest ways how to increase the number of visits for a website?
In: Computer Science