Question

In: Computer Science

Please write a java program that has the following methods in it: (preferably in order)   a...

Please write a java program 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

Java class :

StudentsClass.java :


//import package
import java.util.*;

//Java class
public class StudentsClass {
   // main() method
   public static void main(String[] args) {
       // call method to get university name
       String uniName = universityName();
       // call method to get number of students
       int numStudents = numberOfStudents();
       // call method to calculate tuition fee
       double tuition = calculateTuitionFee(numStudents);
       // call method to display details
       printDetails(uniName, numStudents, tuition);

   }

   // a method to read in the name of a University and pass it back
   public static String universityName() {
       // Object of Scanner class
       Scanner sc = new Scanner(System.in);
       // asking user university name
       System.out.print("Enter University Name : ");
       // reading name
       return sc.nextLine();
   }

   // a method to read in the number of students enrolled and pass it back
   public static int numberOfStudents() {
       // Object of Scanner class
       Scanner sc = new Scanner(System.in);
       // asking user number of students
       System.out.print("Enter number of students : ");
       // reading number of students
       return sc.nextInt();
   }

   // a method to calculate the tuition as 20000 times the number of students and
   // pass it back
   public static double calculateTuitionFee(int numStudents) {
       // calculate and return tuition fee
       return numStudents * 20000;
   }

   // a method print the name of the University, the number of students enrolled,
   // and the total tuition
   public static void printDetails(String uniname, int numStudents, double tuition) {
       // print details
       System.out.println("University Name : " + uniname);// print university name
       System.out.println("Number of Students : " + numStudents);// print number of Students
       System.out.println("Tuition Fee: " + tuition);// print tuition fee
   }
}
=====================================

Output :


Related Solutions

Write a program (preferably in Java) that, given an arithmetic expression, first transforms it to a...
Write a program (preferably in Java) that, given an arithmetic expression, first transforms it to a postfix form, and then computes its value (by using stack-based algorithms). Assume that all the numbers in the arithmetic expression are one-digit numbers, i.e., each of these numbers is either 0, or 1, or 2, ..., or 9. For example, your program should correctly process expressions like 2+3*4, but there is no need to process expressions like 11+22.
Please show screenshot outputs and fully functional code for the Java program. Write the following methods...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods to   1) read the content of an array of 5 doubles public static double[] readingArray() 2) find and print:the smallest element in an array of 5 double public static void smallest(double [] array) 3) find and print:the largest element in an array of 5 doubles pubic static void largest (double [] array) In the main method - invoke readingArray and enter the following numbers...
Methods – Compute Grade Please write a complete Java program, given the following information about (a...
Methods – Compute Grade Please write a complete Java program, given the following information about (a few lines of code in) main: projectAverage = getAverage(”Project”); // returns average of 2 grades testAverage = getAverage(”Test”); // returns average of 2 grades displayGrade(projectAverage, testAverage); // test are 70% & projects 30%
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple The class Apple DOES NOT HAVE a main method Some of the attributes of Apple are Type: A string that describes the apple.  It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith Weight: A decimal value representing...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads three strings from the keyboard. Although the strings are in no particular order, display the string that would be second if they were arranged lexicographically.
How to write a Java program that has a base class with methods and attributes, subclasses...
How to write a Java program that has a base class with methods and attributes, subclasses with methods and attributes. Please use any example you'd like.
write program that develop a Java class Dictionary to support the following public methods of an...
write program that develop a Java class Dictionary to support the following public methods of an abstract data type: public class Dictionary { // insert a (key, value) pair into the Dictionary, key value must be unique, the value is associated with the key; only the last value inserted for a key will be kept public void insert(String key, String value); // return the value associated with the key value public String lookup(String key); // delete the (key, value) pair...
java please 1. Write a Java program to generate random numbers in the following range a....
java please 1. Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 2. Write statements that assign random integers to the variable n in the following ranges: a) 1 ≤ n ≤ 2 b) 1 ≤ n ≤ 100 c) 0 ≤ n ≤ 9 d) 1000 ≤...
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)   a method to read in the name of a University and pass it back a method to read in the number of students enrolled and pass it back a method to calculate the tuition as 20000 times the number of students and pass it back a method print the name of the University, the number of students enrolled,...
Please convert this java program to a program with methods please. import java.io.*; import java.util.*; public...
Please convert this java program to a program with methods please. import java.io.*; import java.util.*; public class Number{ public static void main(String[] args) {    Scanner scan = new Scanner(System.in); System.out.println("Enter 20 integers ranging from -999 to 999 : "); //print statement int[] array = new int[20]; //array of size 20 for(int i=0;i<20;i++){ array[i] = scan.nextInt(); //user input if(array[i]<-999 || array[i]>999){ //check if value is inside the range System.out.println("Please enter a number between -999 to 999"); i--; } } //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT