System.out.println Not Printing in Custom Class’s Method

I’ve created two .java files, one named and the other named Here are the contents of and, respectively:

import java.util.Scanner;

class Ques
  Scanner numin = new Scanner(;

  String quesText = "";
  String quesAtr1 = "";
  String quesAtr2 = "";
  String quesAtr3 = "";
  String quesAtr4 = "";
  boolean done = false;

  Ques(String qText, String qAtr1, String qAtr2, String qAtr3, String qAtr4)
    quesText = qText;
    quesAtr1 = qAtr1;
    quesAtr2 = qAtr2;
    quesAtr3 = qAtr3;
    quesAtr4 = qAtr4;

  String ask()

    if (numin.nextInt() == 1)
      System.out.println(quesAtr1); return quesAtr1;
    } else if (numin.nextInt() == 2)
      System.out.println(quesAtr2); return quesAtr2;
    } else if (numin.nextInt() == 3)
      System.out.println(quesAtr3); return quesAtr3;
    } else if (numin.nextInt() == 4)
      System.out.println(quesAtr4); return quesAtr4;
    } else
      System.out.println("That is not a valid input. Possible inputs are: 1, 2, 3, 4."); System.out.println(""); return "";


import java.util.Scanner;

class TBRPGgame
  public static void main(String[] args)
    Ques question1 = new Ques("nnOne day, while you were travelling, you visited a city. However, you had only enough time to visit one building before you had to leave the city.nnWhich building did you visit?n1.) I visited the library.n2.) I visited the tavern.n3.) I visited the blacksmith.n4.) I visited the temple.", "kno", "rhe", "str", "fai");

However, when the Ques object’s ask method is executed, the System.out.println code included in the 5 possible results (the input being 1, 2, 3, 4, or something else) doesn’t seem to be printing.

[Java/Swing/GUI]Container with BoxLayout is resized by component

I’m currently working on a project for my studies and I have a little problem concerning the Graphic Interface.
Here is some code:

private JButton zoomUp, zoomDown;
private JComboBox fractalList;
private JLabel choice,space;
private JPanel ui,display;
private JFrame window;
    public FractalView(FractalModel m, FractalController c, String title, int size_X, int size_Y)
    window =new JFrame();
    window.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();

    ui=new JPanel();        
    ui.setBorder(BorderFactory.createTitledBorder("Interface de Controle et Options"));
    BoxLayout uiLayout = new BoxLayout(ui, BoxLayout.PAGE_AXIS);

    zoomUp = new JButton("Zoom +");
    zoomDown = new JButton("Zoom -");
    choice = new JLabel("Choisir une fractale : ");
    Object[] elements = new Object[]{"Mandelbrot", "Julia", "Buddhabrot"};
    fractalList = new JComboBox<Object>(elements);
    fractalList.setMaximumSize(new Dimension(Short.MAX_VALUE,20));



    display=new JPanel();

The problem comes from JPanel ui . As long it is empty the size is as desired. But when I add any component to it it’s weight increases.
I tried to use setMaxSize() but even tho it gets resized and this could cause problem with what I want to display on JPanel display. I would prefer to avoid using GridBagLayout again . Does someone have an idea?

Get a time value from a text file in Java

Is there any way to extract a time value from a text file. The format of the text file is

Jack Johnson
Sunday 1100 – 1500,

I cannot find a way to extract these 2 times from a text file by themselves. This code below is what I have so far and it works for strings but I cannot find a way to get it to extract the time ranges within the text file

Boolean isAvail = false;
Date day = new Date();

SimpleDateFormat simpleDateformat = new SimpleDateFormat("EEEE");
String token1 = "";

Scanner inFile1 = new Scanner(new File("F:\Example\text.txt")).useDelimiter(",\s*");

List<String> availability = new ArrayList<String>();

while (inFile1.hasNext()) 
        token1 =;

    String[] availabilityArray = availability.toArray(new String[0]);

    String searchArray = simpleDateformat.format(day);
    for (String curVal : availabilityArray)
        if (curVal.contains(searchArray))

special character conversion in android studio

guys I’m working on an app that establish a connection using json data and present to user. I’m stripping the json data from html tags; however, the ‘ symbol is getting a weird conversion to something like “#4457;”. Check the following image.
I’ve manage to strip html tags but keep getting the weird code from ‘. how can I fix it?
here’s my code


import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


public class QuotesActivity extends AppCompatActivity {

    Toolbar myToolbar;
    String randQuote = "";
    String author;
    TextView quoteTextView;
    //    ImageView bgImageView;
    ImageView nextImageView;
    String url = "[orderby]=rand&filter[posts_per_page]=1";

    protected void onCreate(Bundle savedInstanceState) {

        //setting the ActionBar for the activity
//        myToolbar = (Toolbar) findViewById(;
//        setSupportActionBar(myToolbar);

        quoteTextView = (TextView) findViewById(;
        nextImageView = (ImageView) findViewById(;

        /*onclick listener for next quote*/
        nextImageView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                FetchQuote fetchQuote = new FetchQuote();

    * async class to get random quote in background
    class FetchQuote extends AsyncTask<Void, Void, Void> {
        String quote = "";
        protected void onPreExecute() {
//            Toast.makeText(MainActivity.this,"Fetching Quote!",Toast.LENGTH_SHORT).show();

        * making connection and parsing json data
        protected Void doInBackground(Void... voids) {
            try {
                URL uri = new URL(url);
                HttpURLConnection urlConnection = (HttpURLConnection) uri.openConnection();
                InputStream inputStream = urlConnection.getInputStream();
                BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
                String line = "";
                while((line = bf.readLine()) != null) {
                    Log.v("line: ",line);
                    quote += line;
            catch (MalformedURLException ex) {
            catch (IOException ex) {

            //json parsing
            try {
                JSONArray ja = new JSONArray(quote);
                JSONObject jo = (JSONObject) ja.get(0);
                randQuote = jo.get("content").toString().replaceAll("\<[^>]*>","");
                author = jo.get("title").toString();
                Log.v("QUOTE", randQuote+" "+author);
            catch (JSONException ex){
            return null;

        protected void onPostExecute(Void aVoid) {
//            Log.v("Post Exec", randQuote);
            quoteTextView.setText(randQuote +"n"+author);


How do you create a For loop in Java using netbeans 8.1

import java.util.Scanner;

public class ProgAssignment12ForLoop {

 * @param args the command line arguments
public static void main(String[] args) 
 int time = 0; 
 int speed = 0;
 int distance = 0;

 for (int i = 0, i > 0, i++)
     Scanner keyboard = new Scanner(;
     System.out.println("Please input the speed of the vehicle: ");
     speed = keyboard.nextInt();

     System.out.println("Please input how many hours you've traveled: ");
     time = keyboard.nextInt();

     distance = speed * time;

     System.out.println("the distance you have traveled is " + distance);

 System.out.println("Programmed terminated");



this is the prompt for the type of program I’m suppose to do. ‘

Use FOR loop to program this problem
The distance a vehicle travels can be calculated as follows:
Distance = speed * time
For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. It should use a loop to display the distance a vehicle has traveled for each hour of a time perios specified by the user. For example, if a vehicle is traveling at 40 mph for a three-hour time period, it should display a report similar to the one that follows:

Hour 1

Distance Traveled 40

Hour 2

distance traveled 80

hour 3

distance traveled 120

Searching for highest possible XP points in sheet

this might be an unusual request or ask for help.
Ive been playing a browser game lately that has me pretty hooked, and I decided to make a small program to calculate my level in the game when you add a certain amount of exp, but I can’t seem to get the program to work.

What Im trying to achieve is basically when you input “yourlevel exp” it will print out the level I will become, but as far as my knowledge goes I can only make it print out each level, required exp and total exp and that’s about it.

public static void main(String[] cmdLn){
    int yourlevel = Integer.parseInt(cmdLn[0]);
    int totexp = 0;
    int exp = 0;
    int expperlevel = 10;
    for(int level = 1; level <= yourlevel; level++){
        exp = exp + expperlevel;
        totexp = totexp + exp;
        System.out.println("Level: " + level + " ||| XP required: " + exp + " ||| XP increase: " + expperlevel + " ||| Total XP: " + totexp);
        if (level % 100 == 0)
            expperlevel = expperlevel + 5;
            exp = exp/2;
//System.out.println("Level: " + yourlevel + " total exp: " + totexp);

I was thinking of taking the total exp for the level I input, add the specified experience and then search for the level with the highest total exp combined but not going over, if you guys know what I mean. My problem is, I don’t know how to call for the total exp for a specific levcel, only how to print it all out. For example totalexp for level X + Y exp = level Z. Basically all I have is an experience point sheet.

Anyone got ideas?

Intelilj Error connecting to a Database in java (MySQL)

I have been trying to connect to a database in java for a while now and everything I do seems to fail. I am working with the latest version of intellij Ultimate edition, I’m also using XAMMP to run the MySQL database. When I try to connect to the database through intellij I get a connection failed error(as show bellow). I’m not sure what is going wrong and how to solve this issue any help will be greatly appreciated and also if there is a better way to do this I would be happy to happy to know about them.(I have also tried to add the MYSQL connector to the ide by editing the SDK)

enter image description here

javax.validation.* does not exist when application deployed on Payara 174

When I changed the server from Payara 171 to Payara 174, I get the following error on compilation:

Caused by: java.lang.RuntimeException: Uncompilable source code –
package javax.validation.constraints does not exist

and all the javax.validation.* imports are marked as does not exist.

My java EE 7 Web application was migrated from glassfish 4.1.1 to Payara 171 without any troubles.
I have JDK8 on my work station and my web app is based on JDK7.
Any help please

Choosing a default server in Eclipse

I have two instances of wildfly in my Eclipse EE IDE. One is version 10.1 and the other one is version 11.

I deploy my projects by doing the following:

  • build the project using maven
  • right click on the EAR file that was build by maven, and then choosing Mark as Deployable (that way the project re-deploys when I build the project again using Maven
  • However, sometimes I manually remove the deployment from the deployment while I leave the server running
  • In this scenario, when I build the project again, it won’t automatically deploy and I right click on EAR and select Run As -> Run on Server
  • When I first tested my project I deployed it on Wildfly 11 and choose it as my default server for this project
  • However, I changed my mind, and now want to run it on Wildfly 10 (the other server)
  • The problem is Eclipse won’t let me choose again and when I click Run on server it automatically tries to deploy my project on Wildfy 11 ( the server I selected as a default for the project)

I am looking for the way to change the default run configuration in Eclipse for this project to run on Wildfly 10, not 11.

I tried right clicking on the EAR module and then clicking on properties-> servers and choosing Wildfly 10 as my default server.

However, this doesn’t solve the problem. When I click on the EAR archive and select Run as -> Run on server it stills tries to run my project on Wildfly 11.

How can I change the default server?