Psuedocode to java.. help needed

this is the start of psuedocode i need to convert into java:
Roll a 12 sided die to choose a number in the range 1.....12
While the user has not made an incorrect guess
Ask the uer to guess whether they think the next number will be higher
or lower
it goes on to other topics but i was just wondering if anyone knew how
to begin, especially the prediction or random output of a number by the
computer..
if anyone can help then that'd be great, thank you
steve

hey again, cheers for the hint.. i have been working hard on a simpler program and have only one error surround the 'if' statement.. how does this look to you?? i can't find the error however.
import java.util.Scanner;
public class dice
          public static void main (String [] args)
                    Scanner in = new Scanner(System.in);
                    Random rnd = new Random();
                    int r = rnd.nextInt(12) + 1;
               System.out.print("guess a number ");
               int x = in.nextInt();
          while (x != r);
               System.out.print("Guess incorrect, choose hi or low ");
               int hi = in.nextInt();
               int low = in.nextInt();
                    if
                    (hi > r); {
                    System.out.print("correct ");
                    if (low < r);
                         System.out.print("correct ");
                    else
                         System.out.print("spot on! ")
          }

Similar Messages

  • Psuedocode to java. help needed if poss

    i need to convert the following into java, but i am not sure how to output it..
    Roll a 12 sided die to choose a number between 1...12
    while the user has not made an incorrect guess
    ask the user if the next number will be higher or lower
    choose random number
    if users guess is correct
    increment count of correct guesses
    update the stored current number
    end if
    end while
    tell the user how many correct guesses there are
    any help would be greatful, i am a beginning so go easy!!!
    thanks alot
    stevie

    hey, sorry if i've caused a 'cross post', i am not too sure what it is but i hope i haven't done anything wrong! so far i am just trying to put a basic program together before building on it..
    import java.util.scanner;
    public class dice
    public static void main (String [] args)
    Scanner in = new Scanner(System.in);
    Random rnd = new Random();
    System.out.print("input a number between one and twelve")     int r =in.nextInt;
                   int r = rnd.nextInt(12) + 1;
              System.out.println(r);
    i know this has errors, but i was just hoping for a hint/clue for the basic program before researching more to build on it.. hope this code will help. reply when you can, thank you very much
    stevie

  • Java help needed-Inventory System

    I urgently need help in finishing my java inventory project for school. Can anyone help me usin files and streams to get the program to save data and help me get the menu to work pls THANKS> Heres the source code below:
    // TextForm.java
    // A simple label/field form panel
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class TextForm extends JPanel {
    private JTextField[] fields;
    // Create a form with the specified labels, tooltips, and sizes.
    public TextForm(String[] labels,
    int[] widths, String[] tips) {
    super(new BorderLayout());
    JPanel labelPanel = new JPanel(new GridLayout(labels.length, 1));
    JPanel fieldPanel = new JPanel(new GridLayout(labels.length, 1));
    add(labelPanel, BorderLayout.WEST);
    add(fieldPanel, BorderLayout.CENTER);
    fields = new JTextField[labels.length];
    for (int i=0; i < labels.length; i+=1) {
    fields[i] = new JTextField();
    if (i < tips.length) fields.setToolTipText(tips[i]);
    if (i < widths.length) fields[i].setColumns(widths[i]);
    JLabel lab = new JLabel(labels[i], JLabel.RIGHT);
    lab.setLabelFor(fields[i]);
    labelPanel.add(lab);
    JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
    p.add(fields[i]);
    fieldPanel.add(p);
    JScrollBar JScrollBar = new JScrollBar();
    JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);
    add(vbar, BorderLayout.EAST);
    public String getText(int i) {
    return( fields[i].getText() );
    public static void main(String[] args) {
    String[] labels = { "115ml Medicine", "236.60ml Water-clear", "236.60 Water-Amber", "250ml Irish Moss",
    "250ml Sauce", "355ml Water", "380ml Juice", "473ml Vinegar", "500ml Water", "500 ml Blue Water", "600ml Water",
    "750ml Syrup/honey", "900ml Disinfectant", "1000ml Syrup", "1500ml Water", "Total # caps:" };
    int[] widths = { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12 ,12 };
    String[] descs = { "", "Enter Quantity" };
    final TextForm form = new TextForm(labels, widths, descs);
    JButton submit = new JButton("Save Inventory");
    JButton cancel = new JButton( "Cancel");
    submit.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JOptionPane.showConfirmDialog(null,"Are you sure you want to save this record?");
    JOptionPane.showMessageDialog(null, " Inventory status updated");
    JOptionPane.showConfirmDialog(null, "Do you want to exit?");
    JFrame f = new JFrame("Sweet Inventory System");
    f.getContentPane().add(form, BorderLayout.NORTH);
    JPanel p = new JPanel();
    p.add(submit);
    f.getContentPane().add(p, BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
    Its error free except i cant see the menubar or get it to save items usin files and streams.
    HELP PLEASE

    TELL ME THE CODE I CAN USE TO MAKE IT SAVE ITEMS LIKE
    IN A TEXT FILE AND HOW CAN I ATTACH IT TO THE SAVE
    BUTTON USIN A LISTENER
    THANKS
    PLS POST HEREPosts like this make me ignore you forever.

  • *Basic* Java help needed...

    I feel like a complete novice for posting this kinda stuff, but i figured somebody would take 5 minutes and help me out. My final in my programming class depends on 2 programs, one of which is giving me some actual trouble.
    What I have to do is create a java applet that allows a user to input their weight, select a planet, and then have their weight converted to what their weight would be on the selected planet. However, if the ouput is higher than 60 pounds, I need a picture of the michelin man to appear and the theme from star wars to play. If it is below 60, A multicolored asterisk should be displayed with applause.
    I will post what code I have already made. Please note: ITS VERY VERY BASIC. I may have overcomplicated some things, and there is always more than one way to do something (in my experience). Also, I kinda just converted a temperature conversion applet, so there may be some extra stuff I don't need.
    Please help.
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class tempsapp2 extends Applet implements ActionListener
    Label prompt1;
    TextField input1;
    Label prompt2;
    TextField input2;
    int number1, number2;
    int mercury, venus, earth, mars, jupiter, saturn, neptune, uranus, pluto, result;
    public void init()
    prompt1 = new Label ("Enter your weight:");
    add (prompt1);
    input1 = new TextField (10);
    add (input1);
    prompt2 = new Label ("Enter the Number of the Planet you would like to have your weight converted to:");
    add (prompt2);
    input2 = new TextField (10);
    add (input2);
    input2.addActionListener(this);
    add (input2);
    public void paint (Graphics g)
    number1 = Integer.parseInt(input1.getText());
    number2 = Integer.parseInt(input2.getText());
    mercury = (number1*3780)/1000;
    venus = (number1*9070)/1000;
    earth = (number1*10)/1000;
    mars = (number1*3770)/1000;
    saturn = (number1*9160)/1000;
    uranus = (number1*8890)/1000;
    neptune = (number1*1125)/1000;
    jupiter =  (number1*2364)/1000;
    pluto = (number1*670)/1000;
    if(number2==1)
    g.drawString("Your weight on Mercury would be "+mercury+" lbs",100,150);
    else if(number2==2)
    g.drawString("Your weight on Venus would be "+venus+" lbs",100,150);
    else if(number2==3)
    g.drawString("Your weight on Earth would be "+earth+" lbs",100,150);
    else if(number2==4)
    g.drawString("Your weight on Mars would be "+mars+" lbs",100,150);
    else if(number2==5)
    g.drawString("Your weight on Jupiter would be "+jupiter+" lbs",100,150);
    else if(number2==6)
    g.drawString("Your weight on Saturn would be "+saturn+" lbs",100,150);
    else if(number2==7)
    g.drawString("Your weight on Uranus would be "+uranus+" lbs",100,150);
    else if(number2==8)
    g.drawString("Your weight on Neptune would be "+neptune+" lbs",100,150);
    else if(number2==9)
    g.drawString("Your weight on Pluto would be "+pluto+" lbs",100,150);
    public void actionPerformed(ActionEvent evt)
      number1 = Integer.parseInt(input1.getText());
      number2 = Integer.parseInt(input2.getText());
      repaint();
    }

    I am guessing that you are wondering where to go from here. If so http://java.sun.com/products/plugin/1.5.0/demos/applets/Animator/Animator.java may prove helpful.
    Also I would recommend using arrays of planet names and weight multipliers. It could make your code a lot less cumbersome.

  • Java help needed(PLEASE)

    I have a Question for all you gifted people:
    I am designing a sort of quiz which takes questions and three possible answers from a database(which also holds the real answer).It prints these on the dos screen and I then have a System.in statement which allows the user to enter his or her answer (eg A,B,C or 1,2,3). I need a way of adding up the score at the end!!I was thinking of storing there answers in an array and compairing there answer to my correct answer in the database and if it is the same add 1 and if it not the same add 0???
    How would i write the System.in answers into an array and add them up???
    These are my thoughts on how to do this i would love to hear yours!! And also a help with writing the code for the above system of scoreing would be GREATLY appriciated!!
    thanks everyone,
    james.

    As mathuoa pointed out, since you already display the 3 possible answers to the user, get them into an array and display them on the screen. Then, as the user enters an answer, compare them with the three answers and if it is correct, update the score variable as such. If you want the history of answers that the user has given, then u will have to use a Vector/List/some such collection object to hold the user's answers.
    java.util.Vector answers = new java.util.Vector();
    answers.add(usersAnswer1);
    answers.add(usersAnswer2);
    Then, to get the entries,
    for(Enumeration e = answers.elements(); e.hasMoreElements();)
    System.out.println(e.nextElement());
    //Do something with the answer.
    This is one possible way of getting the answers from the user!

  • Calling perl script from java ---help needed

    I haven't been doing a lot with java lately and i'm building an app with netbeans and having some difficulty with my button calling an outside perl script I'm pasting the code and error below...any help would be greatly appreciated. It's running on fedora 9 pretty much default install...
    thanks.
    code:
    Runtime r = Runtime.getRuntime();
    Process p = null;
    String s = null;
    String cmd123[] = { "perl /home/deaddev/test1.pl" };
    try {
    p = r.exec(cmd123);
    catch {
    foo bar/etc/etc
    error:
    Oct 12, 2008 4:09:37 PM photomainmgr readToPerlActionPerformed
    SEVERE: null
    java.io.IOException: Cannot run program "perl /home/deaddev/test1.pl": java.io.IOException: error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:474)
    at java.lang.Runtime.exec(Runtime.java:610)
    at java.lang.Runtime.exec(Runtime.java:483)
    at photomainmgr.readToPerlActionPerformed(photomainmgr.java:117)
    at photomainmgr.access$000(photomainmgr.java:21)
    at photomainmgr$1.actionPerformed(photomainmgr.java:54)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
    at java.awt.Component.processMouseEvent(Component.java:6101)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3276)
    at java.awt.Component.processEvent(Component.java:5866)
    at java.awt.Container.processEvent(Container.java:2105)
    at java.awt.Component.dispatchEventImpl(Component.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2163)
    at java.awt.Component.dispatchEvent(Component.java:4288)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
    at java.awt.Container.dispatchEventImpl(Container.java:2149)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4288)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
    Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
    at java.lang.ProcessImpl.start(ProcessImpl.java:81)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:467)
    ... 30 more
    error executing perl /home/deaddev/test1.pl

    jschell wrote:
    sabre150 wrote:
    As and alternative you can useString cmd123 = "perl /home/deaddev/test1.pl";Using the single string approach YOU have to do any quoting so with this line no quoting takes place and the script /home/deaddev/test1.pl will be executed.Although that should be true apparently it isn't. I have just run  
    Process p = Runtime.getRuntime().exec("perl /home/sabre/work/dev/perl/xxx.pl");
    new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
    new SyncPipe(p.getInputStream(), System.out).run();
    int returnCode = p.waitFor();
    System.out.println("Return code = " + returnCode);which correctly executes the perl script xxx.pl.
    P.S. SyncPipe is a Runnable that copies an InputStream to an OutputStream.
    Edited by: sabre150 on Oct 14, 2008 9:19 AM
    Interesting! Even though Runtime.exec() works with a single String, ProcessBuilder fails with this approach! You have to split the argument string. This certainly looks like a bug! Some while ago I looked at the source for Runtime.exec() to look at the differences between Runtime.exec() and ProcessBuilder and found that behind the scenes Runtime.exec() uses ProcessBuilder.
    More research is required.

  • New to Java:   Help Needed

    Hi,
    I am writing a utility to monitor all the objects created by my application. I want to be able to get not only values of class variables(for which the reflection package seems pretty useful), but also instance variables.
    For example.
    public class myClass {
    //Constructor
    public myClass(int i) {
    // another class instantiates this one
    myClass mc = new myClass(10);
    myClass mc1 = new myClass(20);
    I need to keep track of the the handles mc and mc1 and the
    other initializations they do based on the value passed at runtime.
    Is there a way to to this. Or even better, is there someplace in Java which stores all the objects instantiated and their handles?
    Any suggestions would be greatly appreciated.
    Thnx
    cvsan

    How do I access private and proteced variables. By default only the public variables are accessible via the reflect class as in the example below.
    Class c = rc.getClass();
    String s = c.getName();
    System.out.println(s);
    try { abcField = c.getField("abc");
    where abc is a public instance variable. If abc is a private instance variable, the above example fails.
    Is there any way to override the data hiding feature of Java?
    Thanks
    cvsan

  • New to java,,,help needed urgently

    I am geeting a compile error..."cannot resolve symbol" in my main class. The program is supposed to prompt the user for five sets of data, and calculate the tax and total of the entered products and print it back to the screen, it is also supposed to calculate the cheapest and most expensive item and print them back. can someone pls shed some light on this error msg, as I cant seem to get my head around it.
    import java .io.*;
    import java.util.StringTokenizer;
    import java.text.NumberFormat;
    import java.util.Locale;
    //set up a class to call on the constructors from the catalogueitem class
    public class Myassg4
         private static final int MAX = 2;//sets the length to 2
         private static CatalogueItem[] prodlist ;//sets array for product list
         NumberFormat cash = NumberFormat.getCurrencyInstance(new Locale("en","AU"));
         private static void main(String[] args) throws IOException
         {//declare the variables and initialize
         double preTotal = 0.00;
         String inString;
         double maximum, lowest;
         double sum = 0.00;
         BufferedReader stdin = new BufferedReader (new
         InputStreamReader(System.in));
         prodlist = new CatalogueItem[];//sets the length (THIS IS WHERE THE PROBLEM OCCURS!!!!)
    System.out.println("Enter 5 sets of data");
         //loop through the array and read the data in
         for(int i = 0;i <prodlist.length;i++)
              inString = stdin.readLine();
              //create a String Tokenizer to read the data separately
              StringTokenizer tok = new StringTokenizer(inString, ":");
    prodlist[i] = new CatalogueItem(tok.nextToken(), tok.nextToken(),
    Double.parseDouble(tok.nextToken()));
    }//end of loop
    //create a header and print the data back to the screen
    System.out.println();
    System.out.println("LISTING OF ALL GOODS");
    System.out.println();
    System.out.println("Cat\tDescription\tExTax\tTax\tIncTax");
    System.out.println("___\t___________\t_____\t___\t______");
    System.out.println();
    for(int j = 0;j <prodlist.length;j++){
    System.out.println(prodlist[j].getCatno()+"\t"+prodlist[j].getDesc()+
    "\t"+prodlist[j].getPrice()+"\t"+prodlist[j].getTax()
    +"\t"+prodlist[j].getIncTax());
    I have errors every where the prodlist is used, I know I am not initializing it correctly but dont know what the alternatives are.

    daniel here is the entire code if you do get a chance can you pls have a look at it for me thanks.
    import java .io.*;
    import java.util.StringTokenizer;
    import java.text.NumberFormat;
    import java.util.Locale;
    //set up a class to call on the constructors from the catalogueitem class
    public class Myassg4
         private static final int MAX = 2; //sets the length to 2
         private static CatalogueItem[] prodlist; //sets array for product list
         NumberFormat cash = NumberFormat.getCurrencyInstance(new Locale("en","AU"));
         private static void main(String[] args) throws IOException
         {//declare the variables and initialize
         double preTotal = 0.00;
         String inString;
         double maximum, lowest;
         double sum = 0.00;
         BufferedReader stdin = new BufferedReader (new
         InputStreamReader(System.in));
         prodlist = new CatalogueItem[5];//sets the length
         System.out.println("Enter 5 sets of data");
         //loop through the array and read the data in
         for(int i = 0;i <prodlist.length;i++)
              inString = stdin.readLine();
              //create a String Tokenizer to read the data separately
              StringTokenizer tok = new StringTokenizer(inString, ":");
    prodlist[i] = new CatalogueItem(tok.nextToken(), tok.nextToken(),
    Double.parseDouble(tok.nextToken()));
    }//end of loop
    //create a header and print the data back to the screen
    System.out.println();
    System.out.println("LISTING OF ALL GOODS");
    System.out.println();
    System.out.println("Cat\tDescription\tExTax\tTax\tIncTax");
    System.out.println("___\t___________\t_____\t___\t______");
    System.out.println();
    for(int j = 0;j <prodlist.length;j++){
    System.out.println(prodlist[j].getCatno()+"\t"+prodlist[j].getDesc()+
    "\t"+prodlist[j].getPrice()+"\t"+prodlist[j].getTax()
    +"\t"+prodlist[j].getIncTax());
    //use this data and call the cheapest method to print
    //the cheapest goods in the catalogue
    System.out.println();
    System.out.println("CHEAPEST GOODS IN THE CATALOGUE");
    System.out.println();
    lowest = cheapest(prodlist, MAX);
    System.out.println("Cat\tDescription\tExTax\tTax\tIncTax");
    System.out.println("___\t___________\t_____\t___\t______");
    System.out.println();
    for(int k = 0;k <prodlist.length;k++){
    if(prodlist[k].getTaxInc == lowest)
    System.out.println(prodlist[k].Catno()+"\t"+prodlist[k].getDesc()+
    "\t"+prodlist[k].getPrice()+"\t"+prodlist[k].getTax()
    +"\t"+prodlist[k].getIncTax());
    //use the listing of all goods and call the most expensive method
    //to calculate and display back on screen
    System.out.println();//create two lines of space in between
    System.out.println();
    System.out.println("MOST EXPENSIVE GOODS IN THE CATALOGUE");
    System.out.println();
    maximun = expensive(prodlist, MAX);
    System.out.println("Cat\tDescription\tExTax\tTax\tIncTax");
    System.out.println("___\t___________\t_____\t___\t______");
    System.out.println();
    for(int l = 0;l < prodlist.length;l++){
    if(prodlist[l].getTaxInc == maximum)
    System.out.println(prodlist[l].Catno()+"\t"+prodlist[l].getDesc()+
    "\t"+prodlist[l].getPrice()+"\t"+prodlist[l].getTax()
    +"\t"+prodlist[l].getIncTax());
    //print the pretax worth of goods by calling the method and display
    System.out.println();//create a two lines of space in between
    System.out.println();
    System.out.println("TOTAL OF PRE-TAX WORTH OF CATALOGUE ITEMS: "+preTaxWorth
    (prodlist));
    //print the avg tax payable per item
    System.out.println();
    System.out.println("AVERAGE AMOUNT OF TAX PAYABLE PER ITEM:"+avgTax
    (prodlist));
    //declare the other methods within the scope of the main class
    public static double cheapest(CatalogueItem[] prodlist, int size)
         double lowest = prodlist[0].getIncTac();
         for(int i = 0; i < size;i++)
              if(prodlist.getIncTax() < lowest)
              lowest = prodlist[i].getIncTax();
         return lowest;
    public static double expensive(CatalogueItem[] prodlist, int size)
         double maximum = prodlist[0].getTaxInc();
         for(int i = 0; i < size; i++)
              if(prodlist[i].getIncTax() > maximum)
              maximum = prodlist[i].getIncTax();
         return maximum;
    public static double preTaxWorth(CatalogueItem[] prodlist)
    {//add all the getPrice's in together
    double preTax = 0; //prodlist[0].getPrice();
    for(int i =0; i <prodlist.length; i++)
         preTax += prodlist[i].getPrice();
    return preTax;
    public static double avgTax(CatalogueItem[] prodlist)
    {//run through the array and add all the getTax amounts up.
         double sum = 0;
         for(int i = 0; i < prodlist.length; i++)
              sum = sum + prodlist[i].getTax();
         //to get the avg we divide the sum by the MAX number of entries
         double Total = sum / MAX;
         return Total;
    }//end of main class
    //CatalogueItem class      
    //catalogue item class
    //ensure that the accesors and mutators
    //are visible and cannot be overridden
    class CatalogueItem
    //declare the data types
    private String catno;
    private String desc;
    private double price;     
    //declare the taxation rate constant
    //but make it visible
    public CatalogueItem(){
         catno = " ";
         desc = " ";
         double price;
    //declare the full constructor
    CatalogueItem (String inCatno, String inDesc, double Price)
         inCatno = catno;
         inDesc = desc;
         Price = price;
    //name accessor---not overidable
    public final String getCatno()
         return catno;
    //name product description accessor--not overidable
    public final String getDesc()
         return desc;
    //name the extax method
    public double getPrice()
         return price;
    //tax utility method
    public double Tax()
    double Tax;     
         Tax = 00.15 * getPrice();
         return Tax;
    //Including Tax method
    public double IncTax()
         double IncTax;
         IncTax = Tax() + getPrice();
         return IncTax;

  • Set Pasword in any folder through java (HELP NEEDED)

    hi i want know it is possibel in java i m set password in any folder of my windows if it is so reply me soon .
    i m waiting for reply

    In java only - no.
    If there is a command line tool that does it then you can use Runtime.exec() with an OS specific command. Presumably you are talking about windows so you might look in the appropriate resource kit. That is probably the most likely location for a command. But it could be somewhere else too.
    If you can't find a command then you would have to use JNI.

  • Some java help needed!!!!

    Exception in thread "main" java.lang.NullPointerException
         at Standings.<init>(Standings.java:15)
         at Client.main(Client.java:21)
    this is my program and I dont understand what is going wrong, I am also including the 2 classes that complement it.
    class 1
    public class Team
    // Declaring Private Variables
    private double wins;
    private double loses;
    private String Name;
    public Team()
         Name="";
         wins=0;
         loses=0;
    public Team(String t, double w, double l)
         Name=t;
         wins=w;
         loses=l;
    public void setName (String n)
         Name=n;
    public void setWins (double w)
         wins=w;
    public void setLoses (double l)
         loses=l;
    public String getName ()
         return Name;
    public double getWins ()
         return wins;
    public double getLoses ()
         return loses;
    public String toString ()
         String toString=Name + " " + wins + " " + loses;
         return toString;
    public boolean equals (Team p1, Team p2)
         if ((p1.Name.equals(p2.Name))&&(p1.wins==p2.wins) && (p1.loses==p2.loses))
              return true;
         else
              return false;
    class 2
    public class Standings
    private Team [] teams;
    private String [] steams;
    public Standings (Team [] arr)
         for(int i=0;i<arr.length;i++)
              teams[i] = new Team(arr.getName(), arr[i].getWins(), arr[i].getLoses());
    public Team [] toString2 ()
              return teams;
    client program
    import java.text.DecimalFormat;
    import java.util.Scanner;
    import java.io.File;
    import java.io.IOException;
    public class Client
    public static void main( String [] args ) throws IOException
         //first let's create an array of football teams
         Team [] array = new Team[5];
         array[0] = new Team("Alabama", 6, 6);
         array[1] = new Team("Georgia", 7, 4);
         array[2] = new Team("Tennessee", 8, 3);
         array[3] = new Team("Vanderbilt", 4, 8);
         array[4] = new Team("Mississippi", 1, 6);
         // now instantiate the team calling the overloaded constructor
         Standings temp = new Standings(array);
         // now let's print the team (call toString)
         System.out.println(temp.toString());
    //Standings another = new Standings( temp );

    private Team [] teams;You never allocated this array, as in:
    teams = new Team[size];
    so when you get to this line:
    teams[ i ] = new Team(...);teams is null, ergo the NullPointerException.

  • Java Help Needed

    In the below program i want to place some code and i need to know what code to place and where. I want the code to speed up the program by 50 times what it is know.
    Its quite a hard question since if asked alot of people and they don't seem to know.
    import SpikeLib.*;
    public class SpikeOctagon
    public static void main (String args [] )
    SpikeWindow window;
    Spike mySpike;
    mySpike = new Spike ();
    window = new SpikeWindow ();
    window.addSpike (mySpike);
    mySpike.setColour (Spike.RED, Spike.PINK);
    mySpike.moveNorth();
    mySpike.moveNorth();
    mySpike.moveNorth();
    mySpike.moveNorthWest();
    mySpike.moveNorthWest();
    mySpike.moveNorthWest();
    mySpike.moveWest();
    mySpike.moveWest();
    mySpike.moveWest();
    mySpike.moveSouthWest();
    mySpike.moveSouthWest();
    mySpike.moveSouthWest();
    mySpike.moveSouth();
    mySpike.moveSouth();
    mySpike.moveSouth();
    mySpike.moveSouthEast();
    mySpike.moveSouthEast();
    mySpike.moveSouthEast();
    mySpike.moveEast();
    mySpike.moveEast();
    mySpike.moveEast();
    mySpike.moveNorthEast();
    mySpike.moveNorthEast();
    mySpike.moveNorthEast();
    cheers

    I know how to get that 50X speedup. It's easy - get a computer that's 50X faster than the one you're running on now.
    This is one of the worst requests I've seen posted in a while. The OP is a total, utter eejit. NO ONE would be able to make a start on this preposterous question based on the code that's been posted.
    If the quality of the question is indicative of the quality of the code, no one it's a slow pig. - MOD

  • Beginning Java help needed.

    I'm trying to write a program that would display the elapsed time after double clicking in seconds. For instance, first click will start the timer, but it will not display the elapse time after the second click. Here is my code.
    public class ClickTimer extends WindowController {
    private double startingTime;
    private Text message;
    public ClickTimer () {startController (700,500);
    public void begin() {
    message = new Text( "Double click twice to display time elapse." ,50, 50
    ,canvas );
    public void onMousePress(Location point) {
    startingTime = System.currentTimeMillis();
    if (point.getclickCount() == 2) {float elapsedTimeSec = elapsedTimeMillis/1000F;
    }}

    For instance, first click will start the timer, but it will not display the elapse time after the second click.Since there's no code there that would display elapsed time, that isn't surprising.
    Your onMousePress method always sets the startTime value (no matter what click it is), which is probably not what you want.
    Text? Location? WindowController? What library are you using? You should say up front.

  • Help needed  while exporting crystal reports to HTML file format using java

    Help needed  while exporting crystal reports to HTML file format using java api(not using crystalviewer).i want to download the
    html file of the report
    thanks

    the ReportExportFormat class does not have HTML format, it has got to be XML. Export to HTML is available from CR Designer only.
    Edited by: Aasavari Bhave on Jan 24, 2012 11:37 AM

  • Help Needed in Creating Java Class and Java Stored Procedures

    Hi,
    Can anyone tell how can i create Java Class, Java Source and Java Resource in Oracle Database.
    I have seen the Documents. But i couldn't able to understand it correctly.
    I will be helpful when i get some Examples for creating a Java Class, Java Source and Stored Procedures with Java with details.
    Is that possible to Create a Java class in the oracle Database itself ?.
    Where are the files located for the existing Java Class ?..
    Help Needed Please.
    Thanks,
    Murali.v

    Hi Murali,
    Heres a thread which discussed uploading java source file instead of runnable code on to the database, which might be helpful :
    Configure deployment to a database to upload the java file instead of class
    The files for the java class you created in JDev project is located in the myworks folder in jdev, eg, <jdev_home>\jdev\mywork\Application1\Project1\src\project1
    Hope this helps,
    Sunil..

  • Image size and mime type.. non-java guy needs help

    Image size, mime type.. non-java guy needs help
    Im not at all familiar with java so this is really weird for me to work out. I?ve been doing it all day (and half of yesterday).
    Im trying to write a custom clodFusion tag in java that gets the width, height, size and MIME types of a given file. I?ve been trying to get it to work on the command line first. I can get the width and height but cant get the size and the MIME type.
    Here is what I got
    /*import com.allaire.cfx.*;*/
    import java.awt.image.renderable.*;
    import javax.media.jai.*;
    import com.sun.media.jai.codec.*;
    import java.io.*;
    import java.util.*;
    public class ImageInfo {
    private RenderedOp image = null;
    private RenderedOp result = null;
    private int height = 0;
    private int width = 0;
    private String type = "";
    private String size = "";
    public void loadf(String file) throws IOException
    file = "80by80.jpg";
    FileSeekableStream fss = new FileSeekableStream(file);
    image = JAI.create("stream", fss);
    height = image.getHeight();
    width = image.getWidth();
    System.out.println(height + "\n");
    System.out.println(width);
    System.out.println(type);
    public static void main(String[] args) throws IOException {
    ImageInfo test = new ImageInfo();
    test.loadf(args[0]);
    can anyone please help me out to modify the above so I can also print the mime type and the file size to screen.
    thanks for any help

    any suggestions?

  • Help Needed With A Java Installation

    Hello,
    I'm beyond being a novice with regards to Java. To be quite honest, I don't have the time right now to learn the language, nor do I have the need for anything other than what I am about to ask. I say this upfront to avoid unfriendly comments from people who may criticize my "laziness", NOT to sound disrespectful to those who post or answer questions in this forum.
    With that said, here's my question...
    I have a Sun/Cobalt RaQ4i server. I'd like to run a few free license Java games that I found on a website. The problem is, RaQ appliances do not ship with Java installed. I've been looking for some way to get it on my server for a few days now, with little luck. I've searched the Java help forums, the Sun/Cobalt forums and a few other help sites such as www.raqzone.com. (...which is why laziness is in quotes up there.) I did find this page... "http://developer.cobalt.com/java/java.raq.php". I have now installed both, the package and the update, on the server. However, the applet still does not run. I don't need the JSP feature, as my site is done in ASP. I don't know what a servlet is, but thought it might be similar to an applet, and would do the trick. *?* Apparently, I was wrong. Can ANYONE tell me what I need to do to get the desired results when I try to run a Java applet on my Cobalt RaQ?? I'd also be willing to be a fee to have it installed... correctly, of course! :)
    Thanks in advance for any directions or guidance,
    -Daniel
    [email protected]

    Assuming you're running Solaris, you can download the Java Runtime Environment (JRE) from http://java.sun.com/
    One of the provided programs is appletviewer, which you will be able to use to run applets if they are on your local machine. I'm not entirely sure about Solaris, but the JRE may also install the Java Plugin to your browser so you can view applets in the browser.
    Apologies if this was already mentioned in the link you provided - registration/login is required, so I didn't read it.
    I hope you have more luck with your applets,
    -Troy

Maybe you are looking for

  • Excise duty - not reflected in Purchase Order

    Hi Dears I have maintained tax code JMOP with tax code FV11 and selected country-plant-control code wise. I have also entered desired rate of excise duty here. Further J1ID was properly maintained for material-control code (Chapter id). But when I pr

  • Substituted Drive Not Always Visible in Windows Explorer

    We have a 2008 server with terminal services enabled and the login script is used to subst I: to a folder on a local hard disk eg. SUBST I: D:\FOLDER When the domain administrator is logged in via an RDP session they have an entry for I: shown in win

  • Getting Canon S90 CR2 files off my iPad to my PC

    Using the camera connection kit, I transferred a number of Canon S90 CR2 files to my iPad. That worked fine as it always does. But how do I get them onto my PC? Canon Camera Window says it does not find any "camera", when the iPad is plugged in. Wind

  • Lost iPod, iTunes, everything

    I have a very big problem...on Friday, my iPod touch was stolen at school. I learned that you can hack into this device and wipe all the info on it. Now today, my computer crashed and I lost all my iTunes info. I do have my serial number, but I don't

  • Replace Canvas with Group!??

    Hi, I tried to replace the Canvas with a group in the following code This works fine: 1.) <mx:TabNavigator id="tn" width="100%" height="100%"> ... private function AddForm():void{     var children:Array=tn.getChildren();     var form:myCanvas=new myC