首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
ITE3101编程辅导、Java程序语言辅导
ITE3101 - Introduction to ProgrammingAssignment (2021/22) Version 1
ITE3101_Assignment_Question_GA_2021.docx
Page 1
ITE3101 Introduction to Programming
EA1 - Programming Assignment Hand-out: 11/11/2021 9:30
Deadline: 02/12/2021 17:30
Important Notice to Students
1. This assignment should be done by individual student. All downloaded materials are not
allowed.
2. Plagiarism will be treated seriously. All assignments that have been found involved
wholly or partly in plagiarism (no matter these assignments are from the original authors or
from the plagiarists) will score ZERO marks.
3. Your program must be compiled and run with ONLY the following commands for Java
JDK6 or above.
C:\...\bin\javac SphereDistances.java
C:\...\bin\java SphereDistances
4. Your program must be structured and well commented.
The first few lines in the source file must be comments stating the name of the source file,
student name, student ID, course name, course code, and brief description of your
program. Marks will be deducted if such comments are not included.
/********************************************************
Program File: SphereDistances.java
Programmer: Chan Tai Man (180000000)
Programme: IT114… - HD in …
Description: This program is …
…
********************************************************/
5. A sample program, Sample.java, is provided for your reference. You can use the program
codes to read data from a text file, e.g. spheres.txt.
6. Test your program with the given data file, points.txt.
7. Put all your program codes in a SINGLE Java source file named as
SphereDistances.java. Submit your UNZIPPED source file to the Moodle link
EA1_Submission.
8. This is part of End-of-Module Assessment (EA). The weight of this assignment is 20% of
the module total assessment.
ITE3101 - Introduction to ProgrammingAssignment (2021/22) Version 1
ITE3101_Assignment_Question_GA_2021.docx
Page 2
Calculating Distances of Spheres on a 3-D Space
Background
We use x-, y- and z- coordinates to represent spheres on a 3-D space. We can measure the
distance (d1,2) of any two distinct spheres, S1(x1, y1,z1) and S2(x2,y2,z2) by the following formulas:
𝑑1,2 = √(𝑥1 − 𝑥2)
2 + (𝑦1 − 𝑦2)
2 + (𝑧1 − 𝑧2)
2
Figure 0. Distance between two spheres in a 3-D space
Tasks
Write a Java program to do the following tasks:
1. Read a set of Si(xi,yi,zi) parameters representing some spheres from a text file,
e.g. points.txt.
-80 10 65
1 13 -78
…
28 -6 35
38 -39 -33
ITE3101 - Introduction to ProgrammingAssignment (2021/22) Version 1
ITE3101_Assignment_Question_GA_2021.docx
Page 3
2. When the program starts, Main Menu will be shown as follows: (5 masks)
Name: CHAN Tai Man (210000000) IT114206/1D
*** Main Menu ***
1) Display the spheres data
2) Calculate the distance
3) Display the 10 shortest distance
4) Credit
9) Quit
You have to handle the following user input:
User Input Action
1
(15 marks)
Display the All spheres data. (Show data in 3 spheres each line )
(See Figure 1. Sphere Data )
Proceeds to Main Menu
2
(15 marks)
Prompt the user to enter 2 indexes, and calculate the distance of two spheres
(See Figure 2. calculate the distance )
Proceeds to Main Menu
3
(20 marks)
Display the 10 shortest distances (together with their spheres)
(See Figure 3. 10 shortest distances)
Proceeds to Main Menu
4
(10 masks)
Display the Credit (Design by you, include your description, your name)
(See Figure 4. Credit)
Proceeds to Main Menu
9
(5 masks)
Confirm whether the user chooses to Quit the program
(See Figure 5. Quit)
[1 – Yes] to Quit program , [0 – No] to Main Menu
Other Assessment Criteria
Problem solving techniques, e.g. algorithms, data structures, and
Java programming technique, e.g. statements, control structures, etc. (10 marks)
Programming style. (10 marks)
Testing (10 marks)
Resources
Please download the following files from Moodle:
Sample.java
spheres.txt
ITE3101 - Introduction to ProgrammingAssignment (2021/22) Version 1
ITE3101_Assignment_Question_GA_2021.docx
Page 4
Appendix A – Expected output of your program with the given spheres.txt file
Name: CHAN Tai Man (210000000) IT114206/1D
*** Main Menu ***
1) Display the spheres data
2) Calculate the distance
3) Display the 10 shortest distance
4) Credit
9) Quit
Figure 0. Main Menu
1. Sphere Data
Total 15 Spheres
S1 [-94,11,63] S2 [1,3,-88] S3 [-88,-96,80]
S4 [99,49,77] S5 [41,-92,-9] S6 [-47,-77,-59]
S7 [-54,-33,52] S8 [-65,83,-80] S9 [-91,-97,-43]
S10 [-28,27,75] S11 [65,12,20] S12 [-55,45,28]
S13 [39,-98,1] S14 [-99,9,10] S15 [0,0,0]
--\\ Enter <
> to return Main Menu\\--
Figure 1. Sphere Data
2. Calculate the distance
Please enter the First sphere index(1-15): 2
Please enter the Secord sphere index(1-15): 10
The distance is 162,
between S2 [1,13,-78] and S10 [-18,39,81]
--\\ Enter <
> to return Main Menu\\--
Figure 2. Calculate distance
3. Display 10 Shortest distances
The 10 shortest distances:
Rank 1st Sphere 2nd Sphere Distance
1 S12 S15 40
2 S13 S14 40
3 S4 S11 41
4 S6 S9 48
5 S11 S13 48
6 S5 S15 56
7 S1 S7 57
8 S11 S14 62
9 S1 S10 70
10 S3 S7 72
--\\ Enter <
> to return Main Menu\\--
Figure 3. Shortest distances
ITE3101 - Introduction to ProgrammingAssignment (2021/22) Version 1
ITE3101_Assignment_Question_GA_2021.docx
Page 5
4. Credit
********************************************************
Program File: SphereDistances.java
Programmer: Chan Tai Man (210000000)
Programme: IT114… - HD in …
Description: This program is …
********************************************************
--\\ Enter <
> to return Main Menu\\--
Figure 4. Credit
5. Quit
End of program
Figure 5. Quit
--- END ---
* Design by yourself
ITE3101 - Introduction to ProgrammingAssignment (2021/22) Version 1
ITE3101_Assignment_Question_GA_2021.docx
Page 6
Sample.java
import java.io.File;
import java.util.Scanner;
public class Sample {
final static int MAX_NO_POINTS = 20; // maximum number of input points
final static int X = 0; // array index for x-coordinates
final static int Y = 1; // array index for y-coordinates
final static int Z = 2; // array index for z-coordinates
public static void main( String[] args ) throws Exception {
int p[][] = new int[MAX_NO_POINTS][3]; // array to store the points parameters
int nPoints; // number of points read
nPoints = readPointsFile( "points.txt", p );
System.out.println( "Points read from points.txt" );
for (int i=0; i
System.out.println( p[i][X] + "," + p[i][Y] + "," + p[i][Z] );
}
/***************************************************************************
This is a method to read the parameters (x-, y-, z-coordinates)
of points from a text file.
Inputs:
filename is the file name of the input file
Outputs:
points[][] is a 2-dimensional array to store parameters
e.g. points[0][0] stores the x-coordinate of the 1st point
points[0][1] stores the y-coordinate of the 1st point
points[0][2] stores the z-coordinate of the 1st point
...
points[n-1][0] stores the x-coordinate of the last point
points[n-1][1] stores the y-coordinate of the last point
points[n-1][2] stores the z-coordinate of the last point
Return value:
the total number of points read
***************************************************************************/
public static int readPointsFile( String filename, int[][] points ) throws Exception {
// Create a File instance and a Scanner for the input file
File inFile = new File( filename );
Scanner input = new Scanner( inFile );
// Read parameters of points from the input file
int nPoints = 0; // count number of points read
while (input.hasNext()) {
points[nPoints][X] = input.nextInt(); // read x-coordinate
points[nPoints][Y] = input.nextInt(); // read y-coordinate
points[nPoints][Z] = input.nextInt(); // read z-coordinate
nPoints++;
}
// Close the input file
input.close();
return nPoints;
}
}
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
辅导 infosys 110 digital sys...
2024-12-28
辅导 fbe 506 quantitative me...
2024-12-28
讲解 part i: (crazy eddie ht...
2024-12-28
辅导 infosys 110 digital sys...
2024-12-28
讲解 stats 769 statistics se...
2024-12-28
辅导 ece3700j introduction t...
2024-12-28
讲解 tcm2301 biochemistry讲解...
2024-12-28
讲解 ece5550: applied kalman...
2024-12-28
辅导 mth205 introduction to ...
2024-12-28
辅导 scicomp project 3 week ...
2024-12-28
讲解 business operations ana...
2024-12-28
辅导 mth205 introduction to ...
2024-12-28
辅导 socs0100 computational ...
2024-12-28
讲解 bre2031 – environmenta...
2024-12-28
讲解 malloc lab: writing a d...
2024-12-28
辅导 meaning of work assignm...
2024-12-28
讲解 liquidation and investm...
2024-12-28
辅导 jc360 interactive media...
2024-12-28
辅导 csc 110 y1f fall 2024 q...
2024-12-28
讲解 bman 73271 decision beh...
2024-12-28
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!