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 program that uses printf, and takes user input to find the name of...
Write a Java program that uses printf, and takes user input to find the name of the File. FileCompare (20) Write a program that compares to files line by line, and counts the number of lines that are different. You can use file1.txt and file2.txt when testing your program, but you must ask for the file names in the input. main Interactively requests the names of the two files, after creating the Scanner for the keyboard. Creates a Scanner for...
Write a Java application that prompts the user for an age. If the age entered is...
Write a Java application that prompts the user for an age. If the age entered is greater or equal to 65, display the statement "Age is greater than or equal to 65"; otherwise display the message "Age is less than 65". If the age entered is less than 18; display the statement "This person is a minor"; otherwise display the message "This person can legally vote. Do not create a class for this application. The code can be created in...
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,...
Using Python, write a simple application that takes user input of plaintext and key, and encrypt...
Using Python, write a simple application that takes user input of plaintext and key, and encrypt the plaintext with Vigenere Cipher. The application should then print out the plaintext and the ciphertext.
Write a java program which asks the user to enter name and age and calls the...
Write a java program which asks the user to enter name and age and calls the following methods: printName(): Takes name as parameter and prints it 20 times using a while loop. printAge(): Takes age as parameter and prints all the numbers from 1 up to age. Write a java program that will print first 10 multiples of 3 in a single line.
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...
Question 1: Write a Java program that prompts the user to input a file name (existing...
Question 1: Write a Java program that prompts the user to input a file name (existing text file), then calculate and display the numbers of lines in that file. Also calculate and display the length of the longest line in that file. For example, if the input file has the following lines: Hello This is the longest line Bye The output should be: The file has 3 lines. The longest line is line 2 and it has 24 characters. Test...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT