-3

In this programme I have got the error symbol not found please solve my issue. I have check all the lines, but I found all are correct. And though the compiler gives this error in ec.setName = input.next(); line. So please somebody help me to solve this.

Here my code:

import java.util.Scanner;
  class Encapsul 
   { 
    private String name;
    private int roll_no;
    private float marks;
    private double total;
    private String school;

    public String getName() {
    return name;
    }
    public int getRoll_no() {
     return roll_no;
    }
    public float getMarks(){
     return marks;
    }
    public double getTotal(){
      return total;
    }
    public String getSchool(){
      return school;
    }

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

    public void setRoll_no(int newRoll_no) {
        roll_no = newRoll_no;
    }

    public void setMarks(float newMarks) {
        marks = newMarks;
    }

    public void setTotal(double newTotal) {
         total = newTotal;
    }

    public void setSchool(String newSchool) {
        school = newSchool;
    }

 }


class Test{
   public static void main(String args[]){
      Scanner input = new Scanner(System.in);

    Encapsul c = new Encapsul();
    System.out.println("please enter the Name");
     c.setName = input.next();

    System.out.println("please enter the roll_no");
     c.setRoll_no = input.nextInt();

    System.out.println("please enter the marks");
     c.setMarks = input.nextFloat();

    System.out.println("please enter the total");
     c.setTotal = input.nextDouble();

    System.out.println("please enter the school");
     c.setSchool = input.next();

   System.out.println("Name :"+ c.getName());
   System.out.println("Roll no :"+ c.getRoll_no());
   System.out.println("Marks :"+ c.getMarks());
   System.out.println("Total :"+ c.getTotal());
   System.out.println("School :"+ c.getSchool());
  }
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

0

setName() and others are methods, not fields.

//...
System.out.println("please enter the Name");
c.setName(input.next());

System.out.println("please enter the roll_no");
c.setRoll_no(input.nextInt());

System.out.println("please enter the marks");
c.setMarks(input.nextFloat());

System.out.println("please enter the total");
c.setTotal(input.nextDouble());

System.out.println("please enter the school");
c.setSchool(input.next());
//...
u32i64
  • 2,384
  • 3
  • 22
  • 36