Playing with encryption:
Write a program that will read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the second digit with the fourth. Finally, print the original number and its encrypted one. Now reverse the process. Read an encrypted integer and decrypt it by reversing the algorithm to obtain the original number. Print out both the encrypted and decrypted integer.
In: Computer Science
please write the code in C format avoid using (<<count>>)
Assume that you work for a travel agency. Write a C program that
performs 7 different tasks described below
for this company. The flights have the following
daily departure and arrival times:
| hotel name | cost | ride cost | |
| Rose | 248$ | 0$ | |
| Poprock | 90$ | 25$ | |
| flower | 128$ | 20$ |
| departure time | arrival time | cost |
| 7:15 am | 8:25am | 231$ |
| 8:15 am | 9:25am | 226$ |
| 9:15am | 10:25am | 226$ |
| 10:15am | 11:25am | 283$ |
| 11:15am | 12:25pm | 283$ |
| 3:15pm | 4:25pm | 226$ |
| 4:15pm | 5:25pm | 226$ |
| 5:15pm | 6:25pm | 401$ |
a) Based on the time entered by the customer, the closest departure time is displayed using 12- hour format.
b)the customer is asked if they would like a hotel and for how many days. hotel cost is mentioned above. Calculate the total cost (before taxes) and display it (flight + hotel for n number of days +ride).
c) now there is 2 types of discount:
Discount1: If the total fee is a multiple of 11,
then the
customer gets a 6% discount.
Discount2: An additional discount of 7% is given
to those customers whose subtotal
after discount1 is a multiple of the sum of digits of the
customer’s day of birth.
Three examples are given below for your convenience. See Sample
Input / output
for more clarification.
• Ex1: If the day of birth entered is 3, the customer will get an
additional 7%
discount if the sub-total of their purchase after discount1 is a
multiple of 3.
• Ex 2: If the day of birth entered is 12, the customer will get an
additional 7%
discount if their purchase after discount1 is a multiple of 3
(since sum of digits of
day of birth (12) is 3).
c)13% tax is applied to the total cost and the final bill is?
In: Computer Science
I am having a hard time with these questions regarding JDBC and XML.
1)
Which type of driver provides JDBC access via one or more ODBC drivers?
Group of answer choices
a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver
2)
Which of the following provides the application-to-JDBC Manager connection.
a) JDBC Driver
b) JDBC API
c) JDBC Driver API
d) SQL Server
3)
With the code below, indicate JDBC coding best practices that have been violated (this code does compile and run!):
import java.sql.*;
public class StudentData{
public static void main(String[] args) {
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(args[2], args[0],
args[1]);
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM Student WHERE rollno='" +
args[3] + "'");
while (rs.next()) {
System.out.print(rs.getInt(1) + "\t");
System.out.print(rs.getString(2) + "\t ");
System.out.print(rs.getInt(3) + "\t ");
System.out.println(rs.getDate(4));
}
stmt.close();
stmt = null;
rs.close();
rs = null;
}
catch (Exception exc) {
exc.printStackTrace();
}
}
}
a) The program imports all of the java.sql packages
b) This program does not properly close database resources
c) The program should catch SQLException
d) The program should not string-concatenate a query, but rather use a PreparedStatement.
e) The program retrieves data from a ResultSet by column number instead of by name
f) The program hardcodes the name of the JDBC driver and the SQL query. These should be externalized from the compilable code.
g) Answer 1, 3 and 5 only
h) Answers 1-6 all apply
4)
In JDBC, it is a good practice to use standard SQL statement and avoid using db specific query until necessary.
a) True
b) False
In: Computer Science
Windows 10: Cortana and Windows Search
In: Computer Science
Trying to create a Class of Employees that holds every Employee created from a class called Employee in c++
In: Computer Science
C++ The minimum function.
(a) Write a function that takes two integers and returns the value of the smaller one. In the main() function provide 5 test cases to verify its correctness. (b) Write the function that takes two characters and return the smaller one in the lexicographical order. Write the main() function that tests that functions for 5 different pairs of character type variables. (c) Write a generic function that takes two numeric objects and returns the value of the smaller one according to the less-than operation. Test the function in main() using the integer and character types.
In: Computer Science
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