Question

In: Computer Science

Java Programming Assignment 6-1 We have covered the “Methods” this week. Apply the concepts that we...

Java Programming

Assignment 6-1

We have covered the “Methods” this week. Apply the concepts that we have learnt in class and come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. You program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to discuss in your “reflection” the advantage of using “methods” – we discussed “re-usability” and “modularity”. Write detail comments on the program.

You need to include all the following:

Static Methods

Library methods and user written methods

Non Static Methods (Class & Object)

Methods with arguments

Methods without arguments

Conditional statements

Loops

For Example: (you could come up with any other program) - use your creativity Welcome to my “multifunction” program.

In this program I have an interactive program to show the use and benefits of “methods” in Java program. You will see a “selection menu” that would allow you to use the program. Choose 1. For your “compound interest calculator” of your “retirement nest” income, 2. For your “Interactive input of Employee attributes and then display of their attributes”, 3. For your…. Thank you for using my “multifunction” program. Have a nice day

Solutions

Expert Solution

Code is provided below along with comments. Output screenshot is provided in the last. A brief not is given about the program and the Methods. Program fullfills all conditions given in question:- loops,conditional statement,methods,with argument without argument,static methods and library methods.If need any further clarification please ask in comments.

################################################################################

Program Description:

This program ask user to provide three choice .One is to calculate salary and other is to use arithmatic calculator. and last option to exit the program. If user wants to calculate salary they can choose the same. it asks for details for finding salary and then priints the employee info with salary. If user select calculator then it gives a sub menu for different function. If user selects Addition then it promts to enter two numbers and finds addition. similarly for other operations.

Use Of Methods:- methods are used for reusability and modularity. We can use methods again and agin so we dont have to write code again and again . this shows the re usable concept of methods. Similarly we have ease of maintenance of code if we have methods.methods also provide modularity by method overloading. We can use the same name but different functionality. Hence use of methods in programming is a good practice as well as beneficial.

######################################################################

CODE---->>

import java.util.Scanner;

public class MyProgram {
        
        //static method to multiply
        public static double multiply(double x,double y)
        {
                return x*y;
        }
        //static method to add
        public static double add(double x,double y)
        {
                return x+y;
        }
        //static method to subtract
        public static double minus(double x,double y)
        {
                return x-y;
        }
        //static method to divide
        public static double divide(double x,double y)
        {
                return x/y;
        }
        //method for salary calacuation
        public static void employeeCalculator()
        {
                Scanner sc=new Scanner(System.in);
                String name="",id="";
                double wage=0;
                double hours=0;
                double total=0;
                
                
                System.out.print("Enter the id of Employee: ");
                id=sc.nextLine(); //read id
                System.out.print("Name of Employee: ");
                name=sc.nextLine(); //read name
                System.out.print("Enter the hourly wage: $");
                wage=sc.nextDouble();
                System.out.print("Enter number of hours Worked: ");
                hours=sc.nextDouble(); //read hours
                total=multiply(hours,wage); //call multiply method to find salary
                System.out.println("\nEmployee:  "+name+"  ID:  "+id+"  Hours:  "+hours+"  Total Salary:  $"+total);
                
        }
        //main  method
        public static void main(String args[])
        {
                char choice='0';
                double x=0,y=0;
                Scanner s=new Scanner(System.in); //scanner to take input
                
                
                while(choice!='3') //until user wants to use program
                {
                System.out.println("\n----What do you want to Use?----");
                System.out.println("1. Press 1 for Employee Salary Calculator");
                System.out.println("2. Press 2 for using Arithmetic Calculator");
                System.out.println("3. Press any other key to exit");
                choice=s.next().charAt(0);
                
                if(choice=='1') //if choice is 1
                {
                        employeeCalculator(); //call the method for employee salary
                }
                
                else if(choice=='2') //if choice is 2
                {
                        //print diffrent options under arithmetic calculator
                        System.out.println("          1. Press A for adding two numbers ");
                        System.out.println("          2. Press B for Subtracting two numbers ");
                        System.out.println("          3. Press C for Multiplying two numbers ");
                        System.out.println("          4. Press D for Dividing two numbers ");
                        System.out.println("          5. Press any other key to go to the main menu ");
                        choice=s.next().charAt(0);
                        
                        if(choice=='1' ||choice=='2' ||choice=='3'||choice=='4') //take input if user want to use the calculator
                        {
                                System.out.print("\nEnter first number: ");
                                x=s.nextDouble();
                                System.out.print("Enter second number: ");
                                y=s.nextDouble();
                        }
                        if(choice=='1') //for add
                        {
                                System.out.println("Addition of "+x+" and "+y+" is: "+add(x, y));
                        }
                        if(choice=='2') //for subtract
                        {
                                System.out.println("Subtraction of "+x+" and "+y+" is: "+minus(x, y));
                        }
                        if(choice=='3') //for multiply
                        {
                                System.out.println("Multiplication of "+x+" and "+y+" is: "+multiply(x, y));
                        }
                        if(choice=='4') //for division
                        {
                                System.out.println("Division of "+x+" and "+y+" is: "+divide(x, y));
                        }
                        
                        else //if user wants to go to main menu
                        {
                                choice='0';
                                continue;
                        }
                        
                }
                else //if user want to exit the program
                {
                        System.out.println("Thank you For Using the program!!!Have a nice Day!!");
                        s.close(); //closing scanner
                        System.exit(0); //exit
                }
                
                }
        }
}

#####################################################################

OUTPUT


Related Solutions

COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered this week. come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. Your program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to...
This week we covered the details of Cellular Respiration. Your assignment this week is in two...
This week we covered the details of Cellular Respiration. Your assignment this week is in two parts. Using Excel (or some other Table creating program) create a table that describes the four sub-steps of cellular respiration. Insert the table into a Word document and provide a discussion of how each sub part contributes to overall process of cellular respiration.
java programming Concepts ArrayList - Collections Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment 1....
java programming Concepts ArrayList - Collections Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment 1. Describe auto-boxing, including why it is useful. (Google for this one) Write a few lines of code that auto-box an int into an Integer, and un-box an Integer to an int. 2. Declare an ArrayList of Strings. Add 5 names to the collection. "Bob" "Susan" ... Output the Strings onto the console using the enhanced for loop. 3. Sort the list using the method...
Java Programming II Homework 2-1 In this assignment you are being asked to write some methods...
Java Programming II Homework 2-1 In this assignment you are being asked to write some methods that operate on an array of int values. You will code all the methods and use your main method to test your methods. Your class should be named Array Your class will have the following methods (click on the method signatures for the Javadoc description of the methods): [ https://bit.ly/2GZXGWK ] public static int sum(int[] arr) public static int sum(int[] arr, int firstIndex, int...
JAVA programming- answer prompts as apart of one java assignment Static static variables static methods constants...
JAVA programming- answer prompts as apart of one java assignment Static static variables static methods constants Create a class Die representing a die to roll randomly. ☑ Give Die a public final static int FACES, representing how many faces all dice will have for this run of the program. ☑ In a static block, choose a value for FACES that is a randomly chosen from the options 4, 6, 8, 10, 12, and 20. ☑ Give Die an instance variable...
Assignment: Finance and Operations This week we look at finance and operations, and apply a bit...
Assignment: Finance and Operations This week we look at finance and operations, and apply a bit of quantitative analysis to the effort. Your assignment is to analyze current financial ratios for a given business. 1. i want amazon.com Inc 2. Search the web for that business’ “Financial Statement.” (You will find many hits for the data.) 3. Select the http://www.morningstar.com/ site offering your company’s financial statement. 4. You will now see a number of financial ratios for your company. Below...
Assignment: Finance and Operations This week we look at finance and operations, and apply a bit...
Assignment: Finance and Operations This week we look at finance and operations, and apply a bit of quantitative analysis to the effort. Your assignment is to analyze current financial ratios for a given business. 1. Think of a specific business you find interesting, i.e. Apple, UTC, Southwest Airlines, etc. 2. Search the web for that business’ “Financial Statement.” (You will find many hits for the data.) 3. Select the http://www.morningstar.com/ site offering your company’s financial statement. 4. You will now...
Assignment: Finance and Operations This week we look at finance and operations, and apply a bit...
Assignment: Finance and Operations This week we look at finance and operations, and apply a bit of quantitative analysis to the effort. Your assignment is to analyze current financial ratios for a given business. 1. Think of a specific business you find interesting, i.e. Apple, UTC, Southwest Airlines, etc. 2. Search the web for that business’ “Financial Statement.” (You will find many hits for the data.) 3. Select the http://www.morningstar.com/ site offering your company’s financial statement. 4. You will now...
Assignment: Finance and Operations: This week we look at finance and operations, and apply a bit...
Assignment: Finance and Operations: This week we look at finance and operations, and apply a bit of quantitative analysis to the effort. Your assignment this week is to analyze current financial ratios for a given business. APA FORMATTING REQUIRED. 1. Think of a specific business you find interesting, i.e. Apple, UTC, Southwest Airlines, etc. 2. Search the web for the business' "Financial Statement". (You will find many hits for the data.) 3. Select the "http://www.morningstar.com/" site offering your company's financial...
Assignment: Finance and Operations: This week we look at finance and operations, and apply a bit...
Assignment: Finance and Operations: This week we look at finance and operations, and apply a bit of quantitative analysis to the effort. Your assignment this week is to analyze current financial ratios for a given business. APA formatting required. 1. Think of a specific business you find interesting, i.e. Apple, UTC, Southwest Airlines, etc. 2. Search the web for that business’ “Financial Statement”. (You will find many hits for the data.) 3. Select the “http://www.morningstar.com/” site offering your company’s financial...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT