Knowee
Questions
Features
Study Tools

Write A Java Program to define a class Mobile having 3 members manufacture namebrandpriceDefine 3 constructors1. by default "apple" "i5" "125000"2 .use to enter 3 information3. copy constructor4. only parameter (name,price )and model is same as brand name create the objects for the suitable constructors and use toString() method to display.

Question

Write A Java Program to define a class Mobile having 3 members manufacture namebrandpriceDefine 3 constructors1. by default "apple" "i5" "125000"2 .use to enter 3 information3. copy constructor4. only parameter (name,price )and model is same as brand name create the objects for the suitable constructors and use toString() method to display.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple Java program that defines a class Mobile with three members: manufacturer, brand, and price. It also includes three constructors as per your requirements.

public class Mobile {
    String manufacturer;
    String brand;
    int price;

    // Default constructor
    public Mobile() {
        this.manufacturer = "Apple";
        this.brand = "i5";
        this.price = 125000;
    }

    // Constructor to enter 3 information
    public Mobile(String manufacturer, String brand, int price) {
        this.manufacturer = manufacturer;
        this.brand = brand;
        this.price = price;
    }

    // Copy constructor
    public Mobile(Mobile m) {
        this.manufacturer = m.manufacturer;
        this.brand = m.brand;
        this.price = m.price;
    }

    // Constructor with only name and price parameters
    public Mobile(String name, int price) {
        this.manufacturer = name;
        this.brand = name;
        this.price = price;
    }

    // toString method to display
    public String toString() {
        return "Manufacturer: " + this.manufacturer + ", Brand: " + this.brand + ", Price: " + this.price;
    }

    public static void main(String[] args) {
        Mobile m1 = new Mobile();
        Mobile m2 = new Mobile("Samsung", "Galaxy", 50000);
        Mobile m3 = new Mobile(m2);
        Mobile m4 = new Mobile("Nokia", 30000);

        System.out.println(m1.toString());
        System.out.println(m2.toString());
        System.out.println(m3.toString());
        System.out.println(m4.toString());
    }
}

In the main method, we create four Mobile objects using the four different constructors and print their details using the toString method.

This problem has been solved

Similar Questions

Sarah got confused to creating the constructor. Write a Java application to help Sarah to do this.Type(Class)AttributesMethodsResponsibilitiesStudentint studentIdString studentNameString studentAddressString collegeNameInclude the getters and setters method for all the attributes.  Student Include a public parametrized constructor of four arguments in the following order - studentId, studentName, studentAddress, and collegeName to initialize the values for the Student objectIf student belongs to other college, give input as 'no/NO' and get college name from the user and create student object with 4-argument constructor to initialize all the values.  Student Include a public parametrized constructor of three arguments in the following order - studentId, studentName, studentAddress, and collegeName should be "NIT" to initialize the values for the Student objectIf student belongs to NIT, give input as 'yes/YES' and skip input for the attribute collegeName and create student object with 3-argument constructor to initilze the values for studentId, studentName and studentAddress and  collegeName as "NIT".  Note: The class and methods should be declared as public and all the attributes should be declared as private.  In the UserInterface class, write the main method to test the application.Assume most of the students are from "NIT" college. So user has to give input whether the student is from NIT or not.Instead of Yes / No, if user enters different input then display 'Wrong Input' and get the input again. Note:In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.Ensure to follow the object-oriented specifications provided in the question description.Ensure to provide the names for classes, attributes, and methods as specified in the question description.Adhere to the code template, if provided.Please do not use System.exit(0) to terminate the program. Sample Input 1:Enter Student's Id:12Enter Student's Name:JohnEnter Student's address:ChennaiWhether the student is from NIT(Yes/No):NOEnter the college name:SVS Sample Output 1:Student id:12Student name:JohnAddress:ChennaiCollege name:SVS Sample Input 2:Enter Student's Id:43Enter Student's Name:TomEnter Student's address:CoimbatoreWhether the student is from NIT(Yes/No):yWrong InputWhether the student is from NIT(Yes/No):yes Sample Output 2:Student id:43Student name:TomAddress:CoimbatoreCollege name:NIT

write a java program to define a class Item having item namepricequantityfind the total cost of the itemuse accept method to get the data from the user and toString method to display the detailscreate two objects and display the name of the item which is ordered more quantitydisplay total amount of items purchased.edited 10:37 AM

[25 points] Write a Java class named Employee such that the class contains threeattributes empName, salary, and departmentName. You should be able to createobjects of this class by supplying values to any one, two, or all three of the attributes. Ifno value is supplied during the object creation, the attributes should be initialized withsome default values. You are expected to use 'this' keyword to achieve the result. Discussthe ways in which you can change or reset the attribute values of the objects created.Write appropriate mutator methods that store values in these fields and accessormethods that return the values in these fields. Once you have written the class, write aseparate program that creates three Employee objects to hold the following data:Employee Name Department Salary---------------------------------------------------------------------Susan Meyers Accounting 5000.00Mark Jones IT 8375.00Joy Rogers Manufacturing 6380.00---------------------------------------------------------------------The program should store this data in the three objects and then display the data for eachemployee on the screen

Observe the below code :abstract public class Phone  {         private String model;         private double cost;}public class SmartPhone extends Phone{          private String cameraDetails;}Which of the below are valid declarations ?Select one or more:Phone phoneObj = new SmartPhone();SmartPhone phoneObj = new SmartPhone();SmartPhone phoneObj = new Phone();SmartPhone phoneObj = new Phone();Phone ph = (Phone)phoneObj;Phone phoneObj = new Phone();Phone phoneObj = new SmartPhone();SmartPhone smartph = (SmartPhone) phoneObj

. Design a class for a student who has details, such as id, name and email. The class has method Show() which prints the details of the student. Create one object of the class and initialize the object with details at the time of initialization. Create another object and give the default detail to the object. Perform constructor overloading and method overloading in the class.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.