Currently I am struggeling with an trivial problem I guess. When executing my main methode I get an stackoverflow error. It's because the Artist class creats an instance in the Language class to access some parameters comming from the Artist class (methode). Do you have any suggestions how I can set up the construct based on the current setup.
There are five classes interacting with each other:
First class is the Overview class with the main methode. She should create an instance of my control class and execute the methode control.displayArtist(salary, name):
public class Overview {
private static Control control;
private static String name;
private static int salary;
public static void main (String[]args) {
control = new Control();
control.displayArtist(salary, name);
}
}
The seccond class is the class Control. The class Control creates an instance of the class Language and consists of the methode displayArtist(int salary, String name). This method is callded directly in the main methode of the Overview Class:
public class Control {
private Language language;
public Control() {
language = new Language();
}
public void displayArtist(int salary, String name) {
language.displayArtistAndSalary(name, salary);
}
}
The Language class has all the println statements and is creating an instance of the Artist, for the methode displayArtistAndSalary(String name, int salary) to handle the String name and the int salary coming from the Artist class:
public class Language {
private Artist artist;
public Language () {
artist = new Artist();
}
public void specifyArtist() {
System.out.println("Who is the artist? ");
}
public void specifyArtistSalary() {
System.out.println("How much does the artist earn? ");
}
public void displayArtistAndSalary(String name, int salary) {
System.out.println("Artist: " + artist.getName(name));
System.out.println("Salary: " + artist.getSalary(salary));
}
}
Based on the input from the InputReader class:
import java.util.Scanner;
public class InputReader {
Scanner sc;
private Language language;
public InputReader () {
sc = new Scanner(System.in);
language = new Language();
}
public void addArtist(String name) {
language.specifyArtist();
name = sc.nextLine();
}
public void addArtistSalary (int salary) {
language.specifyArtistSalary();
salary = sc.nextInt();
}
}
the artist class returns the name and the salary in the methodes getName (String name) and getSalary(int salary):
public class Artist {
private InputReader inputReader;
public Artist() {
inputReader = new InputReader();
}
public String getName (String name){
inputReader.addArtist(name);
return name;
}
public int getSalary(int salary){
inputReader.addArtistSalary(salary);
return salary;
}
}