1. Engineering
  2. Computer Science
  3. create a class called rotateencryption that extends the encryption class...

Question: create a class called rotateencryption that extends the encryption class...

Question details

Create a class called RotateEncryption that extends the Encryption class. Override the getLine method. This method will accept a filename and a line number. Display the line of text that corresponds to the line number in the file.

EncryptionDemo1

import java.io.FileNotFoundException;
import java.util.Scanner;

public class EncryptDemo1 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter a filename");
        String name = keyboard.nextLine();
        System.out.println("Enter a line number");
        int which = keyboard.nextInt();

        Encryption test = new RotateEncryption(name);

        String result = test.getLine(which);
        System.out.println(result);
    }
}

Encryption

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Encryption
{
    protected String filename;
    protected int key;
    protected Scanner inputFile;

    public Encryption(String filename) throws FileNotFoundException {
        this.filename = filename;
        this.key = 0;
        this.inputFile = new Scanner(new File(this.filename));
    }

    public Encryption(String filename, int key) throws FileNotFoundException
    {
        this.filename = filename;
        this.key = key;
        this.inputFile = new Scanner(new File(this.filename));
    }

    public String getLine(int which) {
        return "getLine not properly implemented";
    }
    public String getEncryptedLine(int which) {
        return "getEncryptedLine not properly implemented";
    }
}
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution