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

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

import java.util.Scanner;

class Ques
{
Scanner numin = new Scanner(System.in);

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;
}

{
System.out.println(quesText);

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 "";
}
}
}


and

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.setTitle(title);
window.setSize(size_X,size_Y);
window.setLocationRelativeTo(null);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setResizable(false);
window.setLayout(new GridBagLayout());

GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor=GridBagConstraints.FIRST_LINE_START;

ui=new JPanel();
ui.setBackground(Color.GRAY);
ui.setBorder(BorderFactory.createTitledBorder("Interface de Controle et Options"));
BoxLayout uiLayout = new BoxLayout(ui, BoxLayout.PAGE_AXIS);
ui.setLayout(uiLayout);
ui.setMaximumSize(ui.getPreferredSize());

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

gbc.weighty=1;
gbc.gridheight=1;
gbc.fill=GridBagConstraints.VERTICAL;
gbc.gridx=0;
gbc.gridy=0;

display=new JPanel();
display.setBackground(Color.RED);
gbc.weightx=1;
gbc.gridheight=1;
gbc.gridwidth=1;
gbc.fill=GridBagConstraints.BOTH;
gbc.gridx=1;
gbc.gridy=0;
window.setVisible(true);
}


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 = inFile1.next();
}
inFile1.close();

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

String searchArray = simpleDateformat.format(day);
for (String curVal : availabilityArray)
{
if (curVal.contains(searchArray))
{
System.out.println(curVal);
}
}


## 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
CodeActivity

package com.example.george.radonquote;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
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;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class QuotesActivity extends AppCompatActivity {

Toolbar myToolbar;
String randQuote = "";
String author;
TextView quoteTextView;
//    ImageView bgImageView;
ImageView nextImageView;
String url = "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quote_activity);

//setting the ActionBar for the activity
//        myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
//        setSupportActionBar(myToolbar);

quoteTextView = (TextView) findViewById(R.id.quote_text);
nextImageView = (ImageView) findViewById(R.id.next_quote);

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

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

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

//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){
ex.printStackTrace();
}
return null;
}

@Override
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.in);
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);
i++;
}

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(totexp);
}
//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)

## 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.

## Google Maps API – How to get Longitude and latitude values every mile / Km along a route?

So here is what I want to do…I want to be able to get the longLat values for every mile along a route and store them in an 2D array.

For instance. In the UK Going from Bristol to London is 117 Miles. For every Mile I would like to store the LongLat values of that position in a 2D Array, meaning I should end up with 117 LongLat values.

## 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?