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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:43:13+00:00 2026-06-13T07:43:13+00:00

I’ve been working on Java homework. Here are my instructions: Interface Programming Assignment Create

  • 0

I’ve been working on Java homework. Here are my instructions:

Interface Programming Assignment

Create an interface named ISum. The interface should define 2 methods. The first method should take two integers as arguments and return their sum. The second method should take 2 strings as arguments and return their concatenation. The second method should be an overloaded version of the first one.

Define another interface named IAverage. The interface should define one method that takes 2 integer arguments and returns the average.

Create a class named Calculator that implements both the interfaces defined above. Your class MUST implement exception handling. Create a driver class that allows a user to call each of the methods in your class.

My work so far:

Main class:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Calculator calculatorObject = new Calculator();
        Scanner scannerObject = new Scanner(System.in);

        System.out.println("Enter 1 for integer or 2 for string");
        int test1 = scannerObject.nextInt();

        switch (test1){
            case 1: 
                System.out.println("Enter 1st number");
                int int1 = scannerObject.nextInt();

                System.out.println("Enter 2nd number");
                int int2 = scannerObject.nextInt();   

                System.out.println("Enter 1 for sum or 2 for average");
                int test2 = scannerObject.nextInt(); 

                switch (test2){
                    case 1: 
                        int sum = calculatorObject.intSum(int1,int2);
                        System.out.println("The sum is " + sum);
                        break;

                    case 2:
                        int avg = calculatorObject.intAvg(int1,int2);
                        System.out.println("The avg is " + avg);
                        break;

                    default:
                        System.out.println("You entered an invalid option");    
                        break;    
                }

                break; 

            case 2: 
                System.out.println("Enter 1st string");
                String string1 = scannerObject.nextLine();

                System.out.println("Enter 2nd number");
                String string2 = scannerObject.nextLine();   

                String stringConcat = calculatorObject.stringSum(string1,string2);
                System.out.println("The sum is " + stringConcat);
                break; 

            default:
                System.out.println("You entered an invalid option");    
                break;
        }
    }
} 

ISum interface:

public interface ISum {

    public void intSum();
    public void intAvg();

}

IAverage interface:

public interface IAverage {

    public void intAvg();

}

Calculate class:

abstract class Calculator implements IAverage, ISum { 

    public int intSum (int1,int2){
        int int1;
        int int2;
        int sum = int1 + int2;
        return sum;
    }
    
    public String stringSum (string1,string2){
        String string1;
        String string2;
        String stringConcat = string1.concat(string2);
        return stringConcat;
    }

    public int intAvg(int1,int2){
        int int1;
        int int2;
        int avg = (int1 + int2)/2;
        return avg;
    }
    
}
  • 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-13T07:43:14+00:00Added an answer on June 13, 2026 at 7:43 am

    you redeclare and reinitialize your parameter variables before using them, so they are blank by the time you touch them.

    For instance:

    public int intSum (int1,int2){
    
        int int1;
        int int2;
    
        int sum = int1 + int2;
    
        return sum;
    
    
    }
    

    In the first line, public int intSum (int1,int2){, thats you declaring int1 and int2 as method-local variables. You do not need to then do int int1; or int int2;. By including these lines you overwrite them with nothing. For the above method, you just need:

    public int intSum (int1,int2){
    
        int sum = int1 + int2;
    
        return sum;
    
    
    }
    

    Edit: derp, reading fail. you should also give the parameters a type, so

    public int intSum (int int1, int int2){
    
        int sum = int1 + int2;
    
        return sum;
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.