Question

In: Computer Science

in Java using netbeans create a project and in it a class with a main. We...

in Java using netbeans

create a project and in it a class with a main.

We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste

import java.util.Scanner;

Part A

☑ In your main method, paste this code.

         Scanner scan = new Scanner(System.in);
        System.out.println("What is x?");
        int x = scan.nextInt();
        System.out.println("What is y?");
        int y = scan.nextInt();
        System.out.println("What is z?");
        int z = scan.nextInt();
        System.out.println("What is w?");
        int w = scan.nextInt();
        
        boolean happy;
        boolean dead;
        
        System.out.println("Are you happy (y/n)?");
        String userhappy = scan.next();

        System.out.println("Are you dead (y/n)?");
        String userdead = scan.next();

☑ After this, if what they enter for userhappy is "y" set happy to true, otherwise to false.

Do the same again to set a value for dead, so that we can better serve our zombie users.

☑ Write single if statements using boolean operators to do as follows:

  • if x, y, and z all have the same value and the user is happy then print "Same and happy"
  • if w is over 12 and the user is both happy and alive then print "Over 12, happy, alive"
  • [EC+10] if x is less than z and both w and y are in the range between x and z, and either the user is happy and dead, or sad and alive then print "Long expression is . . . long"

Solutions

Expert Solution

Sample output:

The screenshots are attached below for reference.

Please follow them for proper indentation and output.

Program to copy:

import java.util.*;
public class Main{
public static void main (String[] args) {

Scanner scan = new Scanner(System.in);//starter code provided
System.out.println("What is x?");
int x = scan.nextInt();
System.out.println("What is y?");
int y = scan.nextInt();
System.out.println("What is z?");
int z = scan.nextInt();
System.out.println("What is w?");
int w = scan.nextInt();
  
boolean happy;
boolean dead;
  
System.out.println("Are you happy (y/n)?");
String userhappy = scan.next();

System.out.println("Are you dead (y/n)?");
String userdead = scan.next();
  
if(userhappy.equals("y"))//check if userhappy is y or not
happy=true;
else
happy=false;
  
if(userdead.equals("y"))//check if userdead is y or not
dead=true;
else
dead=false;
  
if(x==y && y==z && happy )//check the conditions and print appropriate messages on console
System.out.println("Same and happy");
  
if(w>12 && happy && !(dead))
System.out.println("Over 12, happy, alive");
  
if(x<z){
if(w>x && w<z){
if(y>x && y<z){
if((happy && dead) || (!happy && !dead))
System.out.println("Long expression is . . . long");
  
}
}
}
  
}
}


Related Solutions

in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
Part A Java netbeans ☑ Create a project and in it a class with a main....
Part A Java netbeans ☑ Create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class , after the package statement, paste import java.util.Scanner; As the first line inside your main method, paste Scanner scan = new Scanner(System.in); Remember when you are getting a value from the user, first print a request, then use the Scanner to read the right type...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the...
Start NetBeans. Create a new project called Lab7. Create a Java main class file using the class name YourlastnameLab7 with your actual last name. Create a Java class file for a Polygon class. Implement the Polygon class. Add a private instance variable representing the number of sides in the polygon. Add a constructor that takes a single argument and uses it to initialize the number of sides. If the value of the argument is less than three, display an error...
Create a Netbeans project with a Java main class. (It does not matter what you name...
Create a Netbeans project with a Java main class. (It does not matter what you name your project or class.) Your Java main class will have a main method and a method named "subtractTwoNumbers()". Your subtractTwoNumbers() method should require three integers to be sent from the main method. The second and third numbers should be subtracted from the first number. The answer should be returned to the main method and then displayed on the screen. Your main() method will prove...
create a project and in it a class with a main. We will be using the...
create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?"); int w = scan.nextInt();...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read and follow the instructions below, placing the code statements needed just after each instruction. Leave the instructions as given in the code. Declare and create (instantiate) an integer array called List1 that holds 10 places that have the values: 1,3,4,5,2,6,8,9,2,7. Declare and create (instantiate) integer arrays List2 and List3 that can hold 10 values. Write a method called toDisplay which will display the contents...
Using NetBeans, create a Java project named FruitBasket. Set the project location to your own folder....
Using NetBeans, create a Java project named FruitBasket. Set the project location to your own folder. 3. Import Scanner and Stacks from the java.util package. 4. Create a Stack object named basket. 5. The output shall: 5.1.Ask the user to input the number of fruits s/he would like to catch. 5.2.Ask the user to choose a fruit to catch by pressing A for apple, O for orange, M for mango, or G for guava. 5.3.Display all the fruits that the...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT