Questions
using java. using eclipse. write a program that asks to enter 3 real numbers using GUI....

using java. using eclipse. write a program that asks to enter 3 real numbers using GUI. print the sum if all 3 numbers are positive, print the product of the 2 positive numbers if one is negative, use one nested if statement. all output should be to dialog and the console. ...... So i have most of this program done, i just cant figure out how to get the product of the 2 positve numbers to print to the console and dialog. Here is what I have so far.... i know the if and else if statements are correct, i just dont know how to get the if and else if to print to console and dialog correctly for the product.

import java.util.Scanner;
import javax.swing.JOptionPane;
public class Project3 {
public static float getFloat(){
  String s = JOptionPane.showInputDialog("Enter a real number");
  return Float.parseFloat(s);
}

public static void main(String[] args) {
  float x = getFloat();
  float y = getFloat();
  float z = getFloat();
  // if all three are positive print the sum
  if(x>0 && y>0 && z>0) System.out.printf("Sum:%8.2f\n", (x+y+z));
  //if two of the three are positive print the product
  else if((x>0 && y>0 && z<0)||(x>0 && y<0 && z>0)||(x<0 && y>0 && z>0));
  System.out.printf("Product:%8.2f",((x*y)||(x*z)||(y*z)));
  
  
  JOptionPane.showMessageDialog(null, "Sum:"+(x+y+z)+"\nProduct:"+((x*y)||(x*z)||(y*z)));
  
  
  Scanner scan=new Scanner(System.in);
  System.out.println("\nEnter 2 real numbers");
  // if both are negative print the quotient
  float a = scan.nextFloat();
  float b = scan.nextFloat();
  if(a<0 && b<0) System.out.printf("Quotient:%8.2f", (a/b));
  JOptionPane.showMessageDialog(null, "Quotient:"+(a/b));
  
  
  System.exit(0);
}

}

In: Computer Science

*I JUST WANT A GENERAL WALKTHROUGH OF HOW TO DO THIS. PSEUDOCODE IS FINE. THANK-YOU. THIS...

*I JUST WANT A GENERAL WALKTHROUGH OF HOW TO DO THIS. PSEUDOCODE IS FINE. THANK-YOU. THIS IS IN C THE PROGRAMMING LANGUAGE.*

The program will require the following structure:

struct _data {                                 

   char *name;

   long number;

};

The program will require command line arguments:

int main(int argv, char **argc) {

       

Where argv is the number of arguments and argc is an array

holding the arguments (each is a string). Your program must catch

any case where no command line arguement was provided and print

a warning message (see below).

You MUST include/use the following functions, defined as follows:

int SCAN(FILE *(*stream)) - this function will open the file/stream

and return an integer indicating how many lines there are. Note that

I need to pass stream, which is a pointer, by reference. So I am

passing this as a pointer to a pointer.

struct _data *LOAD(FILE *stream, int size) - this function will

rewind file, create the dynamic array (of size), and read in the

data, populating the _data struct dynamic array. Note that stream

is passed by value this time. The function then returns the populated

array of struct.

void SEARCH(struct _data *BlackBox, char *name, int size) - this function

will get the dynamic array of struct passed to it, the name we are looking

for, and the size of the array. This function will then search the dynamic

array for the name. See below for examples.

void FREE(struct _data *BlackBox, int size) - this function will free up

all of the dynamic memory we allocated. Take note of the number of times

malloc/calloc were called, as you need to free that same number.

Finally, the data file will be called hw5.data and will be formatted as:

ron 7774013

jon 7774014

tom 7774015

won 7774016

HINTS:

------

Functions that will make things much easier:

getline()

feof()

strtok()

atoi()

SAMPLE RUNS:

------------

Case 1 - No command line argument provided.

[yourname@chef junk]$ ./CS230-5

*******************************************

* You must include a name to search for. *

*******************************************

Case 2 - Provided name is NOT in the list.

[yourname@chef junk]$ ./CS230-5 joe

*******************************************

The name was NOT found.

*******************************************

Case 3 - Provided name is in the list.

*******************************************

The name was found at the 2 entry.

*******************************************

In: Computer Science

Express the following bit patterns in hexadecimal. 01000101011001110100010101100111 10001001101010111000100110101011 11111110110111001111111011011100 00000010010100100000001001010010

Express the following bit patterns in hexadecimal.

  1. 01000101011001110100010101100111

  2. 10001001101010111000100110101011

  3. 11111110110111001111111011011100

  4. 00000010010100100000001001010010

In: Computer Science

Python Questions Suppose we run the Python program my_program.py from command line like this: Python my_program.py...

Python Questions

Suppose we run the Python program my_program.py from command line like this:

Python my_program.py 14 CSC121

Which of the following statement in my_program.py will display CSC121?

A.
import sys
print(sys.argv)
B.
 
 
 
import sys
print(sys.argv[0])
C.
 
 
import sys
print(sys.argv[1])
 
 
D.
import sys
print(sys.argv[2])
  1. from datetime import datetime
    dob = datetime(2015, 1, 1)
     

    Which of the following statements will change year to 2018?

    A.
    dob.year=2018
    B.
     
     
     
    dob.replace(year=2018)
    C.
     
     
    dob = dob.replace(year=2018)
     
     
    D.
    dob.set_year(2018)

10 points   

QUESTION 4

  1. from datetime import datetime
    dob = datetime(2011,12,10)
    today = datetime.now()
    age = today - dob

    What is the type of age?

    A.

    int

    B.

    float

    C.

    datetime

    D.

    timedelta

    Which of the following functions returns integers between 0 and 20 that are divisible by both 2 and 3?

    A.
    def divisible_2_3 ():
        for i in range(20):
            if i % 2 == 0 and i % 3 == 0:
                yield i
    B.
     
     
     
    def divisible_2_3 ():
        for i in range(20):
            if i % 2 == 0 and i % 3 == 0:
                return i
    C.
     
     
    def divisible_2_3 ():
        seq = []
        for i in range(20):
            if i % 2 == 0 and i % 3 == 0:
                yield seq
     
     
    D.
    def divisible_2_3 ():
        seq = []
        for i in range(20):
            if i % 2 == 0 and i % 3 == 0:
                return i

In: Computer Science

Q:Write a Java application which allows the user to enter student information The user will enter...

Q:Write a Java application which allows the user to enter student information

The user will enter full name, address, city, province, postal code, phone number and email in text field controls. The student’s major (Computer Science or Business) will be selected from two radio buttons.
A combo box will display the list of courses for each program whenever the user selects the desired program.
A course will be added to a list box whenever the user selects a course from the corresponding combo box. Make sure that the user cannot add a course several times.
Additional information about the student will be provided from a group of check boxes (such as involvement in various activities, etc).
All the information about the student will be displayed in a text area component. Use simple SWING layout managers, such as FlowLayout, BorderLayout, and GridLayout to create the SWING GUI of this application. Provide the titles for the data that will be displayed in the text area.

Note:I know how to do most of the things from question but i do not know how to implement layouts.

In: Computer Science

Write a program that will guess an integer that the user has picked. Imagine that the...

Write a program that will guess an integer that the user has picked. Imagine that the user will write down a positive integer x on a piece of paper and your program will repeatedly ask questions in order to guess what x is, and the user replies honestly. Your program will start by asking for an int n, and you must have 1 ≤ x ≤ n. After that, the program will successively guess what x is, and the user must tell the computer if x is equal to the guess (entering ’e’), larger than the guess (entering ’l’), or smaller than the guess (entering ’s’). Your program will guess by maintaining a lower bound (initially 1) and upper bound (initially n) and pick the largest integer equal to or smaller than1 the midpoint of the lower bound and upper bound. If the user responds with ’l’ indicating that x is larger, the guess becomes the new lower bound plus one. If the user responds with ’s’ indicating that x is smaller, the guess becomes the new upper bound minus one. If the user responds with ’e’ indicating that x is the guess, your program will report the number of guesses made and terminate execution:

Example 1)

Enter n: 50

Is your number 25? l

Is your number 38?

