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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:05:38+00:00 2026-05-30T06:05:38+00:00

import cs1.Keyboard; import java.util.Scanner; class Person { private String name; private String persnr; private

  • 0
import cs1.Keyboard;
import java.util.Scanner;
class Person 
{
    private String name;
    private String persnr;
    private String adress;
    private int age;

    public Person(String _name, String _persnr, String _adress, int _age) 
    {
        name = name;
        persnr = persnr;
        adress = adress;
        age = age;
    }

    public void byterNamn(String _name)
    {
        name = _name;
    }

    public void byterAdress(String _adress)
    {
        adress = _adress;
    }

    public void fyllerAr()
    {
        age = age + 1;
    }

    public String hamtaNamn()
    {
        return name;
    }

    public String hamtaPersonnmmer()
    {
        return persnr;
    }

    public String hamtaAdress()
    {
        return adress;
    }

    public int hamtaAlder()
    {
        return age;
    }

    public String toString()
    {
    String _toString;
    _toString = "Namn: " + name + "\nÅlder: " + age;
    _toString = _toString +  "\nPersonnummer: " + persnr + "\nAdress: " + adress;
    return _toString;
    }

     public p1()
     {
       System.out.print("namn: ");
        name = Keyboard.readString();    

        System.out.print( "adress: " );
        String adress = Keyboard.readString();

        System.out.print( "ålder: " );
        Integer age = new Integer(); 
        age.parseInt(Keyboard.readint());

        System.out.print( "personnummer: " );
        String persnr = Keyboard.readString();

     }
     public p2()
     {
       System.out.print("namn: ");
        name = Keyboard.readString();    

        System.out.print( "adress: " );
        String adress = Keyboard.readString();

        System.out.print( "ålder: " );
        Integer age = new Integer(); 
        age.parseInt(Keyboard.readint());

        System.out.print( "personnummer: " );
        String persnr = Keyboard.readString();
     }

    public static void main(String[] args) 
    {
        String name = Keyboard.readString();
        String persnr = Keyboard.readString();
        String adress = Keyboard.readString();
        int age = Keyboard.readint(); 
        Person p1 = new Person(name, age, adress, personnummer);

        String name = Keyboard.readString();
        String persnr = Keyboard.readString();
        String adress = Keyboard.readString();
        int age = Keyboard.readint(); 
        Person p2 = new Person(name, age, adress, personnummer);

    }
}

hello.
I try to do so it is 2 people. where you should enter the age, name, address of both people and then print it after you enter what you want when the program runs. and i wondering how do i do return on public p1() and public p2() so i can do it. Or is it a easier way to do it?

  • 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-05-30T06:05:39+00:00Added an answer on May 30, 2026 at 6:05 am

    This code does not compile. public p1() and public p2() are not valid method declarations. You must at least add a method return type after the public and before the method name, for example:

    public Person p1()
    

    Then I guess what you want to do is return a Person object from each of those two methods. Inside the method you must create a new Person object and then return it from the method:

    return new Person(name, persnr, adress, age);
    

    See Defining Methods and Returning a Value from a Method in Oracle’s Java Tutorials.

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

Sidebar

Related Questions

import java.util.Scanner; public class Test { private static int decimalNum = 0; private static
import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class Filereader { public static void main(String[]
import java.util.Scanner; class Practice { public static void main(String args[]) { System.out.println(Enter the number
import java.util.Scanner; public class smth { Scanner input = new Scanner(System.in); int array[]={}; }
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateDemo { public static void main(String[]
import java.util.*; public class Test { public static void main(String[] args) { List db
import java.util.ArrayList; import java.util.Random; public class Generator{ //9352141NTBG1223 public static void main(String[] args) {
import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) {
import java.util.*; public class Test { public static void main(String[] args) { Map<String,String> map
import java.util.*; import java.io.*; import java.util.regex.*; class ZiggyTest2 extends Thread{ String sa; public ZiggyTest2(String

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.