Recent Question/Assignment
DPIT111 Assignment 1
Week 4
Objectives
• Data types, variables, constants
• Expressions, math methods, executable statements
• Input and output
• Comments
• Class and object
Assignment 1 (12%) is marked on a scale from 0-12 marks.
• Question 1: 3 mark
• Question 2: 3 mark
• Question 3: 3 mark
• Question 4: 3 mark
Important notices:
This assignment is scheduled to be done in Week 4 (Monday 30 March - Sunday 5 April 12:30 pm). Comments for your work can be checked on Moodle site. You may be asked questions about your code. Your marks will be deducted if you could not answer the questions presented by the assessor.
1. Students must submit all assessment tasks by the due date or penalties will be applied.
No. of calendar days late Penalty
1 10% of the original mark.
2 20% of the original mark.
3 30% of the original mark.
More than 3 A mark of zero will be awarded for the assessment.
2. Make sure that you include following personal information in every file, otherwise it will result in 0 points.
/*------------------------------------------------------ My name:
My subject code:
My student number: My email address:
Assignment number:
-------------------------------------------------------*/
3. Ensure each file in your submission is runnable, compiling error in your file will result in 0 points for the current question. If it is runnable, though it fails to realize all functionalities, you can get partial points for what you have done.
Question 1 (3 mark) : In the Cartesian coordinate space, the radius of a circle centered at the original can be calculated as ?? = ?? + ?? , where (??, ??) is the coordinates of a point on the circumference. Write a program to ask the user to enter the horizontal coordinate x and the vertical coordinate y, calculate the radius r and then display it.
REQUIREMENTS
• The user input is always correct (input verification is not required).
• Your code must use Scanner class
• Your program shall input parameters in the following order:
- horizontal coordinate ?? - vertical coordinate ??
• The program shall perform all calculations with double data type. The radius shall be displayed
with 3 decimal point precision.
• Your code must work exactly like the following example (the text in bold indicates the user input).
Example of the program output:
Enter x: 3
Enter y: 4
Radius = 5.000
Question 2 (3 mark) : If you look at the ASCII Character Table, you'll notice that the difference between uppercase and lowercase character codes is 32. Implement a program to ask the user to enter a string of all lowercase characters and a non-negative integer position, convert the lowercase character at index position to the corresponding uppercase character and then display it.
REQUIREMENTS
• The user input is always correct (input verification is not required).
• Your code must use Scanner class
• Your code should include a method called char convert(String, int) whose arguments are a String and an int, return value is a char.
• Your code must work exactly like the following example (the text in bold indicates the user input).
Example of the program output:
Enter a string: yourname
Enter an index: 4
The uppercase of 5th letter of yourname is N
Question 3 (3 mark) : Implement a program to ask the user to enter two strings and one integer position, concatenate the substring (before index position) of the first string and the substring (from index position to the end) of the second string into a string and then display it.
REQUIREMENTS
• The user input is always correct (input verification is not required).
• Your code must use Scanner class
• Your code should include a method called String stringMerge(String, String, int) whose arguments are two Strings and an int, return value is a String.
• Your code must work exactly like the following example (the text in bold indicates the user input).
Example of the program output:
Enter the first string: abcdefg
Enter the second string: HIJKLMN
Enter an index: 3
The merged string of abcdefg and HIJKLMN is abcKLMN
Question 4 (3 mark) : Implement a program according to the following UML diagrams to ask user to input contact information and display it:
REQUIREMENTS
Person class:
• The constructor Person (int, String, int, String, String, int) shall initialize its data fields, i.e. two component objects of type class Address (the work address and the home address), email address of String type and phone number of long type. The 6 arguments refer to the street number of work address (int), the street name of work address (String), street number of home address (int), the street name of home address (String), the email address (String) and the phone number (int), respectively.
• The method getEmail() is to access email address of data fields.
• The method getPhone() is to access phone number of data fields.
• The method printContactInformation() is to display all contact information about Person class, using class data fields and methods.
• In the main(String []) method, the program shall first ask the user to input contact information details, then create an object of class Person based on these inputs, using its constructor with 6 arguments, finally call printContactInformation() method to display contact information.
Address class:
• The constructor Address(int, String) shall initialize its data fields, i.e. the street number (int) and the street name (String), the suburb (String), the post code (int) and the state (String). The 2 arguments refer to the street number and the street name. The remaining static data fields suburb, post code and state should be respectively initialized as “Wollongong”, 2500 and “NSW” by default.
The initialization of these 3 data fields can either be explicit or in the constructor.
• The method getAddress() is to generate the displaying address information using class data fields.
• The user input is always correct (input verification is not required).
• Your code must use Scanner class
• Your code must contain 2 classes
• Your code must work exactly like the following example (the text in bold indicates the user input).
Example of the program output:
Enter the street number work address: 11
Enter the street name of work address: Steel St Enter the street number of home address: 12
Enter the street name of home address: Apple Ave
Enter the email address: ok@gmail.com
Enter the phone number: 420400000
Work address: 12 Apple Ave, Wollongong 2500, NSW
Home address: 11 Steel St, Wollongong 2500, NSW
Email: ok@gmail.com
Phone Number: 420400000
Submission requirements:
1. Put all your .java files into a folder. Compress this folder into .zip file and submit it via the link Assignment 1 Submission on Moodle.
2. Submission via email is not acceptable without permission.
3. Enquiries about the marks can only be made within a maximum of 1 week after the assignment results are published. After 1 week the marks cannot be changed.
Mark deductions: late submission, compilation errors, incorrect result, program is not up to spec, poor comments, poor indentation, meaningless identifiers, required numeric constants are not defined, the program uses approaches which has not been covered in the lectures. The deductions here are merely a guide. Marks may also be deducted for other mistakes and poor practices.
END OF THE ASSIGNMENT