Rotate Left Bitwise Shift?

May 13, 2014

I'm trying to replicate the rol(rotate left) instruction in assembly though can only get as far as shifting the bits with '<<' or doing Long.rotateLeft(var, 5). Both of these method don't wrap around the bits as the rol instruction does.

View Replies


ADVERTISEMENT

Shift-left Array Values - How To Assign Divisors Indexes To Start

Dec 16, 2014

I am writing a program for a game. It is between the user and a virtual player. The game starts with a pool of consecutive integers 1-100. The size of the pool is based on a random generated number at the beginning of the game. At the start, both players' scores are 0. For each turn, the player picks one number from the pool. That value is added to the player's score, the computer gets the sum of all the remaining numbers in the pool that divide evenly into the player's pick. The player's pick and its divisors are then removed from the pool.

The player should be able to play the game as many times as she wants without ending the program. Instructions should appear on the screen only once at the start of the program.

For each turn, both players' current score, the current pool of numbers, and a prompt for a number to be entered should show onscreen. I have written the code until I get to the function that updates the pool of numbers after a turn.

import java.util.Scanner;
import java.util.Random;
public class SlickPick {
public static void main (String[] args){
Scanner read = new Scanner(System.in);
int []pool = new int[100];

[Code] ....

My thinking is that I need to use the binary search to find the indexes of the divisors array and then use those indexes as the start values. I'm not sure how to assign the divisors indexes to start. Do I need an array for start? Whenever I run the program, the only value missing is 3.

//Name : poolUpdate
//Description : This function modifies the contents of the pool as a result of a turn of play.
//Parameters : The pool array, the divisors array, the size, and the user's pick.
// :
//Return :
public static void poolUpdate(int[] pool, int[] divisors, int size, int pick){
int low=0;
int high=size-1;

[Code] ....

View Replies View Related

How To Type Bitwise Operator Symbol

Jul 6, 2014

It looks like an upside down v , i cant find it on my keyboard. I assume its a keyboard combo.

View Replies View Related

How To Make Shift Encoder / Decoder

Oct 16, 2014

I am working on a project where we need to make a shift encoder/decoder. Right now I am working on my prepareString method, and I have no way of testing it yet. I was just wondering if I wrote it correctly. It should pull in the user entered string and check if each character is a letter, and remove all that are not. Then it should turn all the letters to upper case. Based on that does this look right?

private String prepareString(String plainText)
{
int strLength = plainText.length();
for(int i = 0; i < strLength; i++)
{
char c1 = plainText.charAt(i);
boolean isLetter = Character.isAlphabetic(c1);
if(isLetter == false)

[Code]...

View Replies View Related

Encoding A Message Using Caesar Shift

Feb 9, 2014

I have an assignment, similar to ones of seen in the past. The assignment is to take a users text input and to encrypt it using 3 different types of encryptions: Caesar, Transpose, and Reverser. The professor gave us the bulk of the code, and more specifically how to tokenize and shift the letters using Caeser shift. The problem im coming across is that it is not showing anything past the users input. After running it, it just stays there running without showing anything.

Cipher:

package cipher;
import java.util.Scanner;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
public abstract class Cipher {
public String message;
StringBuilder encrypted_message, decrypted_message;

[Code] ....

The constants have their own separate class, and they appear to work fine. I know that the Transpose and Reverser are incomplete, hence them commented out. But if i cant finish with Caeser first, it wont work at all.

View Replies View Related

How To Create A New Line Feed Character In SHIFT JIS File

Aug 29, 2014

NewLine.PNG

I need creating the end of line character on line 2 of the attached image.

When I try with

and

I get the end of line symbol on line 1. I tried converting ASCII 10 to a character and putting that in the file, but I still get the end of line symbol on line one.

I'm using Sakura as the text editor.

View Replies View Related

Encoder - Possibility Of Shift Being Larger Than Alphabet Array Length

Apr 20, 2015

I have an encoder that will shift the character of a string X places. Im trying to account for the possibility of the shift being larger than alphabet array length. I've come up with the following, but I still get an ArrayIndexOutOfBounds Error and it never gets past the if statement.

private String encryption(char charArrayElement) {
String [] alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
"M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
String str = String.valueOf(charArrayElement);

[Code] ....

View Replies View Related

Rotate Through JTabbedPanels At 5 Second Intervals

Apr 5, 2014

I have a list of Tabs which are dynamic depending on how many cars are in a database. If there are 10 cars there will be 10 tabs called car 1, car 2, car 3, etc. Each tab simply displays a photo and details of the car.

I have a JMenuItem that says start SlideShow and end SlideShow

What i would like to do is automatically slide through tabs when the start Slideshow is clicked.

View Replies View Related

Way To Rotate JPanel In Java

Jul 28, 2014

Is there any way to Rotate jPanel in java (without using Paint Function).

View Replies View Related

Swing/AWT/SWT :: How To Rotate Arrow

Mar 11, 2015

i want to rotate this shape using AffineTransform without changing its position and its size. i want the arrow to be in a straight line. how can i proceed??

I have use this but the place of the arrow is changing.

AffineTransform at = new AffineTransform();
at.rotate(Math.toRadians(45));
c.transform(at);

here is my code for arrow

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

[Code]....

View Replies View Related

Rotate Image In Java?

May 23, 2014

I have been trying to rotate an image on a certain degree, and still remain on the same position. I have tried g.rotate, but it just rotate around a center, and it does not keep the same position as before.

View Replies View Related

Swing/AWT/SWT :: How To Rotate JLabel

Jul 21, 2014

I have written a code to rotate a Jlabel but i am facing some problems.

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import javax.imageio.ImageIO;

[Code] ....

View Replies View Related

BufferedImage Auto Rotate JPG

Apr 11, 2015

I need my Java program (I'm working in Eclipse if it matters) to detect if an image is a portrait or a landscape, but since i am directly downloading them from my camera they only have it written somewhere in metadata, the image width and height is the same for landscape and portrait. I have the rotation code and the rest of the program working, but I need to somehow get a variable (for example integer one) to tell me if it is a portrait or a landscape image. I tried getting to the metadata but my Eclipse decided that import com.drew.metadata.Metadata; cannot be resolved.

BufferedImage image = ImageIO.read(new File(imagePath, imageName)); and after I get the variable "orientation" it looks like this

int orientation = ???;
BufferedImage newImage = oldImage;
if (orientation>1){
newImage = rotate(oldImage);
}

View Replies View Related

How To Rotate Object And Give Colour Inside

Mar 13, 2014

package id.ac.ub.ptiik.computergraphics;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public class CG04_3DTransformation extends CGApplication {
protected boolean wireframe = true;

[Code] .....

View Replies View Related

Rotating A Shape - Graphics2D Rotate (theta) Method

Jun 14, 2014

I am having a problem rotating a shape I am using the transformation rotation matrix and don't seem to be getting the results I expected. Now I know a lot of programmers will just tell me to use the Graphics2D rotate(theta) Method.But I would like to create this ability through writing the code.

package com.trigonometry;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Rotate 2D Square Using Maths Equations Through OpenGL

Feb 23, 2015

So I need to create a square and make it rotate when the letter R is pressed and then make it stop when the letter R is pressed again. I need make it rotate using a maths equation that I can't figure it out myself right this moment.

Code for square:

package lab2;
public class Square {
public double [][] vertices = new double[4][2]; //not good to make this public
public Square(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
vertices[0][0]=x1;
vertices[0][1]=y1;
vertices[1][0]=x2;

[Code] ....

In the Square code there is a method to write an equation to rotate it but I can't figure that part out ....

View Replies View Related

JavaFX 2.0 :: Progress Indicator Doesn't Rotate Anymore (8u20)

Aug 28, 2014

Since the upgrade to JavaFX 8u20 my ProgressIndicator won't rotate anymore when using Caspian style. Is there any workaround for this?
 
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.stage.Stage;
public class TestApp2 extends Application {
    public static void main(String[] args) {
    
[Code] ....

View Replies View Related

Swing/AWT/SWT :: Moving Image Left Or Right

Mar 11, 2014

I can't find any resource on the net about a simple Java code just to move a gif image left or right. I've already accomplished the up, down, and center and they're working fine, thus, I'm still struggling with moving the image left or right. Here's the code.

public class MoveIt extends Applet implements ActionListener
{
private Image cup;
private Panel keypad;
public int top = 10;
public int left = 10;

[Code] ....

I remember in Visual BASIC it's easily achieved by NameOfImage.left = NameOfImage.left - 10 to move left and NameOfImage.left = NameOfImage.left + 10.

View Replies View Related

Drawing Shapes Bottom Right To Top Left

Mar 17, 2014

I am having issues with drawing shapes from bottom right to top left.

Issue:

- g.drawRect() will show like I am calling g.fillRect()
- other shapes will not even show the shape in that area

Needs:

- g.drawSHAPE needs to show and not be filled unless I have my fill checkbox selected

The Program:

- Create a JFrame with a draw panel and a component panel
- have a combobox with shapes that, when selected, will draw that shape in the draw panel
- have a button that, when clicked, will launch JColorChooser to change the color of the drawn shape (draw panel is set to black)
- have a checkbox that, when checked, fills the shape
- have mouse listeners to adjust X and Y and will instantly update the shapes size to where you drag/click/press/release

Code for my drawRect():

Java Code:

// if statement to check if mouse drag X is less than starting X
if(x2 <= x){
if(emptyORfill.isSelected()) // emptyORfill is my JCheckBox
g.fillRect(x2, y, x-x2, y2-y); // x-x2 is the same as Math.abs(x2-x)
else
g.drawRect(x2, y, x-x2, y2-y);

[Code] .....

This is just for my Rectangle. This will show a filled rectangle when both mouse drag X and Y are less then the starting X and Y. If I take this fully functional code and adapt it to drawRoundRect(), the round rectangle wont even show the shape when mouse drag X and Y are less than the starting X and Y but will be fine if one or the other is less than the starting X or Y. NOTE: This same exact code worked on my classmates laptop in her program, but in my program on her laptop it did not. She took out the "else" in the else if's and just made them if statements all the way down and it worked on her laptop in my program, but the same "fix" did not work on my pc.

My mouse listener just sets X and Y values in my Shape class that updates my shape methods. I have an item listener for my comboBox that sets default values when a new selection is made and enables/disables editable on my fill checkbox for certain shapes. My action listener looks for the button click and the checkBox click.

View Replies View Related

How To Identify Up Down Left And Right Keys With Keylistener

Apr 9, 2014

I Want to identify up, down, left and right keys with the keylistener() WHATE NAME DO I IDENTIFY IT WITH

View Replies View Related

Setting Left And Right Node Values

May 6, 2014

I am getting errors when I try setting left and right values (which are String types) for my tree.I tried doing something like:

Node node = new Node("Is it human?", null, null);
node.getLeft().setNode("Is it Zelda?");//the first left Q
node.getRight().setNode("Is it Kirby?");//the first right Q

but that gives me a runtime error of "java.lang.NullPointerException" which points to the line 2. I also tried this:

Node node = new Node("Is it human?", null, null);
node.setLeft(setNode("Is it Zelda?"));//the first left Q
node.setRight(setNode("Is it Kirby?"));//the first right Q

but that gives me another error, pointing to the setNode for both lines 2 and 3,plus it wouldnt make sense since both setLeft and setRight takes in Node types, not String types.

Here is my Node class:

public class Node {
private Node leftPt, rightPt;//left and right pointers for Node
private String node, left, right;
public Node(String node, Node leftPt, Node rightPt){
this.node = node;
this.leftPt = leftPt;
this.rightPt = rightPt;

[code]....

View Replies View Related

JGrasp - Printf Left Justify?

Sep 6, 2014

We're learning printf with JGrasp as the environment at the moment. Heres the problem.

I have a string as this:

String header1 = new String ("Caswell Catering and Convention Service");

as for the printf line, its this:

System.out.printf ("%-5s/n", header 1);

The output is right justified no matter the use of the "-" or without and I can't seem to find the correct thing to do to make it left justified.

View Replies View Related

JPanel Class That Creates Left And Right Panel

Feb 12, 2015

I have a JPanel class that creates a left panel and a right panel. the left panel and right panel both have one button each. What I’m trying to accomplish is when I click on the button in the left panel that it updates the button in the right panel. I have to do this without changing anything in the right panel.Basically I have to have LeftPanel have a way to keep track of an instance of RightPanel and I would have to do this through the JPanel class. But I have no clue where to begin on even accomplishing this.

View Replies View Related

Print With Straight Vertical Line To The Left Instead Of Right

Oct 27, 2014

How can I make this program print so the output looks like this ( ignore the - -- lines ):

--------1

-------21

-----321

---4321

-54321

Instead of:

1

21

321

4321

54321

Java Code:

public class c5e18c {
public static void main(String[]args){
int i;
int j;
for(i = 1; i<=6; i++){
for (j = i; j>=1 ;j--){
System.out.printf(j + " ");
}
System.out.println();
}
} mh_sh_highlight_all('java');
}

View Replies View Related

Type Mismatch For RL Method Which Moves Rows To Left

Feb 16, 2014

I'm trying to make a puzzle that gets the user input and moves the rows either to the left or right, the columns move either up or down depending on what the user wants. The problem I'm getting is a type mismatch for my RL method which moves the rows to the left.

import java.util.*;
import java.io.*;
public class Numbrosia {
static int [][] board = new int [5][5];
public static void main(String[]args){
Scanner scan = null;
try{

[code]....

View Replies View Related

Scan Postfix Expression From Left To Right Using Operand Stack

Apr 13, 2015

package hw9;

import java.util.Scanner;
import java.util.Stack;
public class stack {
public static Integer evaluate(String expression) {
Scanner scanner = new Scanner(expression);
Stack <Integer> operands = new Stack<Integer>();

[Code] ....

When I input my expression which has spaces between characters e.g.:10 2 8 * + 3 -, it worked; when I put expression which may not add space between each char e.g.: 3 14+2*7/, the error showed:

Enter a postfix expression: 3 14+2*7/
Exception in thread "main" java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:102)
at java.util.Stack.pop(Stack.java:84)
at hw9.stack.evaluate(stack.java:22)
at hw9.stack.main(stack.java:45)

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved