Question

Create a class in Java with instance variables to hold the name, street address, city, and...

Create a class in Java with instance variables to hold the name, street address, city, and state for a user. These instance variables should be private. You should enter the name and address in the nameAddress method. You should enter the city and state in the cityState method. In the main method, print the complete address using the method printAddress. You should not use the static keyword except for the main method. Your output should be similar to the output shown below:

Example output:

Please enter the name

Fred Flintstone

Please enter the the address for Fred Flintstone

123 Rock Center Lane

Please enter the city for Fred Flintstone

Bedrock

Please enter the state for Fred Flintstone

GA

Fred Flintstone

123 Rock Center Lane

Bedrock, GA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
class Address
{
private String name;
private String address;
private String city;
private String state;
public void nameAddress()
{
Scanner s = new Scanner(System.in);
System.out.println("Please enter the name");
name=s.nextLine();
System.out.println("Please enter the the address for "+name);
address=s.nextLine();
}
public void cityState()
{
Scanner s = new Scanner(System.in);
System.out.println("Please enter the city for "+name);
city=s.nextLine();
System.out.println("Please enter the state for "+name);
state=s.nextLine();
}
public void printAddress()
{
System.out.println(name);
System.out.println(address);
System.out.println(city+", "+state);
}
public static void main(String[] args)
{
Address m = new Address();
m.nameAddress();
m.cityState();
m.printAddress();
}
}

input Please enter the name Fred Flintstone Please enter the the address for Fred Flintstone 123 Rock Center Lane Please enter the city for Fred Flintstone Bedrock Please enter the state for Fred Flintstone GA Fred Flintstone 123 Rock Center Lane Bedrock, GA . . .Program finished with exit code 0 Press ENTER to exit console.|

Add a comment
Know the answer?
Add Answer to:
Create a class in Java with instance variables to hold the name, street address, city, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In the Python interpreter window (aka IDLE), create five variables: street, number, city, state, zip. street...

    In the Python interpreter window (aka IDLE), create five variables: street, number, city, state, zip. street will hold your street name, number will hold your house number, city will hold your city, state will hold your state, and zipcode will hold your zip code. Print your address in the standard format for mailing addresses. Your print statements will utilize the variable names. Take a screenshot of the IDLE window. It should show your assignment of values to the variables, your...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • How to write a program that create a car class with: instance variables name and mpg...

    How to write a program that create a car class with: instance variables name and mpg (make public) No need for a main() method In a separate file, create a CompareCars class with a main()method create 2 instances of car using new set the name and mpg for each instance variables are public, so use the name an mpg to access the instance variables compare the fuel efficiency of your 2 cars and print out which is more efficient to...

  • in java (Bank Account) Write a program that inputs in the full name, street address, city, state, zip code, and social...

    in java (Bank Account) Write a program that inputs in the full name, street address, city, state, zip code, and social security for new account. In addition, it inputs in the initial account balance and allows the owner of the new account to make one withdrawal followed by one deposit. Your program should calculate the ending balancing after the withdrawal and deposit made by the account holder. It should also find the count of each one of these bills $78,...

  • signature 1. Create a new NetBeans Java project. The name of the project has to be...

    signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...

  • In Java: DATA TYPE CLASS Create one data type class Account_yourLastName that hold the information of...

    In Java: DATA TYPE CLASS Create one data type class Account_yourLastName that hold the information of an account such as accountNumber (String), name (String), address (String), balance (float), interestRate(float) and beside the no-argument constructor, parameterized constructor, the class has method openNewAccount, method checkCurrentBalance, method deposit, method withdrawal, method changeInterestRate REQUIREMENT - DRIVER CLASS Provide the application for the Bank Service that first displays the following menu to allow users to select one task to work on. After finishing one task,...

  • Write a class named Address that takes four strings that represent the fields of any address...

    Write a class named Address that takes four strings that represent the fields of any address as private member variables. For example: Street = "456 mission street" City = "Hayward" State = "CA" zip code = 94542 To display any address you use the cout << operator in the main function to display any "Address" object created. You should overload the operator to work with the Address class. The class also has another member function named "displayAddress" that prints the...

  • JAVA help Create a class Individual, which has: Instance variables for name and phone number of...

    JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...

  • Introduction to computer class, Java programming through eclipse: Ue the following criteria to create the code:...

    Introduction to computer class, Java programming through eclipse: Ue the following criteria to create the code: SALARY Input first and last name - Output the names last, first in your output - Make the federal withholding rate a constant 20% (not an input value) No state tax Generate two new values: regular pay and overtime pay - 40 hours workedor less - Regular pay is pay rate * hours worked - Overtime pay is 0 Otherwise - Regular pay is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT