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

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...
Write a simple JAVA program to understand natural language. The user will enter the input following...
Write a simple JAVA program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Chris came to Bangkok, Thailand in 2009. The user will follow the exactly the same formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay in City for X year(s). City is in...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the maximum number (as integer) Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array Write a method named printTable to print out the MulitTable, with the following header, public static void printTable(int[][] multitable) In printTable(), when the value of the MultiTable is an odd number, print out Z Must use...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the number of Adult tickets to purchase Prompt user to input the number of Children tickets to purchase Prompt user to input the number of Senior tickets to purchase Write a method named, ticketCost(), which will be invoked by main() with statement similar to: cost = ticketCost( adults, children, senior ); Ticket costs structure: $15.00 for each adult $10.00 for each child $5.00 for each...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT