View Single Post
  #1 (permalink)  
Old 09-20-2010, 09:25 PM
bsudhir6 bsudhir6 is offline
Junior Member
 
About:
Join Date: Dec 2009
Posts: 11
bsudhir6 is on a distinguished road

Exclamation please help me with this problem


Enc.java

package Obj5_1;

public class Enc
{
//Instance variables declared as private
private int x=6;
private char c='s';
private float f=5f;
//The accessor and mutator methods
public void setX(int val)
{
x=val;
}
public int getX()
{
return x;
}
public void setC(char val)
{
x=val;
}
public char getC()
{
return c;
}
public void setF (float val)
{
f=val;
}
public float getF()
{
return f;
}
}

class EncEx
{
public static void main(String[] args)
{
int i;
char j;
float k;
Enc E=new Enc();
System.out.println("The values of i,j,k before operation:");
i=44;
j='d';
k=43f;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("k="+k);
System.out.println("The values of i,j,k after get operation:");
i=E.getX();
j=E.getC();
k=E.getF();
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("k="+k);
System.out.println("The values of x,c,f after set operation:");
E.setX(45);
E.setC('S');
E.setF(6.45f);
System.out.println("x="+E.getX());
System.out.println("c="+E.getC());
System.out.println("f="+E.getF());
}
}
Output:
The values of i,j,k before operation:
i=44
j=d
k=43.0
The values of i,j,k after get operation:
i=6
j=s
k=5.0
The values of x,c,f after set operation:
x=83
c=s
f=6.45

X value is supposed to be 45 not 83 please help me with this…



Reply With Quote