l Is your number 44? s

Is your number 41? e

Your number must be 41. I used 4 guesses.

Example 2)

Enter n: 9

Is your number 5? s

Is your number 2?

l Is your number 3? s

Error: that’s not possible.

Example 3)

Enter n: -2

Error: n must be positive.

Example 4)

Enter n: 9

Is your number 5? m

Error: invalid input.

Example 5)

Enter n: a

Error: invalid input.

In: Computer Science

In the Python: Note 1: You may not use these python built-in functions: sorted(), min(), max(),...

In the Python:

Note 1: You may not use these python built-in functions:

sorted(), min(), max(), sum(), pow(), zip(), map(), append(), count() and counter().

(7 points) unique.py: A number in a list is unique if it appears only once. Given a list of

random numbers, print the unique numbers and their count. Print the duplicate numbers and

their count.

Sample runs:

Enter the size of the list : 7

[8, 2, 6, 5, 2, 4, 5]

There are 3 unique numbers: 8 6 4

There are 2 duplicate numbers: 2 5

Sample run:

Enter the size of the list : 7

[2, 2, 4, 3, 3, 3, 4]

There are 0 unique numbers:

There are 3 duplicate numbers: 2 3 4

In: Computer Science

Taking a test on "Inheritance" in C++ tomorrow. So far we have learned about classes, structs...

Taking a test on "Inheritance" in C++ tomorrow. So far we have learned about classes, structs and arrays and strings. We will be provided with coding prompts and have to hand write codes that show examples of inheritance (most likely including some of the earlier concepts as well).

I would like some code examples such as this to study and look over with comments please.

In: Computer Science

Write a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public class...

Write a shoppingcartmanager.java that contains a main method for this code in java

Itemtopurchase.java

public class ItemToPurchase {
   // instance variables
   private String itemName;
   private String itemDescription;
   private int itemPrice;
   private int itemQuantity;
   // default constructor
   public ItemToPurchase() {
       this.itemName = "none";
       this.itemDescription = "none";
       this.itemPrice = 0;
       this.itemQuantity = 0;
   }
   public ItemToPurchase(String itemName, int itemPrice, int itemQuantity,String itemDescription) {
       this.itemName = itemName;
       this.itemDescription = itemDescription;
       this.itemPrice = itemPrice;
       this.itemQuantity = itemQuantity;
   }
   // method to set name of the item
   public void setName(String name) {
       itemName = name;
   }
   // method to set price of the item
   public void setPrice(int price) {
       itemPrice = price;
   }
   // method to set quantity of the item
   public void setQuantity(int quantity) {
       itemQuantity = quantity;
   }
   public void setDescription(String description) {
       itemDescription = description;
   }
   // method to get name of the item
   public String getName() {
       return itemName;
   }
   // method to get price of the item
   public int getPrice() {
       return itemPrice;
   }
   // method to get quantity of the item
   public int getQuantity() {
       return itemQuantity;
   }
   public String getDescription() {
       return itemDescription;
   }
   public void printItemPurchase() {
       System.out.println(itemName + " " + itemQuantity + " @ $" + itemPrice + " = $" + (itemPrice * itemQuantity));
   }
   public void printItemDescription() {

       System.out.println(itemName+": "+itemDescription);
   }
}

*******************

