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...
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.
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT