Consider two sets of integers, X = [x1, x2, . . . , xn] and Y =
[y1, y2, . . . , yn]. Write two versions of a FindUncommon(X, Y )
algorithm to find the uncommon elements in both sets.
Each of your algorithms should return an array with the uncommon
elements, or an empty array if there are no uncommon
elements.
You do not have to write the ‘standard’ algorithms – just use them.
Therefore, you should be able to write each algorithm in about 10
lines of code. You must include appropriate
comments in your pseudocode.
(a) Write a pre-sorting based algorithm of FindUncommon(X, Y ). Your algorithm should strictly run in O(n log n).
(b) Write a Hashing based algorithm of FindUncommon(X, Y ). Your algorithm should run in O(n).
In: Computer Science
Topic 2 TRUE OR FALSE Q’s
31. A natural number is the number 0 or any number obtained by adding 1 to a natural number.
32. The category of numbers called integers includes negative numbers.
33. A rational number is any number that can be expressed without a fractional part.
34. The base of a number system determines the number of digits used in the system.
35. The digits used in any base are 1 through the base number.
36. The base of the hexadecimal number system is 15.
37. A number in any base can be expressed using a positional notation.
38. The letter C is used to represent the number 11 in hexadecimal.
39. The number 10 represents the base value in every number system.
40. Representing a number in base 5 sometimes requires more digits than representing that same number in base 10.
41. The value of each position in a number system is determined by subtracting the base from the position number.
42. A byte is made up of eight binary digits.
43. Two hexadecimal digits can be stored in one byte.
44. Starting from the right, every group of four binary digits can be read as one hexadecimal digit.
45. To find the decimal equivalent in a new base you just divide the decimal value by the new base.
In: Computer Science
OOPDA in java project. in eclipse
Instructions:
Create a class called
Person
with the properties listed:
int id, String firstName, String middleName, String lastName,
String email, String ssn, int age.
The
Person class should have getters
and
setters for all properties
other
than
id. (You may use Eclipse to help you auto-generate
these.)
Person class should also have a getter for id
Create a no-arg constructor for Person
In addition to these getters and setters, Person should have
the
following
instance methods:
String toString() – returns full name, like "Edgar Allen Poe"
String
getEmailDomain()
– returns the domain portion of an email (after
the
@), as in "gmail.com"
String getLast4SSN()
– returns the last 4 digits of the Social
Security
Number
Add validation checking methods
static boolean validAge(String testAge)
You will have to convert the testAge String to an int to store it after validation
static boolean validEmail(String testEmail)
static boolean validSSN(String testSSN)
for the age, email and ssn.You may have done this via the setters in the past. However, this time, let's make them class-level (static) methods to validate these fields as best you can.
Give some thought to what advantages this approach would have.
Notes on validation.
Here is a list of validation checks you should perform. Some are easier to implement than others, and there are many ways to correctly validate these aspects of the fields. Implement as many of these checks as you can.
You may accept any value for the names
Extra Credit: Is there a good way to validate a name? Do a little research on topic and include your answer. If there is, include your algorithm.
Age entered by user
The String entered must be an integer greater than 16
If the String is greater than 100 you should log an info message
Email address string entered by user
String must contain a '@' and at least one '.’
A '.' must follow the '@’
String must only contain one '@'
The domain name (the part after ‘@’ but before the first ‘.’ )must be at least one character in length
Clearly there are far more restrictions on email addresses than those listed above. See if you can think of any others that might be applicable. I will give out extra credit for especially clever email validation tests. Make sure to document and comment your ideas.
Social Security Number string entered by user
String must contain two '-' characters in the correct position
The length of the SSN must be 11 total characters
String must contain only digits or numbers
If you encounter invalid data for any of these fields, log it using the logging API of Java. (Do not use System.out.println(); )
Static variables: Keep track of the highest age entered for a Person in a static variable.
Create a driver program PersonApp to test the class
Prompt user for all Person properties except id. You can hardcode any id you like, but use the id as the HashMap key
Accept any value for the name field
Only accept valid values for age, email and ssn
Create a Person with the valid input
Create subclasses for Instructor and Student
Instructors should have a Department
Students should have a Major
Generate getters and setters
Add the Person, the Student and the Instructor to a HashMap.
In the Driver, create a Student & an Instructor (Hardcoded, do not prompt for Input)
Add each of these three instances (the hardcoded Student & Instructor, and previously created Person ) to a HashMap using the id as the key
Perform the following after creating each person in the Driver:
Loop through the HashMap and display
The person's full name and what kind of Person are they
The person's email domain
The last 4 digits of the person's Social Security Number
Whether the person is the oldest in the collection
The major for the Student, the department for the Instructor
Here is some sample output, to help you understand the end goal of the exercise (your prompts may look different than mine, don’t worry about that as long as they are clear)
Enter person's first name
Julie
Enter
person's middle name
Theresa
Enter
person's last name
Collins
Enter
person's email address
[email protected]
Enter
person's SSN in ###-##-#### format
123-45-6789
Enter
person's age
47
Julie
Theresa Collins (Person)
acme.com
6789
Oldest
Jane Marie Doe (Student)
students.rowan.edu
4444
not
oldest
Computer Science
Stephen
J. Hartley (Instructor)
rowan.edu
5555
not
oldest
Math/Science
In: Computer Science
Java
Define a class called BlogEntry that could be used to store an entry for a Web log.
The class should have instance variables to store :
- the poster’s username,
- text of the entry,
- and the date of the entry using the Date class
Date class is:
class Date
{
private int day, year;
private String mon;
public Date()
{
mon=" ";
day=0;
year=0;
}
public String toString()
{
return (mon+"/"+day+"/"+year);
}
public set_date(String m, int d, int y)
{
mon=m;
day=d;
year=y;
}
}
Methods:
-Add a constructor that allows the user of the class to set all instance variables.
-Also add a method, DisplayEntry()/toString(), that outputs all of the instance variables,
- method called getSummary that returns the first 10 characters from the text (or the entire text if it is less than 10 characters).
.
.
.
.
.
.
my code so far:
import java.util.Scanner;
public class BlogEntry
{
private String name;
private String entry;
public BlogEntry(String n, String e, String m, int d,
int y)
{
System.out.println("Poster's name:
"+n+"\nEntry Text: "+e);
System.out.println("Date: "+m+"
"+d+", "+y);
}
public String getName()
{
return name;
}
public void setName(String n)
{
this.name=n;
}
public String getEntry()
{
return entry;
}
public void setEntry(String e)
{
this.entry=e;
}
class date
{
private int d, y;
private String m;
public date(String m,int d, int y)
{
m= " ";
d=0;
y=0;
}
public void setdate(String m, int d, int y)
{
m=m;
d=d;
y=y;
}
}
private void String setSummary()
{
String summary=" ";
int space=0;
int script=0;
while(space<=9 &&
script<entry.length())
{
String
next=entry.substring(script,script+1);
if(next.equals(" "))
{
if(space<=9)
space++;
else
break;
}
summary+=next;
script++;
}
return summary;
}
public getSummary()
{
return summary;
}
public static void main(String [] args)
{
String name;
String entry;
String month;
int day;
int year;
Scanner input=new Scanner(System.in);
System.out.println("Please enter the Poster's name: ");
name=input.nextLine();
System.out.println("What is the text for the blog entry:
");
entry=input.nextLine();
System.out.println("What is the date of the entry?");
System.out.println("Please enter the month: ");
month=input.nextLine();
System.out.println("Please enter the day: ");
day=input.nextInt();
System.out.println("Please enter the year: ");
year=input.nextInt();
System.out.println("\nBlog Entry:");
BlogEntry entry1= new BlogEntry(name,entry,month,day,year);
BlogEntry entry2= new BlogEntry(name,entry,month,day,year);
entry2.setSummary(entry);
System.out.println("\nThe summary of this entry is
"+entry2.getSummary);
}
}
.
.
.
.
the error is occuring for my getSummary and setSummary
BlogEntry.java:47: error: '(' expected private void String setSummary() ^
BlogEntry.java:67: error: invalid method declaration; return type required public getSummary() ^
2 errors
In: Computer Science
Please construct a code following the instructions below
Part 3 – infixEvaluator method
You are required to implement the following method:
public static double infixEvaluator(String line)
This function first needs to tokenize the input expression (in the form of a String and stored in input variable “line”). You can tokenize the input expression by creating an object of StringSplitter and passing it the String as follows. StringSplitter uses a queue to accomplish the tokenization (see the class for details).
StringSplitter data = new StringSplitter(line);
Next, create your two stacks. Remember one will contain the operators and the other one will include the operands. Define them as follows:
Stack<String> operators = new Stack<String>();
Stack<Double> operands = new Stack<Double>();
Before we continue further in this method, it will be helpful to consider helper methods we might need (which will make our job easier :-).
Skeleton of the code below:
/**
* give a description of the purpose of this method
* @param line fill in
* @return fill in
*/
public static double infixEvaluator(String line){
return 0.0; // placeholder
}
In: Computer Science
Problem: Write a program that takes your weight in pounds as input and then prints how much you will weigh on Moon and Mars. The formula to convert weight on the Earth to weight on Moon and Mars are given below:
You should name the program as weight_watcher.py. The output should look like as shown below:
In: Computer Science
Lab # 4 Multidimensional Arrays
Please write in JAVA.
Programming Exercise 8.5 (Algebra: add two matrices)
Write a method to add two matrices. The header of the method is as follows:
public static double[][] addMatrix(double[][] a, double[][] b
In order to be added, the two matrices must have the same dimensions and the same or compatible types of elements. Let c be the resulting matrix. Each element cij is aij + bij. For example, for two 3 * 3 matrices a and b, c is
Write a test program that prompts the user to enter two 3 * 3 matrices and displays their sum. Here is a sample run
Example run:
Enter matrix1: 1 2 3 4 5 6 7 8 9 (enter)
Enter martix2: 0 2 4 1 4.5 2.2 1.1 4.3 5.2 (enter)
The matrices are added as follows:
1.0 2.0 3.0 0.0 2.0 4.0 1.0 4.0 7.0
4.0 5.0 6.0 + 1.0 4.5 2.2 = 5.0 9.5 8.2
7.0 8.0 9.0 1.1 4.3 5.2 8.1 12.3 14.2
Programming Exercise 8.6 (Algebra: multiply two matrices)
Write a method to multiply two matrices. The header of the method is:
public static double[][] multiplyMatrix(double[][] a, double[][] b)
To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have elements of the same or compatible types. Let c be the result of the multiplication. Assume the column size of matrix a is n. Each element cij is ai1 * b1j + ai2 * b2j + c + ain * bnj. For example, for two 3 * 3 matrices a and b, c is
where cij = ai1 * b1j + ai2 * b2j + ai3 * b3j. Write a test program that prompts the user to enter two 3 * 3 matrices and displays their product. Here is a sample run:
Example run:
Enter matrix1: 1 2 3 4 5 6 7 8 9 (enter)
Enter matrix2: 0 2 4 1 4.5 2.2 1.1 4.3 5.2 (enter)
The multiplication of the matrices is
1 2 3 0 2.0 4.0 5.3 23.9 24
4 5 6 * 1 4.5 2.2 = 11.6 56.3 58.2
7 8 9 1.1 4.3 5.2 17.9 88.7 92.4
In: Computer Science
discuss the local and global impact of computing on individuals, organizations, and society
In: Computer Science
Answer the following questions about Starvation.
In: Computer Science
public class GroceryShopping
{
//declared variable
private String vegetableName;
private String fruitName;
private double vegetablePrice;
private double fruitPrice;
private double vegetableOrdered;
private double fruitOrdered;
//declared constants
public static final double SERVICE_RATE =0.035;
public static final double DELIVERY_FEE=5;
public GroceryShopping( String vegetableName, String
fruitName, double vegetablePrice, double fruitPrice)
{
this.vegetableName =
vegetableName;
this.fruitName = fruitName;
this.vegetablePrice =
vegetablePrice;
this.fruitPrice = fruitPrice;
this.vegetableOrdered =
vegetableOrdered;
this.fruitOrdered=fruitOrdered;
}
public String getVegetableName()
{
return vegetableName;
}
public void setVegetableName(String
vegetableName)
{
this.vegetableName =
vegetableName;
}
public String getFruitName()
{
return fruitName;
}
public void setFruitName(String fruitName)
{
this.fruitName = fruitName;
}
public double getVegetablePrice()
{
return vegetablePrice;
}
public void setVegetablePrice(double
vegetablePrice)
{
this.vegetablePrice =
vegetablePrice;
}
public double getFruitPrice()
{
return fruitPrice;
}
public void setFruitPrice(double fruitPrice)
{
this.fruitPrice = fruitPrice;
}
public double getVegetableOrdered()
{
return vegetableOrdered;
}
public void setVegetableOrdered(double
vegetableOrdered)
{
this.vegetableOrdered =
vegetableOrdered;
}
public double getFruitOrdered()
{
return fruitOrdered;
}
public void setFruitOrdered(double fruitOrdered)
{
this.fruitOrdered =
fruitOrdered;
}
public double calculateSubtotal()
{
double
calculateSubtotal=(vegetablePrice*vegetableOrdered)+(fruitPrice*fruitOrdered);
return calculateSubtotal;
}
public double calculateAdditionalFee()
{
double
calculateAdditionalFee=calculateSubtotal()* SERVICE_RATE +
DELIVERY_FEE;
return
calculateAdditionalFee;
}
public void displayOrderSummary()
{
double
totalBill=calculateSubtotal()+calculateAdditionalFee();
System.out.println("--------------------------------------");
System.out.println("Grocery
Shopping Order Summary");
System.out.println("\nName"+"\t\t\tPrice Per Pound");
System.out.println("Sub-total:"+"\t\t$"+calculateSubtotal());
System.out.println("Additional
Fee:"+"\t\t$"+calculateAdditionalFee());
System.out.println("Total
Bill:"+"\t\t$"+totalBill);
System.out.println("--------------------------------------");
}
}
public class GroceryShoppingApp
{
/**
* @param args
*/
public static void main(String[] args)
{
Scanner input=new
Scanner(System.in);
displayTable1();
System.out.println("\nPlease select
the vegetable from Table 1: ");
String
vegetableName=input.next();
System.out.println("please enter
the price of the selected vegetable: ");
double
vegetablePrice=input.nextDouble();
displayTable2();
System.out.println("\nPlease select
the fruit from Table 2");
String fruitName
=input.next();
System.out.println("Please enter
the price of the selected fruit:");
double fruitPrice
=input.nextDouble();
GroceryShopping gs =new
GroceryShopping(vegetableName, fruitName, vegetablePrice,
fruitPrice);
System.out.println("\n--------------------------------------");
System.out.println("Grocery
Shopping Menu");
System.out.println("\nName"+"\t\tPrice Per Pound");
System.out.println(gs.getVegetableName()+"\t"+gs.getVegetablePrice());
System.out.println(gs.getFruitName()+"\t\t"+gs.getFruitPrice());
System.out.println("--------------------------------------\n");
System.out.println("\nEnter the
pounds of "+ gs.getVegetableName()+" ordered: ");
double
vegetableOrdered=input.nextDouble();
System.out.println("Enter the
pounds of "+ gs.getFruitName()+" ordered: ");
double
fruitOrdered=input.nextDouble();
System.out.println("\n\n\n--------------------------------------");
System.out.println("Grocery
Shopping Order Summary");
System.out.println("\nName"+"\t\tPrice Per Pound");
System.out.println(vegetableName+"\t"+vegetablePrice);
System.out.println(fruitName+"\t\t"+fruitPrice);
gs.displayOrderSummary();
input.close();
}
private static void displayTable1()
{
System.out.println("Vegetable Name\t\t"+"Price Per
Pound");
System.out.println("Broccoli\t\t"+"$3.12");
System.out.println("Yellow Onion\t\t"+"$1.15");
System.out.println("Chill Pepper\t\t"+"$4.58");
System.out.println("Greens Bundle\t\t"+"$2.82");
System.out.println("--------------------------------------");
System.out.println("Table 1: Vegetable names with
corresponding price per pound");
}
private static void displayTable2()
{
System.out.println("\n--------------------------------------");
System.out.println("Fruit Name\t\t"+"Price Per
Pound");
System.out.println("Apple\t\t\t"+"$1.73");
System.out.println("Grape\t\t\t"+"$2.15");
System.out.println("Key Lime\t\t"+"$2.58");
System.out.println("Navel Orange\t\t"+"$1.86");
System.out.println("--------------------------------------");
System.out.println("Table 2: Fruit names with
corresponding price per pound ");
}
}
I have two question
1) My Sub-Total fee is always is zero, no matter what i input.
2)When i input the vegetable and fruit name, only the apple , Grape and Broccoli are working. The others always shows error, when i try to input them.
In: Computer Science
I want to create an Android mobile application, an application that provides courses for students ... I want advice for safety and security, what are its requirements ... and what are the yooze case for this application and the Functional requirements of your opinion
In: Computer Science
MATLAB language;
...
Boyle's law of gases says that:
P1V1 = P2V2
Make a program (script) that calculates any of the 4 parameters, based on the elements that the user decides, that is:
P1 = P2V2 / V1 - ask for the data that is needed. P2, V2, V1
V1 = P2V2 / P1 - ask for the data that is needed. P2, V2, P1
P2 = P1V1 / V2 - ask for the data that is needed. P1, V2, V1
V2 = P1V1 / P2 - ask for the data that is needed. P1, P2, V1
REMEMBER THAT FROM THAT ELECTION, THE REQUIRED VALUES ARE ASKED
In: Computer Science
int main() {
int val = 15;
int pid;
if (pid = fork()){
wait(pid);
printf(“This is parent process and val = “);
}
else{
printf(“This is child process and val = “);
val++;
}
printf("%d\n", val);
return val;
}
In: Computer Science
//2.--------------------------------------------------------------
Given an array of size N, what is the complexity?
int m = A[0];
for (int i=1; i<N; i++)
{ if (A[i] > m) m = A[i]; }
int k = 0;
for (int i=0; i<N; i++)
{ if (A[i] == m) k++; }
What is a (name one) most frequent operation performed?______________________
Expression showing the number of times it is performed ___________
Time Complexity in Big-O Notation O( )
_____________________________________________________
//3.--------------------------------------------------------------
int mult(int N, int M)
{
int s = 0;
while (N > 0)
{
s = s + M;
N = N-1;
}
return s;
}
What is a (name one) most frequent operation performed?______________________
Expression showing the number of times it is performed___________
Time Complexity in Big-O Notation O( )
In: Computer Science
Managing Linux Servers (Apache, Samba, DNS,
1. What is the Apache directive that specifies the base directory for configuration and log files?
2. Once you’ve modified httpd.conf, what command would make Apache reread this file, without kicking off currently connected users?
3. What directive specifies the TCP/IP port associated with Apache?
4. What ports must be open for a Samba server to work with remote systems?
6. What samba configuration steps are required for mapping a Windows user to a Linux user?
7. From a nfs server, how would you allow readonly access to /opt for any system in example.com?
8. How would you instruct a DNS server to respond only to queries from the 137.44.* IP range?
9. What is pNFS ?
10. What do you understand by "nfsstat --nfs --server -3" command?
11. How to retrieve a list of clients connected to the NFS server ?
14. What is a difference between Apache and Nginx web server?
15. Explain Bind chroot environment ?
20. Can Samba be a member of more than one workgroup at the same time?
In: Computer Science