Question

In: Computer Science

1. A company that wants to send data over the Internet will use an encryption program...

1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the second digit with the fourth. Print the encrypted integer on the screen.  Write a separate application where an encrypted four-digit integer is entered and decrypted (reversing the encryption scheme) and finds the original number.

2. Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the new salary by giving each employee a 10% raise and display each employee's annual salary on the screen again.

Note: code should be written in Java language.

Solutions

Expert Solution

Ans: Please read comments in the programs to get a better understanding.

Ques 1:

import java.util.*;

// --------X Encrypt.java X---------
class Encrypt{
    // Returns encrypted value
    public static int encrypt(int val){
        int tempVal = val, idx = 0;
        int [] newNum = new int [4];
        
        // store each new value in an array of size 4
        while(idx<4 && tempVal > 0){
            newNum[idx++] = ((tempVal%10)+6)%10;
            tempVal = tempVal/10;
        }
        
        return ((1000*newNum[1])+(100*newNum[0])+(10*newNum[3])+newNum[2]);
    }
}

// --------X Decrypt.java X---------
class Decrypt{
    // Returns decrypted value
    public static int decrypt(int val){
        int tempVal = val, idx = 0;
        int [] newNum = new int [4];
        
        // store each new value in an array of size 4
        while(idx<4){
            newNum[idx++] = ((tempVal%10)+10) - 6;
            tempVal = tempVal/10;
        }
        
        return ((1000*newNum[1])+(100*newNum[0])+(10*newNum[3])+newNum[2]);
    }
}


// --------X Test.java X---------
class Test{
    // Driver Method
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in); 
        // Takes Input
        int val = sc.nextInt();
        
        // Encrypt and print value
        int encryptedVal = Encrypt.encrypt(val);
        System.out.println("Encrypted value: "+encryptedVal);
        
        // Decrypt the encrypted value and print
        int decryptedVal = Decrypt.decrypt(encryptedVal);
        System.out.println("Decrypted value: "+decryptedVal);
    }
}

Ques 2:

// --------X Employee.java X---------
class Employee{
    private String firstName;
    private String lastName;
    private double salary;
    
    // Constructor
    public Employee(){
        firstName = "";
        lastName = "";
        salary = 0;
    }
    
    // Parameterized constructor
    public Employee(String fname, String lname, double sal){
        firstName = fname;
        lastName = lname;
        if(sal >= 0)
            salary = sal;
        else
            salary = 0;
    }
    
    public void setFirstName(String fname){
        firstName = fname;
    }
    
    public void setLastName(String lname){
        lastName = lname;
    }
    
    public void setSalary(double salary){
        if(salary >=0)
            this.salary = salary;
    }
    
    public String getFirstName(){
        return firstName;
    }
    
    public String getLastName(){
        return lastName;
    }
    
    public double getSalary(){
        return salary;
    }
}

// --------X EmployeeTest.java X---------
class EmployeeTest{
    
    // Print salary
    public static void printDetails(Employee e){
        System.out.print("Annual salary of "+e.getFirstName()+" "+e.getLastName()+" is ");
        System.out.println((12*e.getSalary()));
    }
    
    // Driver Method
    public static void main(String args[]){
        Employee e1 = new Employee("John", "Cena", 52672.25);
        Employee e2 = new Employee("Steve", "Austin", 32456.75);
        
        // Salary of employee 1
        printDetails(e1);
        
        // Salary of employee 2
        printDetails(e2);
        
        // Give increment
        double salary;
        
        salary = e1.getSalary();
        e1.setSalary(salary+(0.1*salary));
        
        salary = e2.getSalary();
        e2.setSalary(salary+(0.1*salary));
        
        // Print updated values
        
        // Salary of employee 1
        printDetails(e1);
        
        // Salary of employee 2
        printDetails(e2);
    }
}

Related Solutions

1. A company that wants to send data over the Internet will use an encryption program...
1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
1) A company that wants to send data over the Internet will use an encryption program...
1) A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
1. A company that wants to send data over the Internet will use an encryption program...
1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
1. A company that wants to send data over the Internet will use an encryption program...
1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
A company that wants to send data over the Internet has asked you to write a...
A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should 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 first...
A company that wants to send data over the Internet has asked you to write a...
A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should 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 first...
For encryption, what does it mean for data to be in transition and in use? What...
For encryption, what does it mean for data to be in transition and in use? What are the major security concerns with data encryption?
If two applications use TCP to send data but only send 10 bytes per segment (e.g....
If two applications use TCP to send data but only send 10 bytes per segment (e.g. by using the push operation), what is the maximum percent of the network bandwidth they will have for their data?
At Transport layer of Networks, we use segments to send data across. 1. Argue for using...
At Transport layer of Networks, we use segments to send data across. 1. Argue for using larger segments by discussing briefly why larger segments could be beneficial. 2. Then also argue why using small segments may be beneficial.
Write a program using interrupts to get data serially and send it to P2 while at...
Write a program using interrupts to get data serially and send it to P2 while at the same time Timer 0 is generating a square wave of 5 kHz. We've been basing our code on the Intel 8051 microntroller and assembly language.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT