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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:40:34+00:00 2026-06-15T13:40:34+00:00

I am new to programming and I have an assignment to write a class

  • 0

I am new to programming and I have an assignment to write a class called Names. In my main method, I want to read in the entire name and pass it to my Names constructor. However, I keep getting type mismatch errors when passing the method data. What am I doing wrong??

import java.util.Scanner;
public class Names {
String first, middle, last;
    /**
     * @param args
     */
    public Names(){

    }
    public Names(String first, String middle, String last){
        first = this.first;
        middle = this.middle;
        last = this.last;
    }

    //returns the first name
    public String getFirst(){
        return first;
    }

    //returns the middle name
    public String getMiddle(){
        return middle;
    }
    //returns the last name
    public String getLast(){
        return last;
    }
    // Returns a string containing the person's full name in order,
    public String firstMiddleLast(){
        String ret = first + " " + middle + " " + last;
        return ret;
    }
    public String lastFirstMiddle(){
        String ret = last + ", " + first + " " + middle;
        return ret;
    }
    public boolean equals(Names otherName){
        if (first.equalsIgnoreCase(otherName.first) || middle.equalsIgnoreCase(otherName.middle) 
                || last.equalsIgnoreCase(otherName.last))
            return true;
        else
            return false;
    }
    public String initials(){
        String retVal = first.substring(0) + "." + middle.substring(0) + "." + last.substring(0) + ".";
        return retVal.toUpperCase();
    }
    public int length(){
        String wholeName = (first+middle+last);
        int retVal = wholeName.length();
        return retVal;
    }
    public static void main(String[] args) {
        Names person1 = new Names();
        Names person2 = new Names();
        Scanner scan = new Scanner(System.in);

        System.out.println("Enter First Name: ");
        person1.first = scan.next();

    }

}
  • 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-15T13:40:36+00:00Added an answer on June 15, 2026 at 1:40 pm

    Line #60 when I try to pass the String first to the constructor
    Names(String first, String middle, String last)

    I dont see any compile time error’s in your posted code but your code should be like this:

        System.out.println("Enter First Name: ");
        String firstname = scan.next();
         System.out.println("Enter Middle Name: ");
        String middlename = scan.next();
        System.out.println("Enter Last Name: ");
        String lastname = scan.next();
    
        Names person1 =new Names(firstname, middlename, lastname);
    

    And as noted by others your constructor declaration is not valid.

     public Names(String first, String middle, String last){
            this.first = first;
            this.middle = middle;
            this.last = last;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment in my C programming class to write a program to
I'm new to PHP programming and have poor knowledge about it, but I want
I am new to programming. I have been trying to write a function in
I am new to programming.I have seen this code.returning a derived class object to
I am new to the Go programming language and I have an assignment to
For our programming assignment we have to ask the user for a Region Name
I have an assignment from my programming class, which is very poorly worded... The
I have an assignment in a C programming class to output a poem with
I'm VERY new to android programming, so please forgive. I have an assignment in
i am new kernel programming.i have been trying to load this driver program for

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.