找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1147|回复: 20

谁会JAVA编程

[复制链接]
发表于 2007-5-9 13:27:08 | 显示全部楼层 |阅读模式
救急 ; o* K0 x% @" F: N& ?8 r. H9 M9 z; H& R) p: U0 M2 L
回复

使用道具 举报

 楼主| 发表于 2007-5-9 13:57:40 | 显示全部楼层
没人懂吗?
回复

使用道具 举报

发表于 2007-5-9 13:58:19 | 显示全部楼层
偶懂一点点点
回复

使用道具 举报

 楼主| 发表于 2007-5-9 13:58:55 | 显示全部楼层
我在做作业啊...遇到不会的问下你..
回复

使用道具 举报

发表于 2007-5-9 14:00:01 | 显示全部楼层
还给老师了
回复

使用道具 举报

发表于 2007-5-9 14:00:25 | 显示全部楼层
我晕到,做JAVA的作业啊  ,你学啥子的
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:00:46 | 显示全部楼层
问下,如果有两个.java的文件,这两个文件有相似性...我们的要求是写一个另外的java程序,然后可以载如 这两个java文件,进行code的逐行对比,然后列出相似的行和相似内容,应该用什么类
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:11 | 显示全部楼层
//*********************************************************************
: l5 L! l: h4 `" |//  ProgramCompare.java         Provided by: DRS
6 j; a3 d# O8 }9 |. T- D0 w0 q& q//
4 E: m. T, ?! W) W0 d0 o# V% r3 |//  Program shell for Assignment 27 M) P  j0 w  s4 M4 N. p1 L
//
- o& S% ~4 h! {2 K1 X/ @1 j9 x( J' r//  Compares two text files line by line
" I8 E1 V/ e1 q2 U//*********************************************************************4 N0 U) [% E1 G
9 b( y) U# N$ R+ d& {
import java.io.*;
' W+ @- \0 p5 i; x( `
# z0 n; c8 c( }6 mpublic class ProgramCompare
4 }1 R- a; o2 s{! V& y# R& D& B( z& U) s
        //-----------------------------------------------------------------
4 A( o  Y. Q! ]        // Constructor" f  Y, i& O: p2 a
        //-----------------------------------------------------------------+ @+ a$ w3 O1 p0 _* A% ^; |
        public ProgramCompare()
. ^7 c6 X; u' X: \        {$ u0 `; c" X) l& W4 Z& P
        }
8 i8 x! q+ ]0 L" T- j6 E- I7 k- Q" x
        //-----------------------------------------------------------------' D5 @4 A& G' D1 u
        // Method for testing that class has been reached
6 X8 ]# U$ D+ _& @* o5 F        //-----------------------------------------------------------------        8 d2 M) S' G8 z1 B; G

