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 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...
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...
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...
JAVA Write code which takes three decimal inputs from the user, creates a circle with a...
JAVA Write code which takes three decimal inputs from the user, creates a circle with a radius equal to the first input and a rectangle with length and width equal to the second and third input respectively, then prints both of these shapes. Sample run: Type a radius: 3.7 Type a length: 4.9 Type a width: 8.6 circle with radius 3.7 rectangle with length 4.9, width 8.6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT