`
guoyiqi
  • 浏览: 1018929 次
社区版块
存档分类
最新评论

java试题

 
阅读更多
You should be comfortable with the content in the modules up to and including the module "Methods" for this project.

A reporter needs a security application that will encrypt their phone numbers in their contact list to protect their sources. The client program will provide a three digit encoding number that will be used to encode the separate parts of a phone number: area code, exchange and subscriber number.  The first digit will be used to encode the 3 digit area code.  The second digit will be used to encode the 3 digit exchange.  The third digit will be used to encode the 4 digit subscriber number. 

Use a simple encryption algorithm to make this easier. The Caesar cipher can be represented as C = (P + key) mod 10, where C is the encrypted value and P is the value being encrypted. The key is the encoding key derived from the security code that is provided by the client.

The corresponding deciphering formula to return the encoded phone number to its original state is:

P = (C - key) mod 10.

In Java, this might look like this (assuming variables previously defined as integers for p, c and key):

p = (c - key) % 10;

if(p<0)
  p= p + 10;

The if condition is necessary in Java because of the way the modulus operator (%) handles negative numbers.  When (C-key) produces a negative number, the Java modulus operator returns that negative number.  To counteract that, add 10 to the result. 

For more information and variations on this cipher, check out modulo encryption.(optional)

In Java, the % is the modulus operator, so you could use it in combination with the addition or subtraction operator for the variables, like this:

C =(P + key) % 10  

P =(C - key) % 10  //use an if condition next to test for a negative result

if(P < 0)

  P= P + 10;

Use this cipher for each individual digit in the phone number.  For example, the client provides this security code: 135.  The security code is broken down to three encoding keys: 1 (for the area code) 3 (for the exchange) 5 (for the subscriber number).  We will use an example phone number, such as 707-123-4567. 

?The area code will be encoded using the Caesar cipher as follows, using the first digit in the security code (1) as the encoding key on each of the numbers in the area code: 7, 0, 7: 
?C = (P + code) mod 10. 
?8 = (7 + 1) % 10
?1 = (0 + 1) % 10
?8 = (7 + 1) % 10
?The exchange will be encoded using the Caesar cipher as follows, using the second digit in the security code (3) as the encoding key on each of the numbers in the exchange:1, 2, 3: 
?C = (P + code) mod 10. 
?4 = (1 + 3) % 10
?5 = (2 + 3) % 10
?6 = (3 + 3) % 10
?The subscriber number will be encoded using the Caesar cipher as follows, using the third digit in the security code (5) as the encoding key on each of the numbers in the subscriber number: 4, 5, 6, 7: 
?C = (P + code) mod 10. 
?9 = (4 + 5) % 10
?0 = (5 + 5) % 10
?1 = (6 + 5) % 10
?2 = (7 + 5) % 10
The resulting phone number is therefore 818-456-9012.

Minimum Requirements:
?Create a separate class that contains the following methods (5 points) Note: This class should be separate and apart from the public class that holds the main method.  You can either make a class that is not a public class or you could put it in a separate .java file: 
?A method that will accept a parameter as an integer array for the phone number and a parameter for the security code (you choose the data type for the security code).  Use one (or more) repetition structures to replace each number in the array with its encrypted version using C = (P + key) mod 10 with the appropriate digit in the security code as described above. Note: You should make the replacement in the original array. (5 points)
?Create a method that will accept an encrypted phone number as an integer array and the decoding key.  Use one (or more) repetition structures to return it to its plain text (decrypted) version using P = (C - key) mod 10 and the conditional:  
?if(P < 0)     P= P + 10;
?Note: You should make the replacement in the original array. (5 points)
?Call the methods of this class in the main method with at least one sample phone number.  Display the phone number in main before and after calling each method (5 points).
Important Note: You can get the phone number from the user at the console or with a GUI if you prefer to do that, but it is not required.  You can put the phone number in the code when you create the array instead if you would rather do it that way.  Regardless of how you get the phone number, it must be put in an array and the array must be passed to another method that accepts an array as a parameter.  You should not get the phone number and process it in the same method
You should be comfortable with the content in the modules up to and including the module "Input Output" for this project.

For this project, download the text file weblog.txt 
Note: To download this file, right click on the link and select SAVE AS.

This file is an Apache web log taken from the web server for St. Mary's University. When a visitor goes to their web site, the visitor's browser makes a request to the web server to view a web page, which is a file residing on the server. Each time a page is requested by a browser, the web server records information about that request. This weblog.txt holds the details of some of those requests. See below for a list of fields with an example:

Web Log Example 

This file does not include all possible information that could be collected by a web server. The full description of the apache log file format can be found here: http://httpd.apache.org/docs/2.2/logs.html

For this project, you can use each line of the web log file as one string. An array of size 2990 will hold all of the lines in this file.

Minimum Requirements:

?Create a separate class that contains the following: (4 points). Note: This class should be separate and apart from the public class that holds the main method.  You can either make a class that is not a public class in the same file or you could make it public and put it in a separate .java file: 
?Create a method to read each line of the web log file. (4 points)
?Each line should then be stored in a private array created in the class, such that the first element of the array is the first line of the web log file. Because each element will hold an entire line from the file, the array should be declared as an array of strings (4 points).
?Create one more method to use the Arrays class sort method to sort the contents of the array and write the contents of the array to a file. The contents of the new file should look like the original input file once your program completes, but in sorted order (4 points).
?In the primary class for your package, create a main method that calls all of your methods (4 points).
You should be comfortable with the content in the modules up to and including the module "Arrays" for this project.

Create a class called consultCo that holds a private class called employee that contains the name, pay rate and social security number of an employee of a consulting firm called consultCo. The consultCo class should also have an array that holds all of the objects of all of the employees in the array.  This will be an array of employee objects.

Here is a logical diagram of this array of objects:

 



You will also need methods to satisfy the following requirements:

Minimum Requirements:

?An add method to hire a new employee.  This method should create a new object with the employee information (name, payrate and social security number) and then it should add that new object to the array.  You are not required to update an employee s data if the employee exists. (5 points)
? A report method that will display the name, pay rate and social security number of all employees. (5 points).
?A raise method that will give all employees a 10% raise. (5 points).
?You will also need a main method that creates calls the method(s) you created to meet the requirements of this project (5 points).
Notes: 

You will need at a minimum two (2) classes for this project: the public class that contains the main method and a class that is a private class that is a member of another class.  If you would like to include more than 2 classes, that is fine but not required.

The Module Lab Activities "Lookup!" and/or "Lookup! With GUI" (a GUI is great but not required) can be extremely helpful for this project.  Just by following the lab activity (and the video demos if needed), you can make significant progress toward completing this assignment.
 
 
分享到:
评论

相关推荐

    javamianshiti.rar_C 笔试题_java 试题_java笔试题_java面试_笔试

    【标题】"javamianshiti.rar_C 笔试题_java 试题_java笔试题_java面试_笔试" 提供了一个关于Java编程语言的面试和笔试准备资源的集合,其中可能涵盖了C语言的基础知识以及Java的核心概念。 【描述】"java面试笔试题...

    变态版java笔试试题

    Java 笔试试题变态版知识点总结 Java 笔试试题变态版是 Java 开发者面试的常见题目,涵盖了 Java 基础知识、垃圾收集器、字符串、Math 函数、线程、数组、多态性、Set 集合等方面。 一、垃圾收集器(GC) 垃圾...

    农行Java笔试题

    【标题】"农行Java笔试题"涉及到的Java知识点涵盖了编程基础、面向对象特性、集合框架、多线程、异常处理、IO流、网络编程、数据库操作等多个领域,这些都是Java程序员必须掌握的核心技能。 首先,从编程基础角度来...

    java试题 java笔试题 java面试题

    Java 试题、Java 笔试题、Java 面试题 本资源摘要信息中,我们将对 Java 相关试题、笔试题和面试题进行总结和分析,涵盖了 XML 解析技术、Struts 框架、ArrayList 和 Vector 的区别、HashMap 和 Hashtable 的区别、...

    java笔试题笔试题

    java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 java笔试题 ...

    java笔试题库.pdf

    #### 七、其他常见笔试题 1. **Java中的基本数据类型有哪些?** - **解析**:Java中的基本数据类型包括: - `byte` - `short` - `int` - `long` - `float` - `double` - `boolean` - `char` 2. **Java中...

    最全的Java笔试题库之选择题篇-总共234道

    最全的Java笔试题库之选择题篇-总共234道 15.下列哪一种叙述是正确的( ) A. abstract修饰符可修饰字段、方法和类 B. 抽象方法的body部分必须用一对大括号{ }包住 C. 声明抽象方法,大括号可有可无 D. 声明...

    2020 兴业银行Java笔试题

    【Java笔试题解析】 在2020年兴业银行的Java笔试中,涉及了多个核心的Java编程和技术概念。以下是对部分题目进行的详细解答: 1. 输入一个正整数,计算并输出距离它最近的对称数 对称数是指从左向右读和从右向左...

    java面试笔试资料java笔试题大集合及答案题库java笔试题汇总资料188个合集.zip

    java面试笔试资料java笔试题大集合及答案题库java笔试题汇总资料188个合集 100家大公司java笔试题汇总.doc 125条常见的java 面试笔试题大汇总.pdf 2011最新整理java经典代码.doc 25个经典的Spring面试问答.docx ...

    java笔试试题(淘宝)

    根据提供的文件信息,标题为“java笔试试题(淘宝)”,描述中提到包含了C、C++、Java等编程语言的笔试试题,并且指出这些试题非常有用,可供下载。结合这些信息,我们可以推断这份文档可能包含了一些针对Java以及相关...

    java笔试题加答案(单选,多选,判断,简答)

    Java笔试题是评估应聘者Java编程能力的重要环节,通常包括单选题、多选题、判断题和简答题。这些题目覆盖了Java语言的核心概念、类库、编程规范以及问题解决能力。以下是一些可能出现在Java笔试题中的关键知识点: ...

    Java笔试题大集合及答案(另附各大公司笔试题)

    本资料集合了大量Java笔试题,旨在帮助求职者全面复习并准备Java相关的笔试环节,同时包含了各大公司的经典试题,以期提供更丰富的实践应用场景。 1. **基础语法**:这部分主要考察对Java基本语法的理解,如变量...

    常见的Java 笔试题

    在软件开发领域,尤其是IT行业,Java程序员的需求量大,因此Java笔试题成为了评估应聘者技能的重要手段。以下是一些常见的Java笔试题及其相关知识点: 1. **数据类型与变量**: - Java分为基本数据类型(如int, ...

    西安软件公司java笔试题

    为了充分准备这些Java笔试题,建议进行大量实践,编写代码,解决实际问题。同时,通过阅读《Effective Java》、《Java并发编程实战》等经典书籍,可以提升你的理论水平和实战能力。愿你在西安的软件公司Java笔试中...

    java笔试题大全

    Java笔试题大全是一份集合了众多Java编程相关的面试与笔试问题的资源,旨在帮助学习者和求职者系统性地复习和提升Java技术能力。这份资料可能涵盖了基础语法、面向对象编程、集合框架、多线程、异常处理、IO流、网络...

    java面试笔试题库java软件设计java笔试题大集合及答案文档资料合集300MB.zip

    java面试笔试题库java软件设计java笔试题大集合及答案文档资料合集300MB“ 100家大公司java笔试题汇总.doc 125条常见的java 面试笔试题大汇总.pdf 2011最新整理java经典代码.doc 25个经典的Spring面试问答.docx 8张...

    JAVA笔试题-包含JAVA各个方面的笔试题

    【JAVA笔试题-包含JAVA各个方面的笔试题】 Java是一门广泛应用的编程语言,以其跨平台、面向对象的特性深受开发者喜爱。在准备Java相关的笔试或面试时,掌握以下几个关键知识点至关重要: 1. **基础语法**:理解...

    java笔试题大集合及答案.zip

    本压缩包"java笔试题大集合及答案.zip"提供了丰富的Java相关试题,涵盖了EJB(Enterprise JavaBeans)、Java基础知识、编程题目、求职笔试、线程编程等多个关键领域。下面将对这些知识点进行详细的阐述。 1. **EJB...

    Java笔试题代码.png

    该文件为山大地纬Java开发岗笔试试题 该文件为山大地纬Java开发岗笔试试题 该文件为山大地纬Java开发岗笔试试题 该文件为山大地纬Java开发岗笔试试题 该文件为山大地纬Java开发岗笔试试题

Global site tag (gtag.js) - Google Analytics