● calcTotal() method should take the two marks entered and return their sum. Also define two constructors:
● A default constructor that takes no parameters and initializes the values to zeros and null.
● A constructor that takes the three variables and sets them as the values of the appropriate fields.
Input#
Name of the student and the marks obtained in the first and second tests
Output#
Sum of both marks
Sample Input#
Student student = new Student(“Jack”, 60, 70);
Sample Output# getMarks(1) => 60 getMarks(2) => 70 calcTotal() => 130.0
Part of solution
class Student {
// Define private fields here
public Student() {
// Write definition here
}
public Student(String name, double mark1, double mark2) {
// Write definition here
}
public double getMarks(int markNumber) {
// Write definition here
return 0;
}
public double calcTotal() {
// Write definition here
double totalMarks = 0;
return totalMarks;
}
}
class Demo {
public static void main(String args[]) {
Student student = new Student(“Jack”, 60, 70);
System.out.println(student.calcTotal());
}
}
○ x( integer type)
○ y( integer type) ● methods:
○ default constructor that initializes the point at (0,0)(0, 0)(0,0)
○ parameterized constructor that takes input x and y and initializes the point to the respective coordinates.
○ float distance(), a method which calculates the distance of the point (represented by the object) from the origin, i.e. (0,0)(0, 0)(0,0)
○ float distance(x1, y1), a method which calculates the distance between the point represented by the class object and (x1,y1)(x1, y1)(x1,y1)
Sample Input#
Point p1 = new Point(5, 5);
Sample Output# distance() => 7.071 distance(2, 1) => 5.0
Part of the solution
import java.lang.Math;
class Point {
// Private fields
private int x;
private int y;
// Default Constructor
public Point() {
// Implement the function
}
// Parameterized Constructor
public Point(int x, int y) {
// Implement the function
}
public double distance() {
// Implement the function
return 0;
}
public double distance(int x2, int y2) {
// Implement the function
return 0;
}
}
class Demo {
public static void main(String args[]) {
Point p1 = new Point(5, 5);
System.out.println(p1.distance());
System.out.println(p1.distance(2, 1));
}
}
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more
Recent Comments