shoppingcart.java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ShoppingCart {
   private String customerName;
   private String currentDate;
   private List<ItemToPurchase> cartItems=new ArrayList<>();
   ShoppingCart() {
       customerName = "none";
       currentDate = "January 1, 2016";
   }
   ShoppingCart(String customerName, String currentDate) {
       super();
       this.customerName = customerName;
       this.currentDate = currentDate;
   }
   public String getCustomerName() {
       return customerName;
   }
   public String getDate() {
       return currentDate;
   }
   public void addItem(ItemToPurchase item) {
       cartItems.add(item);
   }
   public void removeItem(String itemName) {
       boolean check = false;
       for (ItemToPurchase item : cartItems) {
           if(item.getName().equalsIgnoreCase(itemName)) {
               cartItems.remove(item);
               check=true;
           }
       }
       if(!check)
           System.out.println("Item not found in cart. Nothing removed.");
   }
   public void modifyItem(ItemToPurchase item) {
       boolean check = false;
       for (ItemToPurchase itemToPurchase : cartItems) {
           if(itemToPurchase.getName().equalsIgnoreCase(item.getName())) {
               cartItems.remove(itemToPurchase);
               cartItems.add(item);
               check=true;
           }
       }
       if(!check)
           System.out.println("Item not found in cart. Nothing modified.");
   }
   public int getNumItemsInCart() {
       int total=0;
       for (ItemToPurchase item : cartItems) {
           total+=item.getQuantity();
       }
       return total;
   }
   public int getCostOfCart() {
       int cost=0;
       for (ItemToPurchase item : cartItems) {
           cost+=item.getPrice()*item.getQuantity();
       }
       return cost;
   }
   public void printTotal() {
       System.out.println(customerName+"'s Shopping Cart - "+currentDate);
       System.out.println("Number of Items: "+getNumItemsInCart());
       System.out.println();
       for (ItemToPurchase item : cartItems) {
           System.out.println(item.getName()+" "+item.getQuantity()+" @ $"+item.getPrice()+" = $"+(item.getQuantity()*item.getPrice()));
       }
       System.out.println();
       System.out.println("Total: $"+getCostOfCart());
   }
   public void printDesciptions() {
       System.out.println(customerName+"'s Shopping Cart - "+currentDate);
       System.out.println();
       System.out.println("Item Descriptions");
       for (ItemToPurchase item : cartItems)
           System.out.println(item.getName()+": "+item.getDescription());
   }
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       System.out.println("Enter Customer's Name:");
       String name=sc.nextLine();
       System.out.println("Enter Today's Date:");
       String date=sc.nextLine();
       ShoppingCart cart=new ShoppingCart(name,date);
       System.out.println();
       System.out.println();
   }
}

In: Computer Science

I'm trying to work with this code that I have. i want to kick the user...

I'm trying to work with this code that I have. i want to kick the user back if they don't enter a number in the specified range but I haven't been able to get a while loop working right.

  1. Write a program name Blackjack_Jr that allows a human user to play a single hand of "blackjack" against a dealer.
  2. Pick two values from 1-10 for the player. These are the player's "cards". These two values must be user inputs
  3. Generate two more values from 1-10 for the dealer. These two values should be randomly generated by your code
  4. Whoever has the highest total is the winner.

public class Blackjack_Jr
{

   public static void main(String[] args)
   {
       int card1;
       int card2;
       int player1;
       int dealer;
       Random rand = new Random();
       int card3 = rand.nextInt(11);
       int card4 = rand.nextInt(11);
       Scanner in = new Scanner(System.in);
      
       System.out.println("Blackjack Jr!");
       System.out.println();
       System.out.print("Pick Your First Card from 1-10: ");
       card1 = in.nextInt();
       System.out.print("Pick Your Second Card from 1-10: ");
       card2 = in.nextInt();
       System.out.println();
       player1 = card1 + card2;
       dealer = card3 + card4;
          
       System.out.print("You have entered " +card1);
       System.out.println(" and " +card2);
       System.out.println("Your total is: " +player1);
       System.out.println();
              
      
              
       System.out.print("The dealer has drawn " +card3);
       System.out.println(" and " +card4);
       System.out.println("The dealer's total is: " +dealer);
              
           if(player1 > dealer)
           {
               System.out.println("Congratulations! You Won!");
           }else
           {
               System.out.println("Sorry you have lost. :-(");
           }
      
      

   }

}

In: Computer Science

Create a class Person with two instance variables of type String called firstName and LastName, an...

Create a class Person with two instance variables of type String called firstName and

LastName, an instance variable of type int called age, an instance variables of type int

called height (measured in inches), and an instance variable of type double called weight.

Define an appropriate constructor that takes initial values for all instance variables and

calls the corresponding set methods. Define get and set methods for all instance variables.

All set (mutator) methods should validate that reasonable data is being passed to the

object.

