cgeier 187 Junior Poster

Prevent user from entering the same number twice (duplicates).

Largest.java

import java.util.Scanner;

class Largest//finds largest value
{
    
  //constructor
  public Largest(){

  } //end constructor
  
  //finds the largest integer
  public void findLargest()
  {
  //create Scanner to input
  Scanner input = new Scanner(System.in);

  //set variables
  int [] numbers = new int [10]; //number of integers
  int x; //counter
  int largestNumber; //largest integer
  int userData; // integer entered by user
  boolean numberExists = false;

  //initialization phase
  largestNumber = 0;//initilize

  //processing phase
    
    System.out.println("You will be prompted for 10 numbers.");
    //initialize counter "x"
    x=0;
    while (x<10)
    {

      System.out.print("Enter a number[" + x + "]:");//prompt for integer
      userData=input.nextInt ();//input next integer
      
      for (int y=0; y<=x;y++)
      {
          //see if the integer already exists in the array
          //we only need to check up to the last number entered
          //by the user so we say "y<=x"

          //don't need to check if this is the first number
          if (x !=0)
          {
            if (numbers[y] == userData)
            {
              numberExists = true;
              
              System.out.println("This number was already entered: " + userData);
              System.out.println("Please choose a different number.");
            }
          }
      }

      if (numberExists == false)
      {
        //this is a unique number, so store it in the array
        numbers[x] = userData;

        //initialize largestNumber to first number entered by user
        if (x == 0)
        {

          largestNumber = numbers[0];
        }

        //if any other numbers are larger than the 1st one entered
        //replace with the new largest number
        if (numbers[x] > largestNumber)
        {
          largestNumber = numbers[x];
        }

        x = x + 1;
      }
      else
      {
          //reset numberExists to false …
cgeier 187 Junior Poster

You probably want to do something like the following. Remember to keep track of your variable names and data types. Also, don't name any of your variable names the same as the class name. This version does not prevent duplicates or prevent strings from being entered--error handling is a more "advanced" topic.

Largest.java

import java.util.Scanner;

class Largest //finds largest value
{
    
  //constructor
  public Largest(){

  } //end constructor
  
  //finds the largest integer
  public void findLargest()
  {
  //create Scanner to input
  Scanner input = new Scanner(System.in);

  //set variables
  int [] numbers = new int [10]; //array of integers
  int x; //counter
  int largestNumber; //largest integer

  //initialization phase
  largestNumber = 0;//initilize

  //processing phase
    
    System.out.println("You will be prompted for 10 numbers.");
    
    for (x=0; x<10; x++)
    {
      //prompt for integer
      System.out.print("Enter a number[" + x + "]:");
      numbers[x]=input.nextInt ();//input next integer
    
      //initialize largestNumber to first number entered by user
      if (x == 1)
        largestNumber = numbers[0];

      //if any other numbers are larger than the 1st one entered
      //replace with the new largest number
      if (numbers[x] > largestNumber)
        largestNumber = numbers[x];

    }//for loop ends

    //print out largest number
    System.out.printf("The largest number is %d \n", largestNumber);
  }//end method findlargest


} //end class Largest

LargestTest.java

public class LargestTest
{
  public static void main(String[] args )
  {
    Largest myLargest = new Largest();
    myLargest.findLargest();
  //myLargestTest.displaylargestTest();
  }//end main
}//end class LargestTest
cgeier 187 Junior Poster

Don't think you can do this:

....
//set variables
int [] counter = new int [10]; //number of integers

//processing phase
while([] counter <= 10);//loop 10 times
{ 
.....

I've never seen anyone try to write a statement like that. Don't think that is valid syntax:

while([] counter <= 10);

Also, you are trying to compare an array to an integer. You can't compare an entire array to a single integer. You could however compare an array element to an integer:
while (counter <=10)

Probably not what you are trying to achieve. You probably just need to do the following:

int counter; //number of integers
....
while (counter <= 10)
{
...

counter = counter + 1; //increment counter
}

cgeier 187 Junior Poster

Store the random number in a variable. Then search the array for the randomly generated number. If it is found, generate another random number. Repeat until random number does not exist in the array.

cgeier 187 Junior Poster

Opening with a new buffered reader, opens the file again. You may want to read your file data into an ArrayList and then work with it--depending on how large your file is I suppose.

If you really want to work directly with the file and be able to change file pointer position use "java.io.RandomAccessFile":
http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html


To time your function use: "System.currentTimeMillis()". Store the "start time" and "end time". Subtract the two and you'll have your execution time.

Also see the following article about performance tuning: http://java.sun.com/developer/technicalArticles/Programming/PerfTuning/

cgeier 187 Junior Poster

If you have a floppy drive you can get the XP boot disks here:
http://support.microsoft.com/kb/310994

cgeier 187 Junior Poster

Looks like you've made progress. There are many ways to accomplish a task. Here's something that may help. Use what you can for ideas. Sorry about the formatting.

import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JOptionPane;

    //create array list of type StudentClass
    ArrayList<StudentClass> studMasterArray = new ArrayList<StudentClass>();

    ArrayList<StudentClass> studTransArray = new ArrayList<StudentClass>();

    //used to keep track of record number when pressing "previous" or "next"
    int recordNumber = 0;

    //used to keep track of how many array elements/students we have
    int recordCount = 0;

   //used to keep track of order
   String orderBy = "";

    public void addDefaultData() {
        String[] defaultNames = {"Alvin Du", "Ryan Gosden", "Michelle Dowling", "Toni Dowling", "Romeo Jones"};
        int[] defaultID = {153679, 417950, 234512, 762903, 200120};

        //clear array of any previous data
        studMasterArray.clear();
       

        for (int i = 0; i < defaultNames.length; i++) {
            recordCount = recordCount + 1;

            //need to create new Nstudent for each loop
            //otherwise all data will = the last student entered

            StudentClass Nstudent = new StudentClass();

            Nstudent.setStudentID(defaultID[i]);
            Nstudent.setStudentName(defaultNames[i]);

        
            studMasterArray.add(Nstudent);


           // tranList.addElement(defaultNames[i] + "     " + defaultID[i]); //adds arrays to JList
        }

        displayData(studMasterArray,masterJlist);
        
        statusLbl.setText("Default Records Loaded!");

    }

    //------------------------------------------------------------------

    public void orderRecordsByID(){
        statusLbl.setText("Sorting by id...");
        //set global variable value so we can keep track how newMasterJlist 
        //is ordered
        orderBy = "id";
 
        displayData(bubbleSort(studMasterArray,orderBy),newMasterJlist);
    }
    //------------------------------------------------------------------

    public void orderRecordsByName(){
        statusLbl.setText("Sorting by name...");
        //set global variable value so we can keep track how newMasterJlist 
        //is ordered
        orderBy = "name";

        displayData(bubbleSort(studMasterArray,orderBy),newMasterJlist);
    }
    //------------------------------------------------------------------
   

    private ArrayList<StudentClass> bubbleSort(ArrayList<StudentClass> arrayToSort, String sortBy)
      {
           //create a new arrayList to hold the sorted values
           ArrayList<StudentClass> sortedList …
cgeier 187 Junior Poster

Here's an example of printing to a jList:

private void displayData(ArrayList<StudentClass> myArrayList){
        String userData = "";

        //needed for jList
        Vector studentData = new Vector();

        //clear the jList box
        jList1.clearSelection();


        //add student data to vector
        for (int i=0; i<myArrayList.size();i++){
            studentData.add(myArrayList.get(i).getStudentID() + " " + myArrayList.get(i).getStudentName());
        }


        //if data exists add to jList, otherwise just leave it empty
        if (myArrayList.size() >0){
            jList1.setListData(studentData);
        }
        
    }
cgeier 187 Junior Poster

http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.18.1

<i>15.18: ...If the type of either operand of a + operator is String, then the operation is string concatenation....If only one operand expression is of type String, then string conversion is performed on the other operand to produce a string at run time. The result is a reference to a String object (newly created, unless the expression is a compile-time constant expression (§15.28))that is the concatenation of the two operand strings.
</i>
Also look at section 15.18.1.3

Additionally see:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

-----------------------------------------------
How does this apply?
In "addTransactionDefaultData" you have the following statement:

tranList.addElement(defaultNames+" "+defaultID+" "+defaultTType); //adds Object Array to JList


Since you use the "+" (string concatenation) operator, it results in a String.

Then in "bubbleSort" you do the following:
if (((StudentClass) tranList.get(i)).getStudentID() > ((StudentClass) tranList.get(j)).getStudentID())

-----------------------------------------------
"(StudentClass)" is a casting operation. It "casts" the following statement to that type.
The rest of the statement would probably thow a compiler error too, because you stored a String in tranList and "getStudentID" isn't a String method--it is a method in your StudentClass. I believe the compiler only reports the first error it finds on any given line.

So, to eliminate the compile error in your "bubblesort" change the following line from:

if (((StudentClass) tranList.get(i)).getStudentID() > ((StudentClass) tranList.get(j)).getStudentID())

TO:

if (tranList.get(i).compareToIgnoreCase(tranList.get(j)) )

This should eliminate the compile error. Will it make your program work? …

cgeier 187 Junior Poster

I think that you probably want to use a vector. If you just print out the e-mail address right away and forget about it, you'll never be able to check for duplicates. So, each time you "find" an e-mail address see if it already exists in the vector. If not add it to the vector, if it does, then do not add it to the vector. When you are finished with the file, close it and print out the vector (which contains your e-mail addresses) to the console. The nice thing about vectors is that you can resize it each time you need to add another e-mail address--this way you don't have to try to guess what size you should make it.

For more information on vectors, see: http://www.mochima.com/tutorials/vectors.html

In order to compare e-mail addresses to see if they are the "same", you may need to use something like "toupper" or "tolower". I found this post on how to convert a string to all lower case: http://www.daniweb.com/forums/thread57296.html . Once both strings are all lower (or upper) case you can compare them. You may want to use a temporary variable for comparison but store the e-mail address how it originally existed in the file.

cgeier 187 Junior Poster

You need to follow your code--execute your code on paper. Follow line by line and write down on paper what the values are for the variables. For example: if (i <= day). You set i=1. So unless the user enters a value for day of "0" this will always get executed. If a someone worked "0" days, then there is no reason to run this program. No work = no pay.

I didn't look through/correct all of your code, but I've modified your code a bit to help you along.

#include <stdio.h>

int main()
{
    int day;
    int i = 1;
    //wHours should be float because people work partial hours sometimes
    float wHours;
    //hRate should be float because people aren't paid only in whole dollar amounts 
    float hRate;
    float total = 0.0;
    float cTax,gross,salary,nSalary,aTotal;
    float tax = .12;
    
    printf("Enter Hourly Rate: ");
    scanf("%f",&hRate);
    printf("Enter number of days you've worked: ");
    scanf("%d",&day);
    

    while (i <= day)
    {
        printf("\nEnter number of hours you worked in  Day %d:  ",i);
        scanf("%f",&wHours);

        if (wHours > 8.0)
        {
             //what do you want to do if wHours > 8 ???

        }
        else
        {
             salary=wHours*hRate;
        }

        printf("\nYour salary for  day %d is %.2f  \n",i,salary);
        i=i+1;
        total=total+salary;
         
    }
   

    aTotal = total;
    printf("\nYour weekly gross salary is %.2f", aTotal);  
    cTax =tax*total;                
    printf("\n\n the tax is %.2f",cTax );
    gross=aTotal-cTax;
    printf("\n\n weekly net salary is %.2f", gross);
    
    
    getchar();
    getchar();
}
cgeier 187 Junior Poster

Think you need to enable/use TCP/IP. This particular article references SQL Express, but it probably also applies to SQL Server 2005.

The following info is from:

http://support.microsoft.com/kb/910229

3.1 Service Account and Network Protocols

For SQL Server Express, the Local System Account is Network Service Account.

SQL Server Express listens on local named pipes and shared memory. With a default installation, you cannot remotely connect to SQL Server Express. You will need to enable TCP/IP and check if the firewall is enabled.


3.1.1 To enable TCP/IP, follow these steps:


From the Start menu, choose All Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Configuration Manager.
Expand SQL Server 2005 Network Configuration, and then click Protocols for InstanceName.
In the list of protocols, right-click the protocol you want to enable, and then click Enable.
The icon for the protocol will change to show that the protocol is enabled.


3.1.2 To enable the firewall, follow these steps:


Click Start, click Control Panel, and then click Network Connections.
From the navigation bar on the left, click Change Windows Firewall settings.
On the Exceptions tab, in the Programs and Services box, you will probably see that SQL Server is listed, but not selected as an exception. If you select the check box, Windows will open the 1433 port to let in TCP requests. …

cgeier 187 Junior Poster

I think that we need to know what is meant by "doesn't boot". The boot process consists of a lot of pieces. Things such as loading BIOS, memory checks/tests, detecting boot devices, loading device drivers, etc. See http://technet.microsoft.com/en-us/library/bb457123.aspx for more information.

Need to make sure that the boot order in the BIOS is correct. The option should be set to boot off of CD/DVD BEFORE it tries to boot from hard drive.

Press the "Esc" key as soon as the computer starts to boot to see the screens. Do you see anything on the screen? Does it pass the memory test?

cgeier 187 Junior Poster

Use your XP CD to enter the Recovery comand prompt screen, and then run "chkdsk".

cgeier 187 Junior Poster

Please post more information about the requirements for your program. Also more about how the data should look during different stages of the program execution as well as explanations as to why the data should look that way. It'd also be nice if you could show how the data is supposed to look (or how you think it looks) inside the arraylist (including data types).

cgeier 187 Junior Poster

Sorry about the code formatting. You have multiple things going on:

In "addDefaultData" you give the impression that "studTranArray" is a record.
Ok, records/struct don't really exist in Java so you can use a class to
try to achieve something similiar.

You do the following:

String [] defaultNames = {"Alvin Du","Ryan Gosden","Michelle Dowling","Toni Dowling"};
int [] defaultID = {153679,417950,234512,762903};

Nstudent.setStudentName(defaultNames);
Nstudent.setStudentID(defaultID);

studTranArray.add(Nstudent);


------------------------------------------------------------------------------
You declare "studTranArray" as follows:
ArrayList studTranArray = new ArrayList();

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

then in "addRecord", you do the following:
studTranArray.add(iD.getText());
studTranArray.add(nameSur.getText());

you are mixing what should probably be integer data (ID) with
String data (name). You need to keep your id's separate from
the names. Looks like you started to do this in "addDefaultData".
----------------------------------------------------
in "sDemoButtonActionPerformed" you call:
sort.bubbleSort(studTranArray );

but you declare "bubbleSort" as follows:

static int bubbleSort(ArrayList <Integer> sortedList)

------------------------------------------------------
Looks like you added "String" data to the array list and told
bubblesSort that you were going to pass it an "Integer" array list.

Even if you remove "<Integer>" from your bubbleSort declaration,
you can't compare String data with ">" or "<". You have to use
"compareTo" or "compareToIgnoreCase".

-------------------------------------------------------
I would recommend creating a separate class that separates the student data:


package assignment2009;

public class StudentClass {

        public StudentClass() {
    }


    protected String studentName;
    protected int
cgeier 187 Junior Poster

You can use "localhost", but I would make it a "configurable" option. What if they decide to move the database to another computer? Place all user configurable options in a file (text or binary)--in essence make your own ".ini" file. Then read the values from file either when the program is loaded or before trying to connect to the database. Obviously you also need to build an interface that will allow the user to update/change the necessary information. If I it was me, I would make it so that it is easy to add support for different databases. See http://www.connectionstrings.com for connection string info for other databases. Also if you don't really have concurrent transactions occurring you may consider using SQL Server Compact edition providing you meet the requirements of their "Terms and Conditions"--it is a free download from the Microsoft website.

cgeier 187 Junior Poster

Some of the following I found on these websites, I've ordered it in the way that I think that may apply best to your situation:

http://v4.windowsupdate.microsoft.com/troubleshoot/
http://www3.telus.net/dandemar/updtcl.htm
http://support.microsoft.com/?kbid=193385

Verify the following services are running. Set them to "automatic" and start them if they aren't:

    -Automatic Updates
    -Background Intelligent Transfer Service
    -Cryptographic Services
    -Remote Procedure Call (RPC)
    -System Restore Service

One way to do this is to go to: Start -> Run -> type “services.msc”

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

Internet Explorer:

Add the following URLs to your Internet Trusted sites list in Internet Explorer: 
       *.windowsupdate.microsoft.com
       *.windowsupdate.com
       *.microsoft.com

-------------------------------------------------------
Verify Internet Explorer connection settings
-Open Internet Explorer
-Go to Internet Options (in older IE versions, Tools -> Internet
     Options)
-Click "Connections."
-Click "LAN Settings."  
-Delete anything in the Automatic Configure text box and clear the "Use automatic configuration script" check box.

-------------------------------------------------------
Set Advanced Internet Explorer options:
 
    -Open Internet Explorer
    -Go to Internet Options (in older IE versions, Tools -> Internet
     Options)
    -Click on “Advanced” tab
    -Check the "Use HTTP 1.1" check box. 
    -Check the "Use HTTP 1.1 through proxy connections" check box.
    -Uncheck “Check for server certificate revocation”
    -Restart Internet Explorer

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

Check your Internet Explorer security settings 

- In Internet Explorer click "Tools," and then click "Internet Options."
- Click "Security."

If using  "Custom Level."
    - Make sure that "File Download" is enabled.
    - Make sure that "Run Active X controls and plug-ins" is enabled.
    - Make sure that "Active Scripting" is enabled.
    - Set your …
cgeier 187 Junior Poster
String nameOfEmployee = "";
        String strRateOfPay = "";
        double dblRateOfPay  = 0;

        System.out.println("Enter employee name (type 'stop' to exit): ");
        InputStreamReader kbInput = new InputStreamReader(System.in);
        BufferedReader brIn = new BufferedReader(kbInput);


            do {
                try {
                    nameOfEmployee = brIn.readLine();

                    if (nameOfEmployee.equalsIgnoreCase("stop"))
                    {
                        break;
                    }
                } catch (IOException ex) {
                    System.err.println(ex);
                }

                try {
                    System.out.println("Enter employee pay rate: ");
                    strRateOfPay = brIn.readLine();
                    if (strRateOfPay.isEmpty())
                    {
                        dblRateOfPay = 0;
                    }
                    else
                    {
                        dblRateOfPay = Double.parseDouble(strRateOfPay);
                    }

                } catch (IOException ex) {
                    System.err.println(ex);
                }

                if (!(nameOfEmployee.equals("stop"))){
                    System.out.println("Name: " + nameOfEmployee);
                    System.out.println(dblRateOfPay);

                    System.out.println("Enter employee name (type 'stop' to exit): ");
                }

          } while (!(nameOfEmployee.equalsIgnoreCase("stop")));

    }
cgeier 187 Junior Poster

By default, the Windows Update client records all transaction information to the following log file:

%windir%\Windowsupdate.log

(to find the value of %windir%, open a cmd/command window (Start -> run -> cmd) and type "set windir"

Open the log file and post the contents.


http://support.microsoft.com/kb/902093

cgeier 187 Junior Poster

Go to your local thrift store (ex: Goodwill, Salvation Army, etc...) and buy yourself a used corded keyboard (if you don't have one).

cgeier 187 Junior Poster

Check out this Microsoft article: http://support.microsoft.com/kb/836941

cgeier 187 Junior Poster

Does anyone know how to communicate with a Unisys UTS60 system in Visual Basic? I'd like to be able to send commands and receive data.