How to figure out this one error? Table of Contents Search the TOC Starting Out
ID: 3575896 • Letter: H
Question
How to figure out this one error?
Table of Contents Search the TOC Starting Out With JAVA E MPL WARMUP Chapter 1 Introduction to Computers and Ja Chapter 2 Java Fundamentals Chapter 3 Decision Structures Chapter 4 Loops and F E Chapter 5 Methods E Chapter 5 A First Look at Classes Chapter 7 Arrays and the ArrayLIst Class Chapter 8 A Second Look at Classes and O E Chapter 9 Text Processing and More about Chapter 10 Inheritance 0.1 What Is Inheritance? 10.2 Calling the Superclass constructor H 0.3 overriding Superclass Methods 10.4 Protected Members 0.5 Chains of Inheritance 0.6 The Object Class 0.7 Polymorphism 10 a Abstract classes and Abstract Met 0.9 Intertaces 0.10 Common Errors to Avoid El Programming Projects X 71124. 23244 22242 23243 Chapter 11 Exceptions and Advanced File l Chapter 12 A First Look at GUI Applications Chapter 13 Advanced GUI Applications Chapter 14 Applets and More Chapter 15 Creating GUI Applications with J Chapter 16 Recursion Chapter 17 Databases MPL Extra: Other Advanced Topics www turing UNIVERS ITYAT ALBANY We value your feedback! Please take a 5-minute online survey to give us your input on how we can improve MyProgrammingLab. OPREV NEXT O Workbench Exercise 71125 WORK AREA RESULTS COMPILER ERROR MESSAGES publ should be decl lsPe public class clsEerson 1 publ cls Per 3 //private field 4 private String name- address telephone- 6 publ name- 9 add 10 12 13 //conat ructor methoda 15 public cl Person String name, String address, String telephone 16 17 th 18 name 18 th18 add Yeaa 19 th 20 21 22 //AcceBao 23 public String getName 24 2S 26 27 28 //Acce 330M for addre 29 publ ng get Addr 30 31 return address 32 33 34 //Acce lephone numbe 3S publ String getNumbe 36 37 return telephone 38 39 40 //Mutator f 41 public void setName (String name 42 43 13 name 44Explanation / Answer
I think the error occured because the name of the file and the class name should be excatly same.Otherwise we will get this error.
ClsPerson.java
public class ClsPerson {
//Declaring instance variables
private String name;
private String address;
private String telephone;
//Zero Argumented constructor
public ClsPerson() {
super();
name="";
address="";
telephone="";
}
//Parameterized constructor
public ClsPerson(String name, String address, String telephone) {
super();
this.name = name;
this.address = address;
this.telephone = telephone;
}
//Setters and getters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
//toString() method is used to display the contents of an object inside it
@Override
public String toString() {
return "ClsPerson# Name=" + name + " Address=" + address
+ " Telephone=" + telephone;
}
}
______________________
Driver.java
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
//Declaring variables
String name,address,mobileno;
//Scanner class object is sued to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//Getting the name entered by the user
System.out.print("Enter Name :");
name=sc.nextLine();
//Getting the address entered by the user
System.out.print("Enter address :");
address=sc.nextLine();
//Getting the telephone number entered by the user
System.out.print("Enter Telephone No :");
mobileno=sc.next();
//Creating the ClaPerson class Object
ClsPerson cp=new ClsPerson(name, address, mobileno);
//Displaying the contents of the ClsObejct
System.out.println(cp.toString());
}
}
_________________________
Output:
Enter Name :Kane Williams
Enter address :Park street,New York
Enter Telephone No : (734)5551212
ClsPerson#
Name=Kane Williams
Address=Park street,New York
Telephone=(734)5551212
_______Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.