关于后端:ITE3101-基础介绍

37次阅读

共计 6094 个字符,预计需要花费 16 分钟才能阅读完成。

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)
    • (𝑦1 − 𝑦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:
  9. Read a set of Si(xi,yi,zi) parameters representing some spheres from a text file,
    e.g. points.txt.
    -80 10 65
  10. 13 -78
  11. -6 35
  12. -39 -33
    ITE3101 – Introduction to ProgrammingAssignment (2021/22) Version 1
    ITE3101_Assignment_Question_GA_2021.docx
    Page 3
  13. 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
  14. 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 <<any key>> to return Main Menu\–
    Figure 1. Sphere Data
  15. 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 <<any key>> to return Main Menu\–
    Figure 2. Calculate distance
  16. Display 10 Shortest distances
    The 10 shortest distances:
    Rank 1st Sphere 2nd Sphere Distance
  17. S12 S15 40
  18. S13 S14 40
  19. S4 S11 41
  20. S6 S9 48
  21. S11 S13 48
  22. S5 S15 56
  23. S1 S7 57
  24. S11 S14 62
  25. S1 S10 70
  26. S3 S7 72
    –\ Enter <<any key>> to return Main Menu\–
    Figure 3. Shortest distances
    ITE3101 – Introduction to ProgrammingAssignment (2021/22) Version 1
    ITE3101_Assignment_Question_GA_2021.docx
    Page 5
  27. Credit


    Program File: SphereDistances.java
    Programmer: Chan Tai Man (210000000)
    Programme: IT114… – HD in …
    Description: This program is …


    –\ Enter <<any key>> to return Main Menu\–
    Figure 4. Credit

  28. Quit
    End of program
    Figure 5. Quit
    — END —
  29. 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 intMAX_NO_POINTS; // 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<nPoints; i++)
    System.out.println(pi + “,” + pi + “,” + pi);
    }
    /*
    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. points0 stores the x-coordinate of the 1st point
    points0 stores the y-coordinate of the 1st point
    points0 stores the z-coordinate of the 1st point

    pointsn-1 stores the x-coordinate of the last point
    pointsn-1 stores the y-coordinate of the last point
    pointsn-1 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()) {
    pointsnPoints = input.nextInt(); // read x-coordinate
    pointsnPoints = input.nextInt(); // read y-coordinate
    pointsnPoints = input.nextInt(); // read z-coordinate
    nPoints++;
    }
    // Close the input file
    input.close();
    return nPoints;
    }
    }

正文完
 0