Writing A Program To Search Bluetooth Devices

May 2, 2014

Im trying to write a java program to search nearby bluetooth devices.. Im using Bluecove-glp-2.1.0 and bluecove 2.1.0..Im working on Ubuntu 13.04 LTS.I typend a code to get the local Device name..

public class BluetoothSearch {
public static void main(String[] args) {
LocalDevice ld= null ;
String name = ld.getBluetoothAddress();
System.out.print(name);
}
}

this is my code.. It returns me null. doesn't return me the local Device.

View Replies


ADVERTISEMENT

Writing Binary Search Program And Keep Getting Errors

Feb 24, 2014

Java Code:

public class Search
{
public static final int NOT_FOUND = -1;
public static int binarySearch( int [ ] a, int x )
{
int low = 0;
int high = a.length - 1;
int mid;
while ( low <= high )

[Code] ....

I keep getting illegal start of expression at ={-3,10,5,24,45.3,10.5}

It says I have 12 errors and I have tried so many things to fix it and I just don't know what to change to make it work.

View Replies View Related

Writing A Program That Searches Array Using Binary Search

Jul 10, 2014

I'm (failing at) writing a program that searches an array using binary search, but I can't get it to work.

My code so far is this:

Java Code:

package sorting;

import java.lang.*;
import java.util.*;
public class sorteh {
public static void main(String [] args){
int[] array=new int [20]; //creates new array
for (int x=0;x<array.length;x++){ //populates array
array[x]=x*3+1;

[code]...

I copied what a website did for the sorting part, but if I have low=0 and high=19, wouldn't mid not be an int?

View Replies View Related

Bluetooth Client Program To Communicate With Micro Controller

Jan 30, 2014

I use a bluetooth module (dwengo) in combination with a microcontroller (PIC16F877A). I want write a bluetooth client program in java to communicate with the microcontoller. Examples of clients on internet do not work or give errors I cant'n resolve. There is one program ( SampleSPPClient ) that give no errors and shows the bluetooth devices present.

But when I choose my bluetooth module I got an error (Device does not support Simple SPP Service). I think that I have to use an other service of bluetooth but I don't know how to implement. Here is the program I tried to use ....
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Vector;
import javax.bluetooth.DataElement;

[Code] ......

View Replies View Related

Read-in Data From Bluetooth Transmitter

Mar 8, 2014

I have the following code which reads in data from a bluetooth transmitter, however the program is crashing upon read-in. The bluetooth connects to the device just fine, as indicated by the indicator LED on the transmitter. However during the read-in:

void beginListenForData()

is where the exception happens. Specifically, it is at the line

readBuffer[readBufferPosition++] = b;

However I don't know why it is crashing. My transmitter is sending 1 byte (0x02) at 9600 baud every 1 sec for testing purposes.
 
package com.example.bluetoothtest2;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;

[Code] ....

View Replies View Related

Writing A Calculation For A Program?

Sep 8, 2014

I am writing a program in Java where a user adds 1 stamp on a letter for every five sheets of paper in it (or fraction thereof)For example, I if I have 11 sheets of paper, I add 3 stamps. If the total number of stamps is more than 3, they don't send it.

I need to ask the user how many sheets of paper they have, and then calculate the appropriate number of stamps based on the formula above. I just don't know how to write the math formula to calculate this, i'm stuck. So far I have:

package test;
import java.util.Scanner;
public class LetterMailing {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int numSheets;

[Code] .....

What should I do next?

View Replies View Related

Writing A Java Program To PRINT?

Oct 19, 2014

how to print from bluej onto actual paper? how to do the formatting and configuration etc.

View Replies View Related

Writing A Program To Take Input From User?

Oct 23, 2014

Writing a program to take input from user. This input must be done with numbers only. If the input is a string I would like the program to loop and ask for input again.

double depositCheckingAmount;
do
{
System.out.println("Please insert amount to deposit into checking.");

[Code]....

As you can see my attempt is to use the ! expresssion incase the input does not equal a double. Is there another method I should be using?

View Replies View Related

Writing A Program For System Of Linear Equations

Sep 22, 2013

So i was assigned to write a program that would print the answer to the system of two linear equation. the form of ax+by=c and dx+ey=f..I wrote this program, but it is incorrect since I tried it out on my terminal and I keep getting incorrect values.

import java.util.Scanner;
public class Quest4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

Writing A Program To Dynamically Update XML File To Add

Feb 8, 2014

I'm writing a program to dynamically update an xml file to add, delete, and edit entries in the file. I've run into an issue with the add method because when I write into the file, a random letter is added before the line. EX:

I want to add "<item> ..." to the end of the list of entries, but when it is added, this is what is added "Z <item> ..."The spacing for the <item> is correct, however, I don't see where or why the Z is added.

public static void insertItem(Item i)
{
try {
String insert = " <item>";
String text = "";
Scanner in = new Scanner(file);

[code]....

View Replies View Related

Writing A Program That Determines If Number Is Palindrome Or Not

Apr 3, 2015

I'm in the process of writing a program that determines if a number is a Palindrome or not. I'm not allowed to use strings and am required to use the getSize method shown below. I believe my issue that I'm having is that the "num" is not being called in the getSize method, and therefore not running the while loop, or at least that is what I believe is the issue.

import javax.swing.*;
public class getSize{
public static void main( String[] args )
{
int num;
num = Integer.parseInt (JOptionPane.showInputDialog ( "Please input a number" ));

[code]....

View Replies View Related

Factorial - Writing Iterative Program Recursively

Apr 30, 2015

It was quite recently that Data Structures was introduced to me, so I started out writing some iterative programs recursively.I found some strange output which shouldn't have come out but if you take a look at these three codes

long factorial(long n)
{
if(n == 1)
{
return 1;
}
else
{
result = n*factorial(n-1);

[Code] ....

These are three versions of the code, achieving the same objective of obtaining a given number and returning the factorial, but in spite of the changes made to the code, they produce the same result. I needed a reason as to why it is so? I tried to dry run all the codes but at some point or the other I got confused, and had to start all over again and couldn't come up with a proper result.

View Replies View Related

Writing A Program To Test Person Class

Nov 4, 2014

User-defined classes. The concept of getters and setters goes right over my head. Right now we're to write a program to test the Person class below. We have to create 2 instances of the class to test each constructor, and test each method.

class Person {
// Data Members
private String name; // The name of this person
private int age; // The age of this person
private char gender; // The gender of this person
// Default constructor
public Person() {
this("Not Given", 0, 'U');

[code]....

then my output will print out the name. But the assignment doesn't tell us to modify the Person class at all, just to create a tester one.

View Replies View Related

Writing A Program That Converts TXT File To HTML

Nov 26, 2014

I need to convert a .txt file to html text, where the first line is changed to have < h1 > < /h1 > around it and the rest is wrapped in < p > < /p > so for example I read a .txt file that says:

chapter 1

this is a sentence

it would output:

<h1>chapter 1</h1>

<p>this is a sentence</p>

here is what I have so far and I cannot get anything to output.

FileInputStream filestream;
BufferedReader reader;
FileOutputStream output;
String firstline;
String body = "<p>";
String line;

[Code] ......

View Replies View Related

JGrasp - Writing A Program For Ticket Sales

Sep 13, 2014

The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets: box, sideline, premium, and general admission. After each game, the data is stored in a file in the following format:

ticketPrice numberOfTicketsSold

Sample data might look like:

250 5750

100 28000

50 35750

25 18750

The first line indicates that the box ticket price is $250 and that 5750 tickets were sold at that price.

Your program should input in this data (using Scanner or an input dialog box), then output that data to a message dialog box along with total ticket sales information. Output the total number of tickets sold and the total sale amount. Make your output user-friendly and "pretty". Format your output with two decimal places. Use JOptionPane and the formatting techniques learned in chapter 3 for your output. Example output might be:

5750 Box Tickets sold at $250.00
28000 Sideline Tickets sold at $100.00
35750 Premium Tickets sold at $50.00
18750 General Admission tickets sold at $25.00

View Replies View Related

JGrasp - Errors In Writing A Program For Checking And Savings

Sep 19, 2014

Here is the objective of the assignment:

Quote : A bank in your town updates its customers' account at the end of each month. The bank offers two types of accounts: savings and checking. Every customer must maintain a minimum balance. If a customer's balance falls below the minimum, there is a service charge of $10 for savings accounts and $25 for checking accounts. If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:

- Savings accounts receive 4% interest.

- Checking accounts with balances of up to $5000 more than the minimum balance receive 3% interest; otherwise, the interest is 5%.

Write a program that reads a customer's account number (integer), account type (character: s for savings or c for checking), minimum balance that the account should maintain, and the current balance. The program should then output the account number, account type, current balance, and an appropriate message.

Your program should only allow 'c', 'C', 's', or 'S' as valid input, any other character for the account type should result in an error message. Format your monetary output to two decimal places, and use constants for all the above constant values.

Sample output:
Please enter your account number (int), account type (char), minimum balance, and current balance:
46728 S 1000 2700
Account Number: 46728
Account Type: S
You have earned 0.04 interest on your account.
Current Balance: $2808.00

[Code] .....

Invalid account type!

View Replies View Related

Writing A Program To Make A Tic Tac Toe Game Utilizing Inheritance

May 7, 2014

I am new to programming and we are writing a program to make a tic tac toe game utilizing inheritance, client-supplier, arrays, and EventButton. I am still trying to wrap my head around events and inheritance. We are instructed to write 4 classes (a TicTacToeModel, a TicTacToeView, a TicTacToe Controller, and a TicTacToeButton). I got the TicTacToeModel down, but am having trouble with the other classes.

Instructions for View: Write a class that implements the UML class diagram below. The only purpose of this class is to draw a picture of the specified TicTacToeModel. For purposes of this assignment, we understand a ‘theme’ to include such things as the background color of the tic‐tac‐toe board, the shape and color of the X indicator and the shape and color of the O indicator. While you are free to select your own personalized ‘theme’ your TicTacToeComponent must always be proportionally ‘correct’ regardless of the client‐determined width and height of the Component.

Instructions for the Controller: Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will

1) create a TicTacToeModel
2) create a TicTacToeView and
3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided

These are our instructions for the TicTacToeButton: create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game.And this is the code I have thus far for the button:

import java.awt.event.*;
import java.awt.*;
public class TicTacToeButton extends EventButton{
public TicTacToeButton(int x, int y, int w, int h) {
super("Move");
setBounds(x, y, w, h);

[code]....

View Replies View Related

Writing A Pizza Program - Average Cost Of Order

Oct 9, 2014

I'm trying to write a program that will output the total number of large,medium,and small pizza along with the average cost of an order. I'm stuck on this error , "Else without if" on line 48 else ...medium.

import java.util.Scanner;
public class PizzaOrder
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
double cost,total, average;
String name,response,size,type;
int count,l,m,s;

[code]....

View Replies View Related

How To Put Search Bar In Program

Oct 21, 2014

how to put search bar in my program.i am just new to java programming so i dont really master all the codes.i dont have much time

import java.io.*;
import java.util.Scanner;
public class myjavProject{
public static void main(String[] args)throws IOException{
PrintWriter output = null;
String ID;
String firstname;
String lastname;
String ans = "y";
String userinput;

[code]....

View Replies View Related

Writing A Program Using Switch Statement - Allow Users To Choose Item Of A Menu

Oct 5, 2014

Write a program using switch statement to allow users to choose an item of a menu. For example, the menu looks like the following.

File menu
1. Open
2. Close
3. Save
4. Exit
Enter your choice:

If you type 1, then your program should print out "Open is selected" (double quotes not included).

Notice:
(1) Using Scanner to get user choice;
(2) If the number user input is not in {1,2,3,4}, your program should let user know that.

Here's what I have:

public static void main (String[] args) {
int user = 1
switch (1) {
case value: 1
System.out.println ("Open is selected");

[Code] .....

View Replies View Related

Writing Output Of Two Different Java Class Files To One Txt File While Program Runs

Jul 20, 2013

So I am trying to write the output of two different java class files to one txt file while the program runs.  The file name is determined before the program is ran, through the command prompt as arguments.  How can I get the second class file to edit the same txt file without running into compile errors.
 
For right now I'm just going to send everything that the second file outputs to a message String variable, so that the Main class outputs to the the text file.  I still want to learn how to write to the same text file directly from the second class file.
 
import java.io.*;
public class Test{
    public static void main(String[] args) throws IOException{
        int x;
        //create a new file internally called doc.  But externally labelled the user input
        File doc = new File(args[0]);
        if (doc.exists()){

[Code] .....

View Replies View Related

Optimizing Search For Food In Java Program

Apr 21, 2015

I have a java program where there are bacteria that have to eat the food spread for a map, I have to find a way to optimize the search for food, I put random at the beginning I have to try a better way...

protected void Move(){
int dx = (int)(Math.random()*3) - 1;
int dy = (int)(Math.random()*3) - 1;
if (x+dx >= 0 && x+dx<food.getWidth())
x += dx;
if (y+dy >= 0 && y+dy<food.getHeight())
y += dy;

View Replies View Related

Inventory Program - Add / Delete / Modify / Search And Save

Feb 15, 2015

The goal was to add a few buttons an add delete modify search and save. I feel like I have the entire need satisfied. I'm having a few symbol problems which I'm not quite sure how to fix.

My full code is:

import javax.swing.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

[Code] ....

which is directing me towards Prodname on the far right of the if statement. I'm not sure what the problem is. I've double checked my spellings several time for each spot and I cant quite get it.

Everyone has told me but I am aware that I made some bad decisions with the variables being capitalized this was my first go at a program and my instructor didn't let me know that thats the normal way to do it.

View Replies View Related

Java Program To Search Data From Database On Website - IE Cannot Load URL

Jun 23, 2014

I am writing a java program which searchs data from a database on a website , my problem is that the url does not works on IE but works fine in other browsers..

private URL getURL(String selection) {
URL exampleURL = null;
String url = "http://www.example.com/list?keyphrase=";
if (selection.equals("mfcCode")) {
url += getURLcriteria(EditList.get(CurrentListIndex)

[Code] .....

View Replies View Related

Ability To Search A Binary Search Tree And Return The Number Of Probes

Sep 1, 2014

I'm trying to build a method that can search a binary search tree for a specific target and then return the number of probes it took to get there. It seems to me that the best way to do this would be a recursive search method and a counter that tracks the number of calls. But I'm struggling with how to implement this. Here's the code I have so far. what works/doesn't work with the method.

// Method to search the tree for a specific name and
// return the number of probes
public T search(BTNode<T> btNode) {

[Code]....

View Replies View Related

Creating Search Method For Binary Search Tree

Apr 22, 2014

I want to create a search method that returns the frequency of a word in the search method.

public class IndexTree {
private class TreeNode {
TreeNode left;
String word;
int frequency;
TreeNode right;

[Code] .....

View Replies View Related







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