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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:50:22+00:00 2026-06-14T01:50:22+00:00

This is my class that everything is done in: import java.awt.Color; import java.awt.Graphics; //This

  • 0

This is my class that everything is done in:

import java.awt.Color;
import java.awt.Graphics;

//This class will not compile until all 
//abstract Locatable methods have been implemented
public class Block implements Locatable
{
    //instance variables
    private int xPos;
    private int yPos;
    private int width;
    private int height;
    private Color color;

    //constructors
    public Block () {}

    public Block(int x,int y,int w,int h)
    {
        xPos = x;
        yPos = y;
        width = w;
        height = h;
    }

    public Block(int x,int y,int w,int h, Color c)
    {
        xPos = x;
        yPos = y;
        width = w;
        height = h;
        color = c;
    }

    //set methods
    public void setBlock(int x, int y, int w, int h)
    {
        xPos = x;
        yPos = y;
        width = w;
        height = h;
    }

    public void setBlock(int x, int y, int w, int h, Color c)
    {
        xPos = x;
        yPos = y;
        width = w;
        height = h;
        color = c;
    }

    public void draw(Graphics window)
    {
      window.setColor(color);
      window.fillRect(getX(), getY(), getWidth(), getHeight());
    }

    //get methods
    public int getWidth()
    {
       return width;
    }

    public int getHeight()
    {
       return height;
    }

    //toString
    public String toString()
    {
       String complete = getX() + " " + getY() + " " + getWidth() + " " + getHeight() + " java.awt.Color[r=" +     color.getRed() + ", g=" + color.getGreen() + ", b=" + color.getBlue() + "]";
       return complete;
    }
}

and here is my interface class that has to be implemented:

public interface Locatable
{
    public void setPos( int x, int y);
    public void setX( int x );
    public void setY( int y );

    public int getX();
    public int getY();
}

I haven’t had formal instruction yet on interfaces/implementations and thus, am not sure what needs to be done to get the first class to run right

  • 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-14T01:50:23+00:00Added an answer on June 14, 2026 at 1:50 am

    When you implementing an interface, you have to implement all the methods declared in that interface.
    Interface is a contract that your implementing class must full fill.in your case your implementing class Block should implement the following methods to full fill the contract.

    public void setPos( int x, int y);
    public void setX( int x );
    public void setY( int y );
    
    public int getX();
    public int getY();
    
    public class Block implements Locatable {
         public void setPos( int x, int y){
           // your implementatioon code
          }
          public void setX( int x ) {
    
    
            // your implementatioon code
          }
         public void setY( int y ){
    
     // your implementatioon code
    }
    public int getX(){
    
    
     // your implementatioon code
     return (an int value);
    }
    public int getY(){
    
    
     // your implementatioon code
      return (an int value);
    }
    
    }
    

    EDIT: for your NPE from the comments.

    you never initialized your Color object.and trying to call a method on its refrence in your toString method.

    private Color color;
    

    initialize it like this

     private Color color = new Color(any of the Color constructors);
    

    check here for Color API

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class that looks like this: class A { public: class variables_map vm
I wrote this class that draws a animated progress with a circle (it draws
I have this class that have a function to load other classes and create
I've written this class that returns feed updates, but am thinking it can be
I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
I have this class that has many class members, and a lot of different
I have a class that contains this class method: def self.get_event_record(row, participant) event =
Assume I have a class that looks like this: class Sample { public string
I have a Handler class that looks like this: class Handler{ public $group; public
I've created a class that extends Application. This class starts a service when the

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.