Java Program Can Someone Help With This Method Stuff /**************************
ID: 649457 • Letter: J
Question
Java Program Can Someone Help With This Method Stuff
/**********************************************************
* Program Name : Practice Coding - Creating Methods
* Author :
* Date :
* Course/Section : CSC111 - 01
* Program Description: This program will act as the driver
* for practice creation methods lab assignment
*
* Methods:
* -------
* Main - manages a student GPA
*
**********************************************************/
public class CreatingMethods
{
static Library myLib;
/**********************************************************
* Method Name : Main
* Author : Professor Scheemaker
* Date : April 01, 2010
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN Creating Methods
* Input employee name
* Input 3 integers
* Call method to format employee name
* Clear screen
* Call a method to return the avg of the three integers
* Call a method to display the name and avg to 2 decimal places
* END Creating Methods
**********************************************************/
public static void main (String [] args)
{
//local constants
//local variables
myLib = new Library(); //instantiate
/******************** Start main method *****************/
//input employee name
//input three integers
//clear screen
//call method to format employee name
//call method to find average of three integers
//call method to display name and average (to 2 decimal places)
}
/**********************************************************
* Method Name : formatName
* Author :
* Date : April 01, 2010
* Course/Section : CSC111 - 01
* Program Description: This method will format a full name
* into phonebook format (Last, First).
*
* BEGIN formatName(fullName)
* convert entire name to lower case
* extract first name from fullName
* extract last name from fullName
* convert 1st letter of first name to capital letter
* convert 1st letter of last name to capital letter
* create formatted full name
* return the formatted full name
* END formatName
**********************************************************/
public
{
//local constants
//local variables
/******************************************************/
}//end calcAvg
/**********************************************************
* Method Name : calcAvg
* Author :
* Date : April 01, 2010
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN Calculate Average(num1, num2, num3)
* calculate average of 3 integer parameters
* return the average
* END Calculate Average
**********************************************************/
public
{
//local constants
//local variables
/******************************************************/
}//end calcAvg
/**********************************************************
* Method Name : dispInfo
* Author :
* Date : April 01, 2010
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN Display the employee info
* format the average to 2 decimal places
* display average on the screen
* END Display the employee info
**********************************************************/
public
{
//local constants
//local variables
/******************************************************/
}//end dispAvg
} //end Creating Methods
Explanation / Answer
Program code:
//import the Scanner class to read the input
//DemicalFormat class to format the average value
import java.util.Scanner;
import java.text.DecimalFormat;
/**********************************************************
* Program Name : Practice Coding - Creating Methods Author : Date :
* Course/Section : CSC111 - 01 Program Description: This program will act as
* the driver for practice creation methods lab assignment
*
* Methods: ------- Main - manages a student GPA
*
**********************************************************/
public class CreatingMethods
{
// since functioning of Library class is not mentioned
// for time being kept in comment form
// static Library myLib;
/**********************************************************
* Method Name : Main Author : Professor Scheemaker Date : April 01, 2010
* Course/Section : CSC111 - 01 Program Description:
*
* BEGIN Creating Methods Input employee name Input 3 integers Call method
* to format employee name Clear screen Call a method to return the avg of
* the three integers Call a method to display the name and avg to 2
* decimal places END Creating Methods
**********************************************************/
/******************** Start main method *****************/
public static void main(String[] args)
{
// local variables
String Name;
int value1, value2, value3;
double average;
// Create a Scanner class object to read input from
// the user
Scanner input = new Scanner(System.in);
// myLib = new Library(); //instantiate
// temporarily not using the call Library so eliminating
// the above line.
/******************** Start main method *****************/
// input employee name
System.out.println("Enter the full name of the person: ");
Name = input.nextLine();
// input three integers
System.out.println("Enter first integer value: ");
value1 = input.nextInt();
System.out.println("Enter second integer value: ");
value2 = input.nextInt();
System.out.println("Enter third integer value: ");
value3 = input.nextInt();
// call method to format employee name
Name = formatName(Name);
// call method to find average of three integers
average = calcAvg(value1, value2, value3);
// call method to display name and average (to 2 decimal places)
dispInfo(Name, average);
}
/**********************************************************
* Method Name : formatName Author : Date : April 01, 2010 Course/Section :
* CSC111 - 01 Program Description: This method will format a full name
* into phonebook format (Last, First).
*
* BEGIN formatName(fullName) convert entire name to lower case extract
* first name from fullName extract last name from fullName convert 1st
* letter of first name to capital letter convert 1st letter of last name
* to capital letter create formatted full name return the formatted full
* name END formatName
**********************************************************/
public static String formatName(String name)
{
// toLowerCase method converts the entire string to lower case
name.toLowerCase();
// local variables
String names[] = new String[2];
// here it calls the split method of string class and stores
// returned array of strings into names
names = name.split(" ");
// here the substring will get the first letter then convert it
// into the Upper case then adds the rest of the string
names[0] = names[0].substring(0, 1).toUpperCase() + names[0].substring(1);
names[1] = names[1].substring(0, 1).toUpperCase() + names[1].substring(1);
return (names[1] + "," + names[0]);
}// end formatName
/**********************************************************
* Method Name : calcAvg Author : Date : April 01, 2010 Course/Section :
* CSC111 - 01 Program Description:
*
* BEGIN Calculate Average(num1, num2, num3) calculate average of 3 integer
* parameters return the average END Calculate Average
**********************************************************/
public static double calcAvg(int num1, int num2, int num3)
{
// local variables
double average = (num1 + num2 + num3) / 3.0;
return average;
}// end calcAvg
/**********************************************************
* Method Name : dispInfo Author : Date : April 01, 2010 Course/Section :
* CSC111 - 01 Program Description:
*
* BEGIN Display the employee info format the average to 2 decimal places
* display average on the screen END Display the employee info
**********************************************************/
public static void dispInfo(String name, double average)
{
DecimalFormat formatter = new DecimalFormat("##.##");
System.out.println(" The details are: ");
System.out.println("Student Name: " + name);
System.out.println("Average: " + formatter.format(average));
}// end dispAvg
} // end Creating Methods
Sample Output:
Enter the full name of the person:
geun-Suk joong
Enter first integer value:
88
Enter second integer value:
65
Enter third integer value:
79
The details are:
Student Name: Joong,Geun-Suk
Average: 77.33
Note: The entire class along with methods definitions are defined.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.