Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8413299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:53:37+00:00 2026-06-10T00:53:37+00:00

Im studying for an upcoming exam and am working at sample problems, in particular

  • 0

Im studying for an upcoming exam and am working at sample problems, in particular the following one:

Add to class Point below an instance method called midpoint which returns an object of type Point representing the midpoint of two points, where one of the points is supplied as a parameter and the other is the current point (i.e. the point provided by the local instance variables). Note that midpoint returns a new Point object. Making good use of class Point, write a program which reads two points and prints their midpoint. The input consists of two lines where each line contains the x- and y-coordinates of a point. An example of input/output follows, with input indicated by bolding:

Enter two points
2.1 3.2
3.0 2.8
The midpoint is (2.55,3.0)

My code for the point class is as follows and seems to be ok (feel free to point out any errors or improvements):

 class Point {


private double x, y; // coordinates


Point(double x0, double y0){ // all-args constructor

    x = x0; y = y0;

}



Point(){}; // no-args constructor (defaults apply)



void get() { 

    x = Console.readDouble(); 

    y = Console.readDouble();

}

public Point midPoint(Point p) {
     double mx = (p.x + x)/2;
     double my = (p.y + y)/2;
     return new Point(mx,my);
}


public String toString() 
{ 

    return "(" + x + "," + y + ")";
}

}

And where I run into trouble is in actually using my midPoint method in the below code, any advice is appreciated.

import java.util.Scanner;
import java.io.*;

class Midpoint extends Point
{
public static void main (String[] args ) {

    Scanner scanner = new Scanner(System.in);

    System.out.println("Please enter two points:");
    double x1 = scanner.nextDouble();
    double y1 = scanner.nextDouble();
    double x2 = scanner.nextDouble();
    double y2 = scanner.nextDouble();

    Point p1 = new Point(x1, y1);
    Point p2 = new Point(x2, y2);



    p1.get();
    return midPoint(p2);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:53:38+00:00Added an answer on June 10, 2026 at 12:53 am

    The call to get() method seems unnecessary.

    Secondly, call your midPoint using an object(as per the requirement in the question). Hence, it should be:

    p1.midPoint(p2);
    

    Finally, since that method returns a Point type, ensure you catch what is returned.

    Point p3 = p1.midPoint(p2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am studying for an upcoming exam and working through sample problems and am stuck
While studying for a Functional Programming exam, I came across the following questions from
While studying for a Functional Programming exam, I came across the following question from
In studying actionscript 3's graphics class, I've come across the undocumented drawRoundRectComplex() method. It's
While studying for the Zend PHP Exam I came across the following contradicting information:
While studying C++ (and C) I had some particular doubts regarding the working of
Studying MS Exam 70-536 .Net Foundation I've got to Chapter 11 Application Security and
While studying about JMX, I have seen one of the important feature of it
In studying for the OCP Java Programmer Exam, I was slightly surprised to see
I'm studying for upcoming interviews and have encountered this question several times (written verbatim)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.