Home Page > > Details

ITE3101 ProgrammingHelp With ,Java ProgrammingHelp With

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;
}
}

Contact Us - Email:99515681@qq.com    WeChat:codinghelp
Programming Assignment Help!