Мне нужна помощь в очистке некоторых тестовых примеров из основного метода, который был предоставлен. Мне пришлось настроить класс, в котором есть сеттеры и гетры, а также перевод, но я застрял. < /P>
Это класс с тестовыми случаями. < / p>
// This is the driver for the Saurian class
// Use this website to compare with your translator:
// https://saurian.krystalarchive.com/
// Game that Saurian originated from:
// https://en.wikipedia.org/wiki/Star_Fox_Adventures
// http://starfox.wikia.com/wiki/Dino
public class SaurianDriver
{
public static void main(String[] args)
{
// create the Saurian object using the default constructor
Saurian saur = new Saurian();
// TEST #1
// Test the English word "College"
// It should translate to "Seccowo"
saur.setEnglish("College");
System.out.println(saur.getSaurian());
if (saur.getSaurian().equals("Seccowo"))
System.out.println("TEST #1 Passed!");
else
System.out.println("TEST #1 Failed!");
System.out.println();
// TEST #2
// Test the English phrase: "Hello World!"
// It should translate to "Xocce Nehct!"
saur.setEnglish("Hello World!");
System.out.println(saur.getSaurian());
if (saur.getSaurian().equals("Xocce Nehct!"))
System.out.println("TEST #2 Passed!");
else
System.out.println("TEST #2 Failed!");
System.out.println();
// TEST #3
// Test the Saurian word "Faqqu"
// It should translate to "Pizza"
saur.setSaurian("Faqqu");
System.out.println(saur.getEnglish());
if (saur.getEnglish().equals("Pizza"))
System.out.println("TEST #3 Passed!");
else
System.out.println("TEST #3 Failed!");
System.out.println();
// TEST #4
// Test the Saurian phrase: "Kubadw faskihoj aj vid."
// It should translate to "Taking pictures is fun."
saur.setSaurian("Kubadw faskihoj aj vid.");
System.out.println(saur.getEnglish());
if (saur.getEnglish().equals("Taking pictures is fun."))
System.out.println("TEST #4 Passed!");
else
System.out.println("TEST #4 Failed!");
System.out.println();
// TEST #5
// Translate "De edo sud tovouk GENERAL SCALES!"
// It should translate to "No one can defeat GENERAL SCALES!"
saur.setSaurian("De edo sud tovouk");
System.out.println(saur.getEnglish() + " GENERAL SCALES!");
if (saur.getEnglish().equals("No one can defeat"))
System.out.println("TEST #5 Passed!");
else
System.out.println("TEST #5 Failed!");
System.out.println();
// TEST #6
// Translate "Soccer is a way of life!"
// It should translate to "Jessoh aj u nuo ev cavo!"
saur.setEnglish("Soccer is a way of life!");
System.out.println(saur.getSaurian());
if (saur.getSaurian().equals("Jessoh aj u nuo ev cavo!"))
System.out.println("TEST #6 Passed!");
else
System.out.println("TEST #6 Failed!");
System.out.println();
// TEST #7
// Test the English word "College"
// It should translate to "Seccowo"
// create the Saurian object and initialize the data
Saurian saur2 = new Saurian("College", true); // true means 1st
parameter is in English
System.out.println(saur2.getSaurian());
if (saur2.getEnglish().equals("College") && saur2.getSaurian().equals("Seccowo"))
System.out.println("TEST #7 Passed!");
else
System.out.println("TEST #7 Failed!");
System.out.println();
// TEST #8
// Test the Saurian word "Faqqu"
// It should translate to "Pizza"
// create the Saurian object and initialize the data
Saurian saur3 = new Saurian("Faqqu", false); // false means 1st parameter is in Saurian
System.out.println(saur3.getEnglish());
if (saur3.getEnglish().equals("Pizza") && saur3.getSaurian().equals("Faqqu"))
System.out.println("TEST #8 Passed!");
else
System.out.println("TEST #8 Failed!");
System.out.println();
// TEST #9
// Test the English word "Hello World!"
// It should translate to "Xocce Nehct!"
// create the Saurian object and initialize the data
Saurian saur4 = new Saurian("Hello World!", true); // true means 1st parameter is in English
System.out.println(saur4.getSaurian());
if (saur4.getEnglish().equals("Hello World!") &&
saur4.getSaurian().equals("Xocce Nehct!"))
System.out.println("TEST #9 Passed!");
else
System.out.println("TEST #9 Failed!");
System.out.println();
// TEST #10
// Test the Saurian word "Kubadw faskihoj aj vid."
// It should translate to "Taking pictures is fun."
// create the Saurian object and initialize the data
Saurian saur5 = new Saurian("Kubadw faskihoj aj vid.", false); //
false means 1st parameter is in Saurian
System.out.println(saur5.getEnglish());
if (saur5.getEnglish().equals("Taking pictures is fun.") &&
saur5.getSaurian().equals("Kubadw faskihoj aj vid."))
System.out.println("TEST #10 Passed!");
else
System.out.println("TEST #10 Failed!");
System.out.println();
// TEST #11
// Test the toString()
System.out.println(saur.toString());
System.out.println();
System.out.println(saur2.toString());
System.out.println();
System.out.println(saur3.toString());
System.out.println();
System.out.println(saur4.toString());
System.out.println();
System.out.println(saur5.toString());
}
}
< /code>
Это класс со всеми методами. < /p>
// Programmer:
// Date:
// The Saurian class has the ability to translate English to Saurian
// and Saurian to English
import java.util.Arrays;
public class Saurian
{
// data
// constants used for translating
// note M = M and m = m so M and m are not needed
public static final Character[] ENGLISHARR = {'A','B','C','D','E','F','G','H','I','J','K','L','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','n','o','p','q','r','s','t','u','v','w','x','y','z'};
public static final Character[] SAURIANARR = {'U','R','S','T','O','V','W','X','A','Z','B','C','D','E','F','G','H','J','K','I','L','N','P','O','Q','u','r','s','t','o','v','w','x','a','z','b','c','d','e','f','g','h','j','k','i','l','n','p','o','q'};
public static final int ARRLENGTH = ENGLISHARR.length; // should be the same length for ENGLISHARR and SAURIANARR
private String saurian = "";
private String english = "";
public Saurian()
{
english = "";
saurian = "";
}
public Saurian(String phrase, Boolean which)
{
//If the string is in english the boolean will be stored as true and I will pass the phrase on to english as well
if(which == true)
{
english = phrase;
saurian = translateEngToSaur(phrase);
}
else
{
saurian = phrase;
english = translateSaurToEng(phrase);
}
}
public void setEnglish(String newEnglish)
{
english = newEnglish;
//Just seeing what the output is
System.out.println("This is newEnglish " + newEnglish);
}
public String getEnglish()
{
//Just seeing what the output is
System.out.println("This is getEnglish "+ english);
return english;
}
public void setSaurian(String newSaurian)
{
saurian = newSaurian;
}
public String getSaurian()
{
//Just seeing what the output is
System.out.println("This is getSaurian "+ saurian);
return this.saurian;
}
public String translateSaurToEng(String saurianToEnglish)
{
String word = saurianToEnglish;
// String that will be used to store the word after it has been
// translated and will be built using the for loops
// For loop that loops as long as the input is Ex. "Hello World" is 11
// characters long
for (int i = 0; i < word.length(); i++)
{
// indexOfYellow should store the index number for which the letter in the string was located in the array.
int indexOfYellow = Arrays.asList(ENGLISHARR).indexOf(word.charAt(i));
// Should Check if the character at index i is present in ENGLISHARR then it will save it to saurianToEnglish
if (indexOfYellow != -1)
{
saurian += SAURIANARR[indexOfYellow];
// This is just here to see if the if statement passed
}
else
{
saurian += word.charAt(i);
// This is just here to see if the if statement failed
}
}
return saurian;
}
public String translateEngToSaur(String englishToSaurian)
{
String word = englishToSaurian;
// String that will be used to store the word after it has been
// translated and will be built using the for loops
// For loop that loops as long as the input is Ex. "Hello World" is 11
// characters long
for (int i = 0; i < word.length(); i++)
{
// indexOfYellow should store the index number for which the letter in the string was located in the array.
int indexOfYellow = Arrays.asList(SAURIANARR).indexOf(word.charAt(i));
// Should Check if the character at index i is present in ENGLISHARR then it will save it to saurianToEnglish
if (indexOfYellow != -1)
{
english += ENGLISHARR[indexOfYellow];
// This is just here to see if the if statement passed
}
else
{
english += word.charAt(i);
// This is just here to see if the if statement failed
}
}
return english;
}
}
< /code>
Я попытался сохранить значение внутри метода Getter, изменив < /p>
public void translateSaurToEng(String saurianToEnglish)
< /code>
и < /p>
public void translateEngToSaur(String englishToSaurian)
< /code>
Into < /p>
public String translateSaurToEng(String saurianToEnglish)
public String translateEngToSaur(String englishToSaurian)
< /code>
, чтобы я мог вернуть значение и сохранить его для дальнейшего использования. < /p>
Я тогда сделал это < / p>
public String getSaurian()
{
//Just seeing what the output is
this.saurian = translateEngToSaur(english);
return this.saurian;
}
public String getEnglish()
{
this.english = translateSaurToEng(saurian);
//Just seeing what the output is for english
System.out.println("This is getEnglish "+ english);
return this.english;
}
< /code>
Но метод несовместим, потому что < /p>
translateSaurToEng(saurian)
< /code>
void, поэтому я изменил его на < /p>
public String translateSaurToEng(String saurianToEnglish)
< /code>
затем попытался сделать это таким образом, но это не позволило мне из -за ошибки. < /p>
Спасибо за любая помощь, которую вы можете оказать.
Подробнее здесь: https://stackoverflow.com/questions/557 ... r-type-pro
Как настроить сеттеры и Getters, чтобы пройти тестовые примеры. Проблема типа шифра Цезаря ⇐ JAVA
Программисты JAVA общаются здесь
1738381013
Anonymous
Мне нужна помощь в очистке некоторых тестовых примеров из основного метода, который был предоставлен. Мне пришлось настроить класс, в котором есть сеттеры и гетры, а также перевод, но я застрял. < /P>
Это класс с тестовыми случаями. < / p>
// This is the driver for the Saurian class
// Use this website to compare with your translator:
// https://saurian.krystalarchive.com/
// Game that Saurian originated from:
// https://en.wikipedia.org/wiki/Star_Fox_Adventures
// http://starfox.wikia.com/wiki/Dino
public class SaurianDriver
{
public static void main(String[] args)
{
// create the Saurian object using the default constructor
Saurian saur = new Saurian();
// TEST #1
// Test the English word "College"
// It should translate to "Seccowo"
saur.setEnglish("College");
System.out.println(saur.getSaurian());
if (saur.getSaurian().equals("Seccowo"))
System.out.println("TEST #1 Passed!");
else
System.out.println("TEST #1 Failed!");
System.out.println();
// TEST #2
// Test the English phrase: "Hello World!"
// It should translate to "Xocce Nehct!"
saur.setEnglish("Hello World!");
System.out.println(saur.getSaurian());
if (saur.getSaurian().equals("Xocce Nehct!"))
System.out.println("TEST #2 Passed!");
else
System.out.println("TEST #2 Failed!");
System.out.println();
// TEST #3
// Test the Saurian word "Faqqu"
// It should translate to "Pizza"
saur.setSaurian("Faqqu");
System.out.println(saur.getEnglish());
if (saur.getEnglish().equals("Pizza"))
System.out.println("TEST #3 Passed!");
else
System.out.println("TEST #3 Failed!");
System.out.println();
// TEST #4
// Test the Saurian phrase: "Kubadw faskihoj aj vid."
// It should translate to "Taking pictures is fun."
saur.setSaurian("Kubadw faskihoj aj vid.");
System.out.println(saur.getEnglish());
if (saur.getEnglish().equals("Taking pictures is fun."))
System.out.println("TEST #4 Passed!");
else
System.out.println("TEST #4 Failed!");
System.out.println();
// TEST #5
// Translate "De edo sud tovouk GENERAL SCALES!"
// It should translate to "No one can defeat GENERAL SCALES!"
saur.setSaurian("De edo sud tovouk");
System.out.println(saur.getEnglish() + " GENERAL SCALES!");
if (saur.getEnglish().equals("No one can defeat"))
System.out.println("TEST #5 Passed!");
else
System.out.println("TEST #5 Failed!");
System.out.println();
// TEST #6
// Translate "Soccer is a way of life!"
// It should translate to "Jessoh aj u nuo ev cavo!"
saur.setEnglish("Soccer is a way of life!");
System.out.println(saur.getSaurian());
if (saur.getSaurian().equals("Jessoh aj u nuo ev cavo!"))
System.out.println("TEST #6 Passed!");
else
System.out.println("TEST #6 Failed!");
System.out.println();
// TEST #7
// Test the English word "College"
// It should translate to "Seccowo"
// create the Saurian object and initialize the data
Saurian saur2 = new Saurian("College", true); // true means 1st
parameter is in English
System.out.println(saur2.getSaurian());
if (saur2.getEnglish().equals("College") && saur2.getSaurian().equals("Seccowo"))
System.out.println("TEST #7 Passed!");
else
System.out.println("TEST #7 Failed!");
System.out.println();
// TEST #8
// Test the Saurian word "Faqqu"
// It should translate to "Pizza"
// create the Saurian object and initialize the data
Saurian saur3 = new Saurian("Faqqu", false); // false means 1st parameter is in Saurian
System.out.println(saur3.getEnglish());
if (saur3.getEnglish().equals("Pizza") && saur3.getSaurian().equals("Faqqu"))
System.out.println("TEST #8 Passed!");
else
System.out.println("TEST #8 Failed!");
System.out.println();
// TEST #9
// Test the English word "Hello World!"
// It should translate to "Xocce Nehct!"
// create the Saurian object and initialize the data
Saurian saur4 = new Saurian("Hello World!", true); // true means 1st parameter is in English
System.out.println(saur4.getSaurian());
if (saur4.getEnglish().equals("Hello World!") &&
saur4.getSaurian().equals("Xocce Nehct!"))
System.out.println("TEST #9 Passed!");
else
System.out.println("TEST #9 Failed!");
System.out.println();
// TEST #10
// Test the Saurian word "Kubadw faskihoj aj vid."
// It should translate to "Taking pictures is fun."
// create the Saurian object and initialize the data
Saurian saur5 = new Saurian("Kubadw faskihoj aj vid.", false); //
false means 1st parameter is in Saurian
System.out.println(saur5.getEnglish());
if (saur5.getEnglish().equals("Taking pictures is fun.") &&
saur5.getSaurian().equals("Kubadw faskihoj aj vid."))
System.out.println("TEST #10 Passed!");
else
System.out.println("TEST #10 Failed!");
System.out.println();
// TEST #11
// Test the toString()
System.out.println(saur.toString());
System.out.println();
System.out.println(saur2.toString());
System.out.println();
System.out.println(saur3.toString());
System.out.println();
System.out.println(saur4.toString());
System.out.println();
System.out.println(saur5.toString());
}
}
< /code>
Это класс со всеми методами. < /p>
// Programmer:
// Date:
// The Saurian class has the ability to translate English to Saurian
// and Saurian to English
import java.util.Arrays;
public class Saurian
{
// data
// constants used for translating
// note M = M and m = m so M and m are not needed
public static final Character[] ENGLISHARR = {'A','B','C','D','E','F','G','H','I','J','K','L','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','n','o','p','q','r','s','t','u','v','w','x','y','z'};
public static final Character[] SAURIANARR = {'U','R','S','T','O','V','W','X','A','Z','B','C','D','E','F','G','H','J','K','I','L','N','P','O','Q','u','r','s','t','o','v','w','x','a','z','b','c','d','e','f','g','h','j','k','i','l','n','p','o','q'};
public static final int ARRLENGTH = ENGLISHARR.length; // should be the same length for ENGLISHARR and SAURIANARR
private String saurian = "";
private String english = "";
public Saurian()
{
english = "";
saurian = "";
}
public Saurian(String phrase, Boolean which)
{
//If the string is in english the boolean will be stored as true and I will pass the phrase on to english as well
if(which == true)
{
english = phrase;
saurian = translateEngToSaur(phrase);
}
else
{
saurian = phrase;
english = translateSaurToEng(phrase);
}
}
public void setEnglish(String newEnglish)
{
english = newEnglish;
//Just seeing what the output is
System.out.println("This is newEnglish " + newEnglish);
}
public String getEnglish()
{
//Just seeing what the output is
System.out.println("This is getEnglish "+ english);
return english;
}
public void setSaurian(String newSaurian)
{
saurian = newSaurian;
}
public String getSaurian()
{
//Just seeing what the output is
System.out.println("This is getSaurian "+ saurian);
return this.saurian;
}
public String translateSaurToEng(String saurianToEnglish)
{
String word = saurianToEnglish;
// String that will be used to store the word after it has been
// translated and will be built using the for loops
// For loop that loops as long as the input is Ex. "Hello World" is 11
// characters long
for (int i = 0; i < word.length(); i++)
{
// indexOfYellow should store the index number for which the letter in the string was located in the array.
int indexOfYellow = Arrays.asList(ENGLISHARR).indexOf(word.charAt(i));
// Should Check if the character at index i is present in ENGLISHARR then it will save it to saurianToEnglish
if (indexOfYellow != -1)
{
saurian += SAURIANARR[indexOfYellow];
// This is just here to see if the if statement passed
}
else
{
saurian += word.charAt(i);
// This is just here to see if the if statement failed
}
}
return saurian;
}
public String translateEngToSaur(String englishToSaurian)
{
String word = englishToSaurian;
// String that will be used to store the word after it has been
// translated and will be built using the for loops
// For loop that loops as long as the input is Ex. "Hello World" is 11
// characters long
for (int i = 0; i < word.length(); i++)
{
// indexOfYellow should store the index number for which the letter in the string was located in the array.
int indexOfYellow = Arrays.asList(SAURIANARR).indexOf(word.charAt(i));
// Should Check if the character at index i is present in ENGLISHARR then it will save it to saurianToEnglish
if (indexOfYellow != -1)
{
english += ENGLISHARR[indexOfYellow];
// This is just here to see if the if statement passed
}
else
{
english += word.charAt(i);
// This is just here to see if the if statement failed
}
}
return english;
}
}
< /code>
Я попытался сохранить значение внутри метода Getter, изменив < /p>
public void translateSaurToEng(String saurianToEnglish)
< /code>
и < /p>
public void translateEngToSaur(String englishToSaurian)
< /code>
Into < /p>
public String translateSaurToEng(String saurianToEnglish)
public String translateEngToSaur(String englishToSaurian)
< /code>
, чтобы я мог вернуть значение и сохранить его для дальнейшего использования. < /p>
Я тогда сделал это < / p>
public String getSaurian()
{
//Just seeing what the output is
this.saurian = translateEngToSaur(english);
return this.saurian;
}
public String getEnglish()
{
this.english = translateSaurToEng(saurian);
//Just seeing what the output is for english
System.out.println("This is getEnglish "+ english);
return this.english;
}
< /code>
Но метод несовместим, потому что < /p>
translateSaurToEng(saurian)
< /code>
void, поэтому я изменил его на < /p>
public String translateSaurToEng(String saurianToEnglish)
< /code>
затем попытался сделать это таким образом, но это не позволило мне из -за ошибки. < /p>
Спасибо за любая помощь, которую вы можете оказать.
Подробнее здесь: [url]https://stackoverflow.com/questions/55755039/how-to-set-up-setters-and-getters-to-pass-the-test-cases-ceasar-cipher-type-pro[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия