Reputation: 21
This is my class
public class SecretName{
private String str;
private int i;
private int j;
Scanner cycle=new Scanner(System.in);
public SecretName(String str , int i)
{
this.str = str;
this.i = i;
}
public SecretName(String str,int i, int j )
{
this.i = i;
this.j = j;
this.str = str;
}
public void cycleName(String str , int i)// method string and integer
{
System.out.print("Enter string:");
str=cycle.next()+" ";
System.out.print("Enter value:");
i=cycle.nextInt();
int l,len,y;
String str2="";
char x;
len=str.length();
for(l=0;l<len;l++)
{
x=str.charAt(l);
int c=Integer.valueOf(x);
if(i>0)
{
if((c>=97)&&(c<=123-i))
{
c=c+i;
str2=str2+(char)(c);
}
else
{
y=c+i;
c=(y-123)+96;
str2=str2+(char)(c);
}
}
}System.out.println("New string:" +str2);
}
public void cycleName(String str, int i, int j)//method string and 2 integer value
{
String alphabet[][] = {
{ "a", "b", "c", "d", "e" },
{ "f", "g", "h", "i", "j" },
{ "k", "l", "m", "n", "o",},
{ "p", "q", "r", "s", "t",},
{ "u", "v", "w", "x", "y",},
{ "z", "~", "!", "@", "#",}
};
int l=0;
for(i=0; i<6; i++) {//column
for(j=0; j<5; j++)//row
System.out.print(alphabet[i][j] + " ");
System.out.println();
}
System.out.print("Enter string:");
str=cycle.next();
System.out.print("Enter value:");
int n=cycle.nextInt();
int y;
String str2="";
char x;
String len=alphabet[i][j];
for(i=0; i<6; i++) {//column
for(j=0; j<5; j++)//row
{
//x=str.charAt(l);
//int c=Integer.valueOf(x);
if(n>0)
{
if((i>=0)&&(j<=6-n))
{
j=j+n;
str2=str2+(i);
}
else
{
y=i+n;
i=(y-90)+64;
str2=str2+(i);
}
}
}System.out.print("New string: " +str2);
}
}
and this is my extend class.
public class MySN extends SecretName
{
public static void main(String[] arg)
{
SecretName cn1 = new SecretName();
cn1.cycleName("abu", 3);
System.out.println(cn1.cycleName());
}
The problem is when I run it I got this error: constructor SecretName.SecretName(String,int,int) is not applicable (actual and formal argument lists differ in length) constructor SecretName.SecretName(String,int) is not applicable (actual and formal argument lists differ in length) Anyone can help me?
Upvotes: 1
Views: 944
Reputation: 219057
You've defined two constructors in your class:
public SecretName(String str , int i) {
//...
}
public SecretName(String str, int i, int j) {
//...
}
Both of them require arguments (two or three arguments, respectively). But you're trying to call a constructor with no arguments:
new SecretName()
You either need to add a parameterless constructor:
public SecretName() {
// initialize fields to default values?
// or maybe don't initialize anything?
}
Or you need to provide arguments to the constructor:
new SecretName("", 0)
// or...
new SecretName("", 0, 0)
// though you can use any values you like
Upvotes: 0
Reputation: 8657
You need to add the default constructor since you are using it from the main method.
SecretName cn1 = new SecretName();
so add this to the SecretName
class
public SecretName() {}
Upvotes: 2