The following variables have been declared: int num1=17; double num2=46.0; float answer; Write the Java statement to
Question:
The following variables have been declared: int num1=17; double num2=46.0; float answer; Write the Java statement to divide num2 by num1 and store the correct result in answer.
View keyboard shortcuts
2. Write a CLASS method named calcSales() that takes two arguments, a quantity and a price. Use appropriate data types for each of these arguments. The method calculates and returns the sale amount. The sale amount is calculated using the quantity, the price, and a sales tax of 4.5%.
3. Write a main that calls the above method and displays the result with an appropriate label.
4. Create a Java instance class named Rectangle that has two integer fields named length and width. Include two constructors: a default constructor to initialize each of the fields to 1 and a second constructor that takes two arguments. Define a getter method for each of the fields.
5. Write the Java statement to create an instance of a Rectangle of the default size.
6. Write the Java statement to create an instance of a Rectangle with a width of 4 and a length of 8.
7. Write the Java code to calculate and display the area of the Rectangle instantiated above using only the methods of the class. Include an appropriate label for your output.