Question

In: Computer Science

Please write a java program (using dialog box statements for user input) that has the following...

Please write a java program (using dialog box statements for user input) that has the following methods in it: (preferably in order)  

  1. a method to read in the name of a University and pass it back
  2. a method to read in the number of students enrolled and pass it back
  3. a method to calculate the tuition as 20000 times the number of students and pass it back
  4. a method print the name of the University, the number of students enrolled, and the total tuition

Design Notes:

  • The method described in Item #1 above will read in a string and pass it back to the main program. Nothing is passed to the method, but the University name is passed back
  • The method described in Item #2 above will read in an integer for the number of students enrolled and pass it back to the main program. Nothing is passed to the method, but the University name is passed back to the main program
  • The method described in Item #3 above will receive the number of students. It will then do the calculation for the tuition and pass back that value, which is a double value to the main program
  • The method described in Item #4 above will receive all data for printing and pass nothing back to the main program

Please copy the java code along with a screen print (snippet) of the final output. I would like both to review the work that I already have done. Thanks in advance!

Solutions

Expert Solution

Following is the java code for the above problem:


import javax.swing.JOptionPane;

public class Dialog_box_stmt_eg {

   static String name(){
       String name;

   // Get the university name.
   name = JOptionPane.showInputDialog("What is university name? ");

   // Display university name.
   JOptionPane.showMessageDialog(null, "University name is=" + name);
       return name;
   }
   static int Students_enrolled(){
       String input; // To hold number of students enrolled
   int no_of_students;
  
   // Prompt user to input number of students enrolled
   input = JOptionPane.showInputDialog("Enter number of students enrolled");

   // Convert the String input to an int.
   no_of_students = Integer.parseInt(input);

       return no_of_students;
   }
  
   static double Calculate_fees(int stud_enrolled){
      
   double fees; // To hold fees
  
   fees= 20000*stud_enrolled;

   // Display calculated fees
   JOptionPane.showMessageDialog(null,
   "Total tution fees for "+stud_enrolled+" are = "+stud_enrolled+"*20000 = " + fees);
       return fees;
   }
  
   static void print(int stud_enrolled, String name , double tution_fees ){
       JOptionPane.showMessageDialog(null,
stud_enrolled+" students enrolled in "+name+ " university with total tution fees of = "+tution_fees);
      
       System.out.println( stud_enrolled+" students enrolled in "+name+ " university with total tution fees of = "+tution_fees);
   }
  
   public static void main(String[] args) {
       String univ_name= name();
       System.out.println("univ name is="+univ_name);
      
       int stud_enrolled=Students_enrolled();
       System.out.println("Number of students enrolled="+stud_enrolled +" in "+ univ_name + " university");
      
       double tution_fees=Calculate_fees(stud_enrolled);
       System.out.println("total tution fees = "+tution_fees);
      
       print(stud_enrolled, univ_name, tution_fees);
   }
}

Program screenshots:

Explanation: JOptionPane.showInputDialog -- is used for dialog box statements for user input as mentioned in question. Additional import statement is need to be added "import javax.swing.JOptionPane;"

Output Images of the code are below:

Output in console:

univ name is=ABCDEFGH
Number of students enrolled=10 in ABCDEFGH university
total tution fees = 200000.0
10 students enrolled in ABCDEFGH university with total tution fees of = 200000.0

NOTE: You can add various validations as per your choice as it is not mentioned in the question, so i have not added those in order not to complex the answer. Also you can remove or add DISPLAY or System.out.println(); lines as per your choice. I have added in order to give more understanding/readability to the code. If you dont want these lines you can comment it out and execute the rest of the code.


Related Solutions

7) Write a program to open an input dialog box and read a string value. Write...
7) Write a program to open an input dialog box and read a string value. Write the string back to the user using a message box. USING MIPS ASSEMBLY LANGUAGE
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a java program. The program requirements are: the program will let the user input a...
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2.  It will generate ten multiplication problems ranging from 2x1 to 2x10.  For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently. After testing a total of 10 multiplication problems,...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
For input you can either a console Scanner or a dialog box (a modal dialog) and...
For input you can either a console Scanner or a dialog box (a modal dialog) and the static method showInputDialog() of the JOptionPane class which is within the javax.swing package like this String name= newJOptionPane.showInputDialog(” Please enter your data:”). Then convert the String object to a number using Integer.parseInt() or Double.parseDouble() ---- Write a java the ”Letter grade” program that inputs several test scores from user and displays for each the corresponding letter grade using a scale 90 – 80...
For input you can either a console Scanner or a dialog box (a modal dialog) and...
For input you can either a console Scanner or a dialog box (a modal dialog) and the static method showInputDialog() of the JOptionPane class which is within the javax.swing package like this String name= newJOptionPane.showInputDialog(” Please enter your data:”). Then convert the String object to a number using Integer.parseInt() or Double.parseDouble() --- Write a java ”Statistics program” to calculate the mean, variance and standard deviation for a given set of numbers. The user in entering the data interactively. The size...
For input you can either a console Scanner or a dialog box (a modal dialog) and...
For input you can either a console Scanner or a dialog box (a modal dialog) and the static method showInputDialog() of the JOptionPane class which is within the javax.swing package like this String name= newJOptionPane.showInputDialog(” Please enter your data:”). Then convert the String object to a number using Integer.parseInt() or Double.parseDouble() ----- . If an amount of A dollars is borrowed at an interest rate (expressed as a decimal) r for y years, and n is the number of annual...
For input you can either a console Scanner or a dialog box (a modal dialog) and...
For input you can either a console Scanner or a dialog box (a modal dialog) and the static method showInputDialog() of the JOptionPane class which is within the javax.swing package like this String name= newJOptionPane.showInputDialog(” Please enter your data:”). Then convert the String object to a number using Integer.parseInt() or Double.parseDouble() ----- Write a Java program to calculate the first n ( the user enters the integer n) rows of the Pascal triangle. On demand display the first n rows...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT