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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
1 The Java statement to divide num2 by num1 and store the result in answer is java answer num2 num1 ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started