Then create a test application that queries the user for information and uses that

information to create two objects of type Person. The application should display all

information about both objects.

language : java

In: Computer Science

Fuzzy logic modeling has many advantages over the conventional rule induction algorithm. For the discussion forum,...

Fuzzy logic modeling has many advantages over the conventional rule induction algorithm. For the discussion forum, you work in the admissions office of a University. There are a large number of applicants to the University. You classify them into three clusters-admitted, rejected, and those who should be admitted. For the third cluster, how would you handle this taking into consideration the fuzzy logic modeling? Would ranking be a consideration?

need 300 words with no plagrism

In: Computer Science

Write a method called "twoStacksAreEqual" that takes as parameters two stacks of integers and returns true...

Write a method called "twoStacksAreEqual" that takes as parameters two stacks of integers and returns true if the two stacks are equal and that returns false otherwise. To be considered equal, the two stacks would have to store the same sequence of integer values in the same order. Your method is to examine the two stacks but must return them to their original state before terminating. You may use one stack as auxiliary storage.

import java.util.Enumeration;

import java.util.LinkedList;

import java.util.Queue;

import java.util.Stack;

//Name,Class,Date..etc.. Header

public class Assignment6 {

public static void main(String[] args) {

//testSeeingThreeMethod();

//testTwoStacksAreEqualMethod();

//testIsMirrored();

}

public static void seeingThree(Stack<Integer> s) {

/*********Write Code Here************/

}

public static boolean twoStacksAreEqual(Stack<Integer> s1, Stack<Integer> s2)

{

/*********Write Code Here************/

}

public static boolean isMirrored(Queue<Integer> q) {

/*********Write Code Here************/

}

private static void testIsMirrored() {

Queue<Integer> myQueueP = new LinkedList<Integer>();;

for (int i = 0; i < 5; i++)

{

System.out.print(i);

myQueueP.add(i);

}

for (int i = 3; i >= 0 ; i--)

{

System.out.print(i);

myQueueP.add(i);

}

System.out.println();

System.out.println(isMirrored(myQueueP) + " isMirrord");

}

private static void testTwoStacksAreEqualMethod() {

Stack<Integer> myStack1 = new Stack<Integer>();

Stack<Integer> myStack2 = new Stack<Integer>();

Stack<Integer> myStack3 = new Stack<Integer>();

Stack<Integer> myStack4 = new Stack<Integer>();

for (int i = 0; i < 5; i++)

{

myStack1.push(i);

myStack2.push(i);

myStack4.push(i);

}

for (int i = 0; i < 6; i++)

{

myStack3.push(i);

}

System.out.println(twoStacksAreEqual(myStack1,myStack2) + " Same Stack

");

System.out.println(twoStacksAreEqual(myStack3, myStack4) + " Not Same

Stack");

}

private static void testSeeingThreeMethod() {

Stack<Integer> myStack = new Stack<Integer>();

for (int i = 0; i < 5; i++)

{

myStack.push(i);

}

System.out.println();

print(myStack);

seeingThree(myStack);

print(myStack);

}

private static void print(Stack<Integer> s) {

Enumeration<Integer> e = s.elements();

while ( e.hasMoreElements() )

System.out.print( e.nextElement() + " " );

System.out.println();

}

} //end of Assignment6

In: Computer Science

Description For this part of the assignment, you will create a Grid representing the pacman’s game...

Description For this part of the assignment, you will create a Grid representing the pacman’s game grid by using a 2D array of Strings as shown in Section 1. Also, you will design the functionality of the pacman as described in Section 2 and represent it in the grid. 1 The Grid The dimensions of the grid is 15 x 15 and the gird is composed of 4 boundaries: north, south, east, and west boundaries as shown in the Figure. The grid has the following characteristics: 1. The boundaries are represented with “X”, and this will block the pacman. 2. There may be obstacles that obstruct the pacman’s movement. 3. There are 4 gates represented with “ ”, and these gates communicates with the opposite gate. E.g., the north gate communicates with the south gate, and the east gate communicates with the west. This means that if the pacman is located in the north gate, next time it moves up will appear in the south gate, similar with the east and west gate. 4. The grid contains cookies represented with “.”. The idea is to collect all the cookies from the grid in order to win the game. Every time the the pacman eats a cookie, the cookie disappears. The Grid has the following fields • grid: is a 2D array of Strings • x-pos: the x-coordinate where the pacman is located • y-pos: the y-coordinate where the pacman is located • counter: a counter that represents the total number of cookies consumed by the pacman In addition, the Grid has the following methods: • initializeGrid(): This method will print a “fresh” new grid with the pacman located in the middle of the grid and the rest of the grid will contain cookies “.”. Except the boundaries of the grid. Your maze shall have four boundaries i.e., north, south, east, and west. The boundaries are represented with an “X”. Each boundary has a gate in the middle that allows the pacman to communicate to the opposite gate. • updateGrid(): will happen after the selection of moving “a”,“s”,“d” or “w” is done. Since these four options will move to west, south, east, or north, then you need to “update” the grid. The way to do this is by passing the x-coordinate and the y-coordinate as arguments to this method. The method then, will update the new position of the pacman (that is, the x and y coordinate from the arguments). Here is where the previous x and y position of the pacman will “disappear” (which is now a blank space “ ”). This method will reflect the new position of the pacman in the grid in case it moved. This method will also reflect the number of cookies consumed. • checkBoundaries(): Before moving the pacman to the new position, this method will check if is possible according the current coordinates. In case is a valid movement, the method will return true. In case the movement is invalid, due to a boundary or through something else, then your method will return false. The Pacman The pacman has the following characteristics: • The pacman has the ability to move through the gates (i.e., north to south, east to west). • The maze is full of cookies (e.g., “.”). The pacman must eat all the cookies to finish the game. Every time the pacman eats a cookie, it disappears from the maze the counter increases by 1. • If pacman movesUp by typing the key w, the pacman’s y-coordinate must increase by one unit. If the pacman’s y-coordinate exceeds the maze’s upper boundary, then the pacman’s y-coordinate AND the maze’s position shall not be updated. • If pacman movesDown by typing the key s, the pacman’s y-coordinate must decrease by one unit. If the pacman’s y-coordinate exceeds the maze’s lower boundary, then the pacman’s y-coordinate AND the maze’s position shall not be updated. • If pacman movesRight, by typing the key d, the pacman’s x-coordinate must increase by one unit. If the pacman’s x-coordinate exceeds the maze’s right boundary, then the pacman’s x-coordinate AND the maze’s position shall not be updated. • If pacman movesLeft, by typing the key a, the pacman’s x-coordinate must decrease by one unit. If the pacman’s x-coordinate exceeds the maze’s left boundary, then the pacman’s x-coordinate AND the maze’s position shall not be updated. Notice that by moving through the y-coordinate the program deals with the rows of the array, similar when dealing with the x-coordinate, the program deals with the columns of array. 3 The Game Engine In order to simulate a game, you must have an engine that keeps looping the position. This is exactly what happens in the old movie theater when they have the 35mm projectors. Here, we will simulate the same idea with a loop: 1. import java.util.Scanner; 2. public class Engine{ 3. public static void main(String [] args){ 4. String[][] grid = new String[10][10]; 5. int col = 5; 6. initializeGrid(grid); 7. grid[5][col] = "P"; 8. Scanner input = new Scanner(System.in); 9. while(true){ 10. print(grid); 11. String option = input.nextLine(); 12. if(option.equals("d")){ 13. // code goes here 14. } 15. // more code goes here 16. } 17. } 18. // methods go here 19. } In Line 4, will create a grid of 10 x 10 of Strings. In Line 7 will store the pacman (’P’) in the middle of the maze. In Line 9 will allow to run your program “forever” until you decide to finish your program. Line 11 will wait for the input from the user to move the pacman (i.e., “a”, “s”, “d”, or “w”). A complete engine can be found in Grid.java.

In: Computer Science

How does the RDBMS support Business Intelligence Applications?

How does the RDBMS support Business Intelligence Applications?

In: Computer Science