2 u: M' a% K: G$ [2 }& t        public boolean ProgramCompareReached()         4 O* h' H* f) p/ Q) O  \) ?1 a
        {
( w" o! X: I: W' c- d; B8 j      try
- ~: {) g+ C% x$ l# r8 [, k   {        
+ P6 M# b2 s( G7 h8 c% A, j                        ) v* K0 _% Q7 F7 `" t
                //********************************************************************% C2 v0 o' U; G9 @4 z
                // Try-Catch Statement is used to handle exceptions - such as file not found
* N# F- z" b( `; y. o6 {# r! C* o                // Reading the files will need to be placed inside a Try-Catch - just like this one!
; J1 o' W6 c& f3 t: V$ g3 L                // For more information see page 534 of the textbook
9 ~2 \: Y: e$ q                //********************************************************************: p0 ~2 e+ ^! T
                     . E6 B: E" S7 x( x# u* [# p* G0 m8 T. t
        }3 |* v( g3 M4 a+ ]; d) W
             catch (Exception ex) // Exception caught here and message displayed to the screen . |& u+ u  `, d" B  |3 d4 C$ `
          {
6 y3 V2 U; |9 j4 K$ @; g                    ex.printStackTrace (System.err);# Z& I# C5 E2 f2 k" G: |% v
           System.out.println ("Error message goes here"); // Replace this error message with your own         
' J( h! L2 l8 l9 [% P        }- Y# W/ j1 |( B# q
                return true;
, H) n/ S7 M; V" E  j3 d5 X        }
. ]/ Z/ y9 q# b( U& ]' C& a! F0 n, e# X' q/ O; Z( @9 c5 K
} // end of class ProgramCompare
; x! d" Q; ]+ k0 G1 \4 w6 M
+ j) _+ k5 g8 [: Z+ W/ |" M//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:41 | 显示全部楼层
//********************************************************************
3 Q9 J5 `( g$ z0 c5 U2 R  J//  ProgramCompareMenu.java    Provided by: DRS( m7 u; x5 i% h5 |
//& V2 _( H3 ^& r' r# q7 n% m
//  Calls AuthorisedUsers.java and ProgramCompare.java
. l  |! f) E' l$ s4 h6 k//
+ P1 H2 S) f# }: i1 Z0 V//  Driver shell for Assignment 2.
/ g+ P9 q7 b  L3 H2 z//********************************************************************
! W! g, v1 C' d" |
0 S$ I3 o4 B* K5 Z# w: Q- D9 Cclass ProgramCompareMenu! u& ]0 L) ~1 X, S" |- D
{
% Q$ {! A  y+ N* k6 M* n3 F( m/ x7 N    public static void main (String[] args)
8 f( d. u1 {0 P% s4 `3 \+ W            {
( {4 x( t  b/ u8 E: D; ~, }                //Check that the two classes ProgramCompare and AuthorisedUsers are reachable
1 ~% D+ `) Z; E* v* f                ProgramCompare reached1 = new ProgramCompare();
- r6 h/ e; Q  ?% E: N8 _9 K' p                AuthorisedUsers reached2 = new AuthorisedUsers();        5 y2 d5 W7 c& Z2 N, z6 I! _5 V" k' U
                System.out.println("ProgramCompare reached? " + reached1.ProgramCompareReached());  t- y" T0 G: H  }0 J
                System.out.println("AuthorisedUsers reached? " + reached2.AuthorisedUsersReached());        $ O3 X1 k* \8 u9 n+ L) _5 g+ g
        }
( S6 W7 U/ _* v: D0 P}// end of class ProgramCompareMenu
  Z/ k( o7 l' q
6 ?+ J, u/ p# B' D+ q0 k  @* a! ?//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:55 | 显示全部楼层
//********************************************************************  l8 H0 J6 ^( |& N$ @
//          AuthorisedUsers.java          Provided by: DRS1 `( e% j, r5 i9 @4 o4 }
//                ; y8 O& @/ \" }  M2 ]
//         Program shell for Assignment 2
& Q- K5 D( u; o/ {8 O, ^8 G//
. c8 H1 _9 }+ ^! Z3 d; P//         Represents facts about an AuthorisedUser0 \* I4 y. z- Y7 s2 n
//********************************************************************6 w+ L. ?/ y' x

4 x* H9 r" _1 D- f6 Wpublic class AuthorisedUsers% Z/ T+ `" X4 M* A9 I4 v6 O+ H
    {
! P3 G* A6 P4 ~1 [$ z/ Z* {4 @6 r4 d0 e( d* e
        //-----------------------------------------------------------------
' d8 e9 |- |$ }# h' {- a        // Constructor/ F1 H& G2 j7 U8 n8 g0 v( Q6 A
        //-----------------------------------------------------------------  f( P/ z0 n, ~2 [( Y; k
0 p6 p" T& w0 N& {1 d( m6 G2 j& c
        public AuthorisedUsers()
% {5 Q# s; {  }* ]8 Z  n0 v                {
4 a+ Q9 B; ~3 q7 Z: Z# T                }' i% Z& ?; I+ w* ?9 m6 V0 I7 q
& }% ~+ h% \. u3 ]
        //-----------------------------------------------------------------
6 t0 j9 M* j( c# Q3 L4 u        // Method for testing that class has been reached
9 ^5 B# N8 i5 X" q        //-----------------------------------------------------------------          h5 I  W, d1 {9 M* h
        public boolean AuthorisedUsersReached()
/ |- w6 t1 f! V3 t) H4 c$ c                {, ]' x0 H! h/ `5 s  c2 v' e2 h
                        return true;                        4 f! J2 u+ s, q! E
                }
0 N1 Y% R  H1 D" I4 E2 `5 o                . d. A" ~% E* P% M
    } // end of class AuthorisedUsers
# r! ^& n! k, f//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:03:32 | 显示全部楼层
BSA104 Business Programming7 t4 S0 Z8 W5 O5 U% U4 ], @
Shanghai - 20072 G- q2 ~* }, q5 q) i2 l! j
Assignment 2# {$ q8 W& }2 D- j+ S) q8 n7 J$ J3 o' c
Deadline for Submission: 10:00 pm (Shanghai time), Tuesday 15th May 2007 Assessment Weighting: 20% of the total assessment for BSA104 Assignment Type: Individual Scenario: The teaching staff at a nearby university are concerned that some of their students are submitting other students‟ work. They need a simple Java program that will compare the text of two other Java programs, line by line, for equality, and then print out the results, and a recommendation. Requirements: Consider the three Java Classes: ProgramCompareMenu.java, ProgramCompare.java and AuthorisedUsers.java, available from the Assignment 2 page on Vista. You are required to perform the following tasks: The ProgramCompareMenu class: (Total maximum 20 marks available)' U2 ~% M/ h" N6 B+ l" \+ K
1. Provide a basic text-based menu interface to the ProgramCompare class so that it can be used by two staff members to determine if the two supplied Java programs are the same or similar.- ~& Q9 }* j7 s
The staff must be able to:2 u9 t; c% A( i& [8 C- \5 P4 s
 Log on to the „system‟ using their user name, and a Personal Identification Number (PIN) which is a four digit number **.8 j4 \: D- M7 n- L6 M4 |  [+ k& _
1. The user should not be able to use the „system‟ until they have provided the correct user name and PIN combination. You should give them a second or third chance to get it right before shutting the „system‟ down.
9 P) L$ g$ ]. u The interface should provide a menu so that the staff can:1 V9 J" Z, p' e" p: D
a) Enter the names of the two Java program files to be compared
, L8 S" n" p  G For this assignment, it will be assumed that the two Java program files are in the same folder as your program." B: ^9 S# {% o; f. @
** You must use the two user names and PINs provided in your individual data available from the Assignment 2 page on Vista (see requirement 5 below). The user names and PINs should be included in your code, and the output to the screen should prompt the user with the user names and passwords (for marking purposes).
, {# F# A% \! D5 |* W' n4 cBSA104 Business Programming – 2007: Assignment 2
, F; [9 ]4 i2 S3 WPage 2 of 5  Z' l; @7 m( U# U. E
b) Print out to the screen all the lines of code that are the same2 r  W! x4 m8 @2 M0 k( U4 c, B9 X
 Include the name of the file and the line number of the code being printed for each of the two files
- @% b" K" P, Z2 c0 \3 k! `c) Print out to the screen all the available information regarding the evaluation of the two Java program files being compared
/ O% w7 X7 K3 _+ b& z the name, username and department of the user
4 b4 L4 T8 G8 ~4 m the statistics of the comparison
0 l( v- C8 W& `" V  d' ^7 `0 b- For example: the number of lines of code checked, the number of lines the same, the number of lines that are different
3 X% }' Q7 h% S9 V5 ~' \$ { the recommendation for further checking
) {% C( k4 [+ ?2 [, n7 J- For example: if more than 5 (five) lines of code are the same in each Java program file, then print a recommendation to the screen that the staff member check the files more closely7 J( X. ?* E% X1 c. _0 y: t; J) `+ n1 b
 the names of the two files compared/ L! t/ I! A/ p5 U- |# ]
d) Leave the program (exit)
: J# H3 m: k8 G; |: L. }9 DThe ProgramCompare class: (Total maximum 20 marks available)" o% E. e* Z- ]3 {
2. Provide a method/s to read in each line of code from the two files identified by the user: (assumed that the two Java program files are in the same folder as your program)5 b3 V$ _+ F( f# j3 d5 G+ I0 F  y
a) provide an error message if the files are not found or there is a problem opening them8 \9 O8 N. r1 W) N
b) compare each line of code2 I, |+ a0 ~: V2 z
c) print out the lines that are the same
& G5 I/ J: C1 o3 ~9 zd) count the number of lines compared / lines the same3 c5 n9 b3 [+ g% J" r! C3 [: j
The AuthorisedUsers class: (Total maximum 20 marks available)
3 M! b; J) Y; {' w# Z  g- }5 n8 U3. Provide an object that contains the name, username, PIN, and Department of the authorised users of the program (user names and PINs as provided in your individual data - see requirement 5 below)
* |# A% v) ~9 Y2 W4. Provide methods to:
* B, e" b1 L: c" P+ ]( a' j' Za) compare the stored username and PIN with the one entered by the user - return a value that indicates whether they match or do not match
* Y; U; C3 |8 y2 B; Vb) return the name of the authorised user: [: t8 j1 f2 K
c) return the name of the department of the authorised user
! k* a0 o/ v5 ?! R  bIndividual Data (Maximum 20 marks available)
( D0 F, a6 H6 i9 w7 ?7 w/ W8 ~5. You will be given two staff member names, usernames, PINs, and department name, plus a set of two Java program files to compare using your program. You will need to log onto the BSA104 Assignment 2 page on Vista to generate your individual data and instructions for this requirement. You will need to use your University of Tasmania (UTas) student number.
5 W; T; j) c* h% |9 v  c$ u+ qDocumentation (Maximum 10 marks available)8 m( q+ I' A* h$ T) [  o' o& d
6. Your program files should be fully documented, at least to the same standard as demonstrated in the textbook. This includes in-code comments, descriptions, and where appropriate, explanations for each new constructor, method and variable.$ h# P# H# T! f0 f
BSA104 Business Programming – 2007: Assignment 2: n: [/ F: L3 c. A+ a
Page 3 of 5
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:03:53 | 显示全部楼层
上面是作业要求,然后前三个是给的java程序,要求自己修改- -
回复

使用道具 举报

发表于 2007-5-9 14:04:47 | 显示全部楼层
我的妈咪哦,这个已经超出了,我的一点点了) ?0 S, p5 W- H" L: Z, _
不过你要翻JAVA的类库说明。你有下载没有?- ~( t" H0 G2 M4 [
查询关于对比的函数。貌似关键字是contrast,还有compare
/ ]% d8 o/ M0 ?2 _9 r( I' `
. J# J6 t6 y* {- K1 f! N2 w[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:05 编辑 ]
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:06:19 | 显示全部楼层
,.....看来还要翻书哇....我学信息系统的- -
6 z) P$ D" A6 d8 O痛苦啊15搞要交..没觉睡了
回复

使用道具 举报

发表于 2007-5-9 14:07:54 | 显示全部楼层
不是翻书,是要翻在SUN下载的JAVA的手册,书有个毛用。
* O/ i- N9 D8 |# U" r8 y# f可以下载到的 是 jdk-1_X_0-doc
) R4 k- P; r, A" O: X, G$ Z. f5 V/ J' z# E0 A3 r9 t) B+ G3 K
[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:09 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|=|HERO|=战队 ( 皖ICP备19020640号 )|网站地图

GMT+8, 2026-3-29 22:53

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表