So my code is suppose to get information from the user and figure out how much funding the two professors get. My code runs twice but for some reason only the last entry is saved and outputted and my formula for calculating the new funding only outputs zero for some reason here is a sample of an output.
Name: Steve
Position: Assitant Professor
Institute: UCLA
Number of Papers Published: 11
Past Funding: $200,001.00
75
0.0
Heres the two classes
import javax.swing.JOptionPane;
public class NSFFunding {
/**
* @param args
*/
public static void main(String[] args) {
Scientist scientist = new Scientist();
scientist.createScientist();
System.out.print(scientist.createScientist());
System.out.println(scientist.getScore());
double funding;
int score = scientist.getScore();
funding = (score/100 * 500000);
System.out.print(funding);
}
}
import java.text.NumberFormat;
import javax.swing.JOptionPane;
public class Scientist {
/**
* @param args
*/
public int score = 0;
public String createScientist() {
String output = "";
String name1 = JOptionPane.showInputDialog(null, "Please enter your name: ",
"Lab 3", JOptionPane.QUESTION_MESSAGE);
output += ("Name: " + name1 + "\n");
String institute1 = JOptionPane.showInputDialog(null, "Enter your institute name: ",
"Lab 3", JOptionPane.QUESTION_MESSAGE);
String research1 = JOptionPane.showInputDialog(null, "Enter your research topic: ",
"Lab 3", JOptionPane.QUESTION_MESSAGE);
int response = Integer.parseInt(JOptionPane.showInputDialog(null, "1) Full Professor \n2) Associate Professor " +
"\n3) Assistant Professor \n4) Others",
"Lab 3", JOptionPane.QUESTION_MESSAGE));{
switch (response) {
case 1:
{
score = score + 30;
output +=("Position: Full Professor\n");
}
break;
case 2:
{
score = score + 20;
output +=("Position: Associate Professor\n");
}
break;
case 3:
{
score = score + 10;
output +=("Position: Assitant Professor\n");
}
break;
case 4:
{
score = score + 5;
output += ("Position: Other\n");
}
break;
default:
JOptionPane.showMessageDialog(null, "Sorry! No such option is on the menu. " +
"Please eneter it again",
"Lab 3", JOptionPane.WARNING_MESSAGE);
break;
}
}
output += ("Institute: " + institute1 + "\n");
int papersPublished = Integer.parseInt(JOptionPane.showInputDialog(null, "Number of Papers Published: ",
"Lab 3", JOptionPane.QUESTION_MESSAGE)); {
output += ("Number of Papers Published: " + papersPublished + "\n");
if(papersPublished >= 30)
{
score = score + 30;
}
if( 20 <= papersPublished )
{
score = score + 20;
}
if(10 <=papersPublished)
{
score = score + 10;
}
if(papersPublished < 10)
{
score = score + 5;
}
}
String userPastFunding = (JOptionPane.showInputDialog(null, "Past Funding Awarded: ",
"Lab 3", JOptionPane.QUESTION_MESSAGE));
int pastFunding = Integer.parseInt(userPastFunding);
{
if(pastFunding >= 400000)
{
score = score + 40;
}
if(300000 <= pastFunding)
{
score = score + 30;
}
if(200000 <= pastFunding)
{
score = score + 20;
}
if(pastFunding < 200000)
{
score = score + 10;
}
}
NumberFormat currency = NumberFormat.getCurrencyInstance( );
userPastFunding = currency.format(pastFunding);
output += ("Past Funding: " + userPastFunding + "\n");
return output;
}
public int getScore(){
return score;
}
}