Question

In: Computer Science

Create java class with name MyClass1 Instructions for MyClass1 For this portion of the assignment you...

Create java class with name MyClass1

Instructions for MyClass1

For this portion of the assignment you will need to create a java class of your own to model some objects in the real world or your own imagination. your classes should have at least three instances variables, accessor and mutator methods for each of those instance variables, one constructor method of any type, as well as an overridden toString method that will display every field value as part of a String. Use meaningful identifiers for the name of  class.

Demonstrate that your class work appropriately by creating instances of each in the MainClass class which contains a main method

Solutions

Expert Solution

class MyClass {
   private String name;
   private String Id;
   private String address;

   public MyClass(String aName, String aId, String aAddress) {
       super();
       name = aName;
       Id = aId;
       address = aAddress;
   }

   public String getName() {
       return name;
   }

   public void setName(String aName) {
       name = aName;
   }

   public String getId() {
       return Id;
   }

   public void setId(String aId) {
       Id = aId;
   }

   public String getAddress() {
       return address;
   }

   public void setAddress(String aAddress) {
       address = aAddress;
   }

   @Override
   public String toString() {
       return "MyClass [name=" + name + ", Id=" + Id + ", address=" + address + "]";
   }

}

public class MainClass {
   public static void main(String[] args) {
       MyClass m1 = new MyClass("Uday", "1", "Hyderabad");
       MyClass m2 = new MyClass("Koteswari", "2", "Secundrabad");
       System.out.println(m1);
       System.out.println(m2);
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Create a java class with name Cat. Instructions for Cat class: This class is modeled after...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after a Cat. You should have instance variables as follows: The Cat’s name The number of mice caught by the Cat. Whether or not the Cat is secretly plotting to kill you Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after a BaseballPlayer and will contain methods to calculate various statistics based on the stats of a player. For this class, you will want to use a static variable for storing a DecimalFormat object. See the API document for the BaseballPlayer class for a list of methods you will write. API Document Constructors: Identifier: BaseballPlayer(String name, int number, int singles, int doubles, int triples, int...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods designed to perform simple conversions. Specifically, you will be writing methods to convert temperature between Fahrenheit and Celsius and length between meters and inches and practicing overloading methods. See the API document for the Conversion class for a list of the methods you will write. Also, because all of the methods of the Conversion class will be static, you should ensure that it is...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
java For this assignment, you will create a Time class that holds an hour value and...
java For this assignment, you will create a Time class that holds an hour value and a minute value to represent a time. We will be using "military time", so 12:01 AM is 0001 and 1 PM is 1300. For this assignment, you may assume valid military times range from 0000 to 2359. Valid standard times range from 12:00 AM to 11:59 PM. In previous assignments, we had a requirement that your class be named Main. In this assignment, the...
Java: Create a class and name it MyArray and implement following method. * NOTE: if you...
Java: Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items in the...
Create a Netbeans project with a Java main class. (It does not matter what you name...
Create a Netbeans project with a Java main class. (It does not matter what you name your project or class.) Your Java main class will have a main method and a method named "subtractTwoNumbers()". Your subtractTwoNumbers() method should require three integers to be sent from the main method. The second and third numbers should be subtracted from the first number. The answer should be returned to the main method and then displayed on the screen. Your main() method will prove...
Using JAVA: This assignment is about aggregation and class collaboration. You will create several Classes that...
Using JAVA: This assignment is about aggregation and class collaboration. You will create several Classes that will be part of an overall class named InstrumentDisplay. The classes are FuelGage, Odometer, MilesSinceLastGas, and CruisingRange. The FuelGage should assume a 15 gallon tank of gasoline and an average consumption of 1 gallon every 28 miles. It should increment in 1 gallon steps when you "add gas to the tank". It should decrement by 1 every 28 miles. It should display its current...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
Create a Java class with the name (identifier) MyProgram and place it in the Questions package....
Create a Java class with the name (identifier) MyProgram and place it in the Questions package. You will need to create a main method for this class and place all of your code inside of that method. Your program should complete the following steps: - Prompt the user to enter a name for a Student. - Use the Scanner class to read in the user input and store the result in a variable. - Use the Random class to generate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT