The objectives of this question are
Write a java class called ComboLock with the following attributes and behaviours:
The objectives of this question are
(i) x = 2.0; (ii) s = "2"; y = x + x; t = s + s;
John knows that the distance between two points (x1, y1) and (x2, y2) on a plane is given by the following formula
He wrote the following program to calculate the distance between two points given by the user during run-time. However, the program was not able to compile successfully in BlueJ.
1. public class ComputeDistance
2. {
3. public static void main(String[] args)
4. {
5. Scanner console = new Scanner(System.in);
6. int x1, y1, x2, y2;
7. double distance;
8. System.out.print("Enter the coordinate of the first point: );
9. x1 = console.nextInt();
10. y1 = console.nextInt();
11. System.out.print("Enter the coordinate of the second point: ");
12. x2 = console.nextInt();
13. y2 = console.nextInt();
14. d = Math.sqrt((x2-x1)(x2-x1) + (y2-y1)(y2-y1));
15. System.out.println("Point 1 : (" + x1 + ", " + y1 + ")");
16. System.out.println("Point 2 : (" + x2 + ", " + y2 + ")");
17. System.out.println("Distance : " + distance);
18. }
Identify the compilation errors in the program by completing the table below:
Explain clearly what happens when the user enters (1, 1) as the coordinate for the first point and (1.5, 2) as the second point (only the number without the brackets and commas).
Modify the program so that it is able to accept real numbers as the input data for the coordinates. Modify also the program so that the distance printed shows only 2 decimal places. Submit the program listing and a screenshot of output showing one run of the program after all correction and modification are done.
The objectives of this question are
A military format time is to indicate the time in a 24-hour clock from 0000 (12 mid-night) to 2359 (1 minute before 12 mid-night).
Write a program that reads two time in military format where the first time is earlier than the second time and prints the number of hours and minutes between the two times. E.g. first time: 0900 second time: 1730 duration: 8 hours 30 minutes
You are not allowed to make use of any Java pre-defined classes and methods. You are not required to perform data validation here as it is to be done in part (c) below. Your program output must show clearly the time entered and the duration computed (e.g. There is 8 hours 30 minutes from 0900 to 1730).
Submit your program listing together with screenshot showing one run of your program output. Your screenshot must show your name as part of the program output.
Modify your program in part (a) above so that it is able to calculate the time difference if the first time is bigger than second time.
E.g. first time: 1730 second time: 0900 duration: 15 hours 30 minutes
Submit your program listing with the changes clearly highlighted. Submit also screenshot of two runs of your program output. Your screenshot must show your name as part of the program output.
Modify your program in part (b) to perform input validation. Display an error message to indicate the type of error the input value has and repeat the input process until a valid input is entered. You should define a method to validate the input data.
The objectives of this question are
A pet shop gives a discount to its customers if they purchase one or more pets and at least five other items. The discount is equal to 20% of the cost of the other items except the pets. You are required to develop a simple application for the pet shop to manage the bill for its customers. The system should allow the user to perform the following tasks repeatedly until he quits the program:
Your program should include the following:
The main() method to perform the following:
The method displayMenu() to display the following menu:
MENU
A. Enter input
B. List items purchased
C. Print discount
D. Display bill
E. Check out
F. Exit
The method enterInput() that allows the user to enter the price and the indicator of whether it is a pet for each item in the purchases. This method should receive as the parameters the two arrays created in the main() method mentioned above and an integer number that keeps track of the number of items purchased. It prompts and reads the input data from the user and adds it to the arrays. Use a price of -1 as the sentinel. The method should return the number of items purchased.
The method listItems() to display the information of the purchases (prices for each item and whether it is a pet). The output should be nicely formatted for easy reading.
The method calculateDiscount() to calculate and return the discount that the customer is entitled to base on his purchases.
The method displayBill() to display the bill for the customer. The bill should include the information of the purchases (prices for each item and whether it is a pet), the total price before discount, the discount and the final bill after discount. The output should be nicely formatted for easy reading.
Note: the "Check out" option sets the no of item purchases to 0.