Question

In: Computer Science

Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write...

Java Code:

Write an application that takes in user input. (Name, Age, and Salary)

------

Write an application that includes a constructor, user input, and operators.


Solutions

Expert Solution

Two programs are provided below. Both programs satisfy the conditions you have given in question. Both programs are explained in code comments . Output screenshot is also provided. If you need any further clarification please ask in comments.

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

CODE 1

import java.util.Scanner; //importing to use scanner for taking input

public class Employee {

        //main method
        public static void main(String[] args) {
                
                //variables to hold values
                String name;
                int age;
                double salary;
                //creating object of Scanner to take input from user through System standard input
                Scanner scan=new Scanner(System.in); 
                
                System.out.println("Enter name: ");
                name=scan.nextLine(); //taking string input through scanner nextLine()
                System.out.println("Enter age:");
                age=scan.nextInt(); //taking integer input using scanner nextInt()
                System.out.println("Enter salary:");
                salary=scan.nextDouble(); //taking double input using scanner nextDouble()
                
                //displaying all the variables data
                
                System.out.println("Name: "+ name +" Age: "+ age +" Salary: "+salary);
                scan.close(); //closing scanner
        
        }
}

OUTPUT

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

CODE 2

import java.util.Scanner; //importing to use scanner for taking input

public class Mathematics {
        //private data members of class
        private double x;
        private double y;
        //constructor
        public Mathematics(double num1, double num2) {
                x = num1; //assign value of num1 in x
                y = num2; //assign value of num2 in y
        }
        //function to find sum
        public void sum()
        {
                double result=x+y; //using + operator to find sum
                System.out.println("Sum of "+ x +" and "+ y +" is: "+result);
        }
        //function to find subtraction
        public void sub()
        {
                double result=x-y; //using - opereator to find subtraction
                System.out.println("Subtraction of "+ x +" and "+ y +" is: "+result);
        }
        //function to find division
        public void division()
        {
                double result=x/y; //using / operator to find division
                System.out.println("Division of "+ x +" and "+ y +" is: "+result);
        }

        //main method
        public static void main(String[] args) {
                
                //variables to hold values
                double x,y;
                //creating object of Scanner to take input from user through System standard input
                Scanner scan=new Scanner(System.in); 
                
                System.out.println("Enter value of x: ");
                x=scan.nextDouble(); //taking double input using scanner nextDouble()
                System.out.println("Enter value of x: ");
                y=scan.nextDouble(); //taking double input using scanner nextDouble()
                
                Mathematics obj=new Mathematics(x, y); //creating object of Mathematics class using x and y as parameters
                obj.sum(); //calling sum()
                obj.sub(); //calling sub()
                obj.division(); //calling division()
                scan.close(); //closing scanner
        }
}

OUTPUT


Related Solutions

Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a java code that allows the user to input any word/name from the console (10...
Write a java code that allows the user to input any word/name from the console (10 words/names only) and then sorts and alphabetizes them into an array without using predefined methods (.compareTo(), or any sorter functions) and then print out the results. you must have three methods that can: Compare multiple strings Swap elements Sort and alphabetize string ***REMEMBER DO NOT USE ANY PRE-DEFINED METHODS*** Example of how the code should work: Enter names/words (10 only): "james, john, alex, aaron,...
Your Application should ask the user to enter their name and their salary.
Create a C# Console Application, name the solution Homework 6 and the project TaxRate.Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric...
Code in Java Write a recursive method smallestNumber which takes an ArrayList of Integers as input...
Code in Java Write a recursive method smallestNumber which takes an ArrayList of Integers as input and returns the smallest number in the array. You can use a helper method if needed. Write a main method that asks the user for a series of numbers, until the user enters a period. Main should create an ArrayList of these Integers and call smallestNumber to find the smallest number and print it. Input Format A series of integers Constraints None Output Format...
Write application in C# that enables a user to: Use Methods for user input and calculations...
Write application in C# that enables a user to: Use Methods for user input and calculations input the grade and number of credit hours for any number of courses. Calculate the GPA on a 4.0 scale using those values. Grade point average (GPA) is calculated by dividing the total amount of grade points earned, sometimes referred to as quality points, by the total number of credit hours attempted. For each hour, an A receives 4 grade or quality points, a...
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
Create a Java application that will prompt the user for the first name of 6 friends...
Create a Java application that will prompt the user for the first name of 6 friends in any order and store them in an array. First, output the array unsorted. Next, sort the array of friends and then output the sorted array to the screen. Be sure to clearly label the output. See the example program input and output shown below. It does not have to be exactly as shown in the example, however it gives you an idea of...
Java Programming I need an application that collects the user input numbers into an array and...
Java Programming I need an application that collects the user input numbers into an array and after that calls a method that sums all the elements of this array. and display the array elements and the total to the user. The user decides when to stop inputting the numbers. Thanks for your help!
Write a Java program that will ask the user for his/her salary (numerical integer salary) and...
Write a Java program that will ask the user for his/her salary (numerical integer salary) and then convert this numerical salary into income class. The following is a guideline to the income class used. The numeric range within parenthesis maps to the preceding class. If the user gave you a number greater than 700,000 or less than 10,000, you should print a message that the input is invalid. In this code, DO NOT USE && OPERATOR. You should use if-else....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT