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 8974161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:37:09+00:00 2026-06-15T18:37:09+00:00

Background info: —————————————————————- public class Point { protected int x; protected int y; public

  • 0
Background info:
----------------------------------------------------------------
public class Point {

    protected int x;
    protected int y;

    public Point(){

        this.x = x;
        this.y = y;
    }

    public String toString(){

        return "" + x + " , " + y; 
    }
}
---------------------------------------------------------------
public class PointName extends Point {

    private String name;

    public PointName(String name, int x, int y){

        super();
        this.name = name;
    }

    public PointName() {
        // TODO Auto-generated constructor stub
    }


    public String toString(){

        return name + super.toString();

    }

}
------------------------------------------------------------------------

I want to create an application called closest point and in this class data is supplied from the standard input(keyboard). Then i want to supply 10 points (name given points) which will be stored in a vector. Then print them out. A bit more after this but im stuck in this stage as i dont know what to do. I welcome all possible solutions!!

MY SOLUTION SO FAR:

public class ClosestPoint {

    public static void main (String[] args){

        Scanner in = new Scanner(System.in);
        System.out.println("Write in the new point starting with name then x, y");

        String name = "";
        Integer x = 0;
        Integer y = 0;

        String nameGivenPoints[] = null; // List of points to create
        String line = in.nextLine(); // info from the board

        while(!line.endsWith("")){
        nameGivenPoints = line.split("\r\n\r");

        name = nameGivenPoints[0];
        x = Integer.parseInt(nameGivenPoints[1]);
        y = Integer.parseInt(nameGivenPoints[2]);

// Maybe a forloop here
        PointName tenDifferentPunkts = new PointName(name, x, y);
        System.out.println(tenDifferentPunkts.toString());
         line = in.nextLine();

                }   
        }
  • 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-15T18:37:11+00:00Added an answer on June 15, 2026 at 6:37 pm

    Try this:

    PointName.java:

    public class PointName extends java.awt.Point
    {
    
        private String name;
    
        public PointName(String name, int x, int y)
        {
            super(x,y);
            this.name = name;
        }
    
        public String toString()
        {
            return this.name + " : " + super.toString(); 
        }
    }
    

    ClosestPoint.java:

    import java.util.Scanner;
    import java.util.List;
    import java.util.ArrayList;
    
    public class ClosestPoint
    {
        public static void main (String[] args)
        {
    
            Scanner in = new Scanner(System.in);
            String line;
            boolean done=false;
            String error=null;
            List<PointName> points=new ArrayList<PointName>();
    
            do
            {
                System.out.println("Enter a new point in this format: name:x,y");
                line=in.nextLine();
                done=line.equals("");
                if(!done) //Empty line terminates the loop
                {
                    String [] parts=line.split(":");
                    if(parts.length==2)
                    {
                        String name=parts[0];
                        parts=parts[1].split(",");
                        if(parts.length==2)
                        {
                            try
                            {
                                PointName pn=new PointName(name,Integer.parseInt(parts[0]),Integer.parseInt(parts[1]));
                                points.add(pn);
                            }
                            catch(NumberFormatException ex)
                            {
                                error=ex.getMessage();
                            }
                        }else error="Invalid format";
                    }else error="Invalid format";
                }
                if(!done) done=error!=null; //If there was an error exit the loop
            }while(!done); //Keep going until something sets the done flag
            if(error!=null)
            {
                System.out.println("Error: "+error);
            }
            else
            {
                //The points are all stored in the points List object now - this just iterates through and prints them out
                System.out.println("Here are the points you entered:");
                for(PointName pn : points)
                {
                    System.out.println(pn.toString());
                }
            }
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background info: I'm using Microsoft Visual C# 2010 for this project. I want to
Background info I recently handed in an assigment for my class on algorithms and
Some background info: I am currently writing a bootloader in protected mode while learning
First I will give a little background info so this question isn't completely without
Some background info; LanguageResource is the base class LanguageTranslatorResource and LanguageEditorResource inherit from LanguageResource
Quick background info: of the three database tables that are relevant for this question,
Background info I am building a site which displays pictures to its users. This
I'm killing myself trying to solve this routing error. Some background info: I'm using
Usless Background Info Hello, all. This is my first post here, but I often
I am making a website with a voting system, for some background info, this

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.