Lv 114 points

D Y

Favorite Answers0%
Answers0
Questions30
  • Can designing (Calculus?)?

    So we're suppose to use Calculus to design a can. however, I don't understand how to come up with the equations......

    Here are the instructions:

    This can's design requires that there be no waste involved in cutting the metal that makes the vertical sides; however, the top and bottom are to be cut from square pieces of metal using minimum amount of waste.

    So i got one equation: 21.65625 in^3 = (Pi)rh

    where "r" is radius and "h" is height

    However, I have no idea how to come up with the equation for the surface area.

    Please explain well.

    (The 21.65626 is from that the can must hold 12 fluid ounces)

    2 AnswersMathematics9 years ago
  • Java BlackJack Program transferring through classes?

    I have basically one question: how do you transfer the object (card1, or card2, etc.) back to the main method from the other classes?

    public class BlackJack {

    /**

    * @param args the command line arguments

    */

    public static void main(String[] args)

    {

    boolean again = false;

    System.out.println("Welcome to the BlackJack Program!");

    System.out.println("The objective of the game is to get 21");

    System.out.println("RULES: ");

    System.out.println("1: 2 - 10 equals their original value");

    System.out.println("2: jack, queen, king all equal 10");

    System.out.println("3: ace can be either 1 or 11");

    do{

    boolean again1 = false;

    Cards myCards = new Cards();

    Cards2 myCards2 = new Cards2();

    System.out.println("Your Cards: " + " " );

    do{

    DealerCards myDealerCards = new DealerCards();

    }while(again1 == true);

    }while(again == true);

    }

    }

    public class Cards

    {

    public int card1, card2, card3;

    private final int KING = 13;

    private final int JACK = 11;

    private final int QUEEN = 12;

    private final int ACE = 1;

    public Cards()

    {

    Dealer1();

    }

    public void Dealer1()

    {

    card1 = (int)(Math.random()*12 + 1);

    }

    public String toString1()

    {

    String cardname;

    if(card1 == 2)

    cardname = "2";

    if(card1 == 3)

    cardname = "3";

    if(card1 == 4)

    cardname = "4";

    if(card1 == 5)

    cardname = "5";

    if(card1 == 6)

    cardname = "6";

    if(card1 == 7)

    cardname = "7";

    if(card1 == 8)

    cardname = "8";

    if(card1 == 9)

    cardname = "9";

    if(card1 == 10)

    cardname = "10";

    if(card1 == 11)

    cardname = "JACK";

    if(card1 == 12)

    cardname = "QUEEN";

    if(card1 == 13)

    cardname = "KING";

    else

    cardname = "ACE";

    return cardname;

    }

    }

    public class Cards2

    {

    public int card1, card2, card3;

    private final int KING = 13;

    private final int JACK = 11;

    private final int QUEEN = 12;

    private final int ACE = 1;

    public Cards2()

    {

    Dealer2();

    }

    public void Dealer2()

    {

    card2 = (int)(Math.random()*12 + 1);

    }

    public String toString2()

    {

    String cardname;

    if(card2 == 2)

    cardname = "2";

    if(card2 == 3)

    cardname = "3";

    if(card2 == 4)

    cardname = "4";

    if(card2 == 5)

    cardname = "5";

    if(card2 == 6)

    cardname = "6";

    if(card2 == 7)

    cardname = "7";

    if(card2 == 8)

    cardname = "8";

    if(card2 == 9)

    cardname = "9";

    if(card2 == 10)

    cardname = "10";

    if(card2 == 11)

    cardname = "JACK";

    if(card2 == 12)

    cardname = "QUEEN";

    if(card2 == 13)

    cardname = "KING";

    else

    cardname = "ACE";

    return cardname;

    }

    }

    public class DealerCards

    {

    public int card1, card2, card3;

    private final int KING = 13;

    private final int JACK = 11;

    private final int QUEEN = 12;

    private final int ACE = 1;

    public DealerCards()

    {

    Dealer3();

    }

    public void Dealer3()

    {

    card3 = (int)(Math.random()*12 + 1);

    }

    public String toString3()

    {

    String cardname;

    if(card3 == 2)

    cardname = "2";

    if(card3 == 3)

    cardname = "3";

    if(card3 == 4)

    cardname = "4";

    if(card3 == 5)

    cardname = "5";

    if(card3 == 6)

    cardname = "6";

    if(card3 == 7)

    cardname = "7";

    if(card3 == 8)

    cardname = "8";

    if(card3 == 9)

    cardname = "9";

    if(card3 == 10)

    cardname = "10"

    1 AnswerProgramming & Design9 years ago
  • AP calculus / Physics Question?

    An object moves along the x-axis following the position function:

    x(t) = - ( 3 / pi ) cos [ ( pi / 3 ) t ] + ( 3 / pi ) + 2

    A) Are the statements both true, false or one true + one false? give your reasons

    Statement 1: for 3 < t < 4.5, velocity is decreasing

    Statement 2: for 3 < t < 4.5, the speed is increasing

    I thought they were both true since velocity is becoming more negative:

    t = 3, v = 0 then t = 3.5, v = -1m/s etc.

    I think it is speeding up since the acceleration graph is all negative:

    t = 3, a = -3m/s^2 then t = 4, a = -1 m/s^2

    so am i right or am I wrong??

    b) What is the total distance travelled in 4 s?

    I thought you use the position function for intervals [0,3] since velocity is positive and [3,4] since velocity is negative...

    so am i right???

    please explain clearly

    2 AnswersMathematics9 years ago
  • how to convert between number bases?

    What is the equation or method to convert between bases?

    I know it has something to do with dividing the bases and getting remainder, but I really don't get it after that.

    plz help....

    For ex: in binary 1000 = 8 in dec or 8 in hex

    13 in base 10 = 1101 in binary

    2 AnswersMathematics9 years ago
  • How to concatenate integers in strings in Java?

    how do i concatenate integers to a string without using parseInt() ?

    for ex: if I get 2 and 3, it should print out 23 not 5

    I think it has something to declaring a new string, but I'm not sure.

    help would be appreciated

    7 AnswersProgramming & Design9 years ago
  • Java File program? Error?

    The error is this:

    java.io.FileNotFoundException: namefile0.txt (The system cannot find the file specified)

    at java.io.FileInputStream.open(Native Method)

    at java.io.FileInputStream.<init>(Unknown Source)

    at java.io.FileInputStream.<init>(Unknown Source)

    at java.io.FileReader.<init>(Unknown Source)

    at ICS_Allan_yao_culminating_assignment.calculate(ICS_Allan_yao_culminating_assignment.java:310)

    at ICS_Allan_yao_culminating_assignment.main(ICS_Allan_yao_culminating_assignment.java:48)

    the UDM for calculating is this:

    static void calculate () throws IOException

    { // open two files for read back and calculation

    String line0;

    String line1;

    String line2;

    String line3;

    String line4;

    BufferedReader inputBR0;

    FileReader inputFR0;

    BufferedReader inputBR1;

    FileReader inputFR1;

    BufferedReader inputBR2;

    FileReader inputFR2;

    BufferedReader inputBR3;

    FileReader inputFR3;

    BufferedReader inputBR4;

    FileReader inputFR4;

    // the BufferedReader and FileReader are classess from java.io

    inputFR0 = new FileReader ("namefile0.txt");

    inputBR0 = new BufferedReader (inputFR0);

    inputFR1 = new FileReader ("file1.txt");

    inputBR1 = new BufferedReader (inputFR1);

    inputFR2 = new FileReader ("file2.txt");

    inputBR2 = new BufferedReader (inputFR2);

    inputFR3 = new FileReader ("file3.txt");

    inputBR3 = new BufferedReader (inputFR3);

    inputFR4 = new FileReader ("file4.txt");

    inputBR4 = new BufferedReader (inputFR4);

    // NOTE ALL text files are READ BACK LINE BY LINE!

    line0 = inputBR0.readLine ();

    line1 = inputBR1.readLine ();

    line2 = inputBR2.readLine ();

    line3 = inputBR3.readLine ();

    line4 = inputBR4.readLine ();

    // a simple test to ensure that reading the files only goes

    //as far as the shortest length file if the files are not

    // of the same size

    //A FILE SIZE TEST IVOLVES COUNTING THE NUMBER OF LINES IN A FILE

    String heading = "Student Test1 Test2 Test3 Exam Average";

    String form = "";

    while (line0 != null || line1 != null || line2 != null || line3 != null || line4 != null)

    {

    int m1 = Integer.parseInt (line1);

    int m2 = Integer.parseInt (line2);

    int m3 = Integer.parseInt (line3);

    int m4 = Integer.parseInt (line4);

    double avg = ((m1 * 0.15) + (m2 * 0.20) + (m3 * 0.25) + (m4 * 0.40));

    form = form + line0 + " " + m1 + " " + m2 + " " + avg + "\n";

    line0 = inputBR0.readLine ();

    line1 = inputBR1.readLine ();

    line2 = inputBR2.readLine ();

    line3 = inputBR2.readLine ();

    line4 = inputBR2.readLine ();

    }

    JOptionPane.showMessageDialog (null, heading + "\n" + form);

    }

    I have checked the files, and they are all in the same size!

    But it still does not work...

    Why is that?

    All files are readback .

    3 AnswersProgramming & Design9 years ago
  • Java error? Files and Readback?

    Since the program is way to large, I am going to just paste part of it.

    All the files are like this:

    static void file1 () throws IOException

    {

    boolean app;

    String input = JOptionPane.showInputDialog (null, "append file?\n select 1 \n To create new a file \nselect 0");

    int r = Integer.parseInt (input);

    if (r == 1)

    app = true; // if true,append add on to file

    else

    app = false; // if false, write a new file

    String st;

    PrintWriter outputPW;

    FileWriter outputFW;

    // outputPW is an identfier for the PrintWriter class

    //outputFW is an identfier for the FileWriter class

    // BOTH are imported by java.io.* package

    outputFW = new FileWriter ("file1.txt", app);

    // "message" is the name of the text file

    //IMPORTANT!! use "h:message" to save on your home drive

    outputPW = new PrintWriter (outputFW);

    // FileWriter is a class inside of the class PrintWriter

    // classes can be nested inside of other classes in java

    // Enter the characters for the text file

    st = JOptionPane.showInputDialog (null, "Enter your text now. Use the character '^' as an EOF ON A SEPARATE LINE");

    while (!st.equals ("^"))

    {

    outputPW.println (st); // print each string on to file

    st = JOptionPane.showInputDialog (null, "Enter your text now. Use the character '^' as an EOF ON A SEPARATE LINE");

    }

    outputFW.close ();

    outputPW.close ();

    }

    This is where it is suppose to calculate the average.

    static void calculate () throws IOException

    { // open two files for read back and calculation

    String line0;

    BufferedReader inputBR0;

    FileReader inputFR0;

    // the BufferedReader and FileReader are classess from java.io

    inputFR0 = new FileReader ("file0.txt");

    inputBR0 = new BufferedReader (inputFR0);

    String line1;

    BufferedReader inputBR1;

    FileReader inputFR1;

    // the BufferedReader and FileReader are classess from java.io

    inputFR1 = new FileReader ("file1.txt");

    inputBR1 = new BufferedReader (inputFR1);

    String line2;

    BufferedReader inputBR2;

    FileReader inputFR2;

    // the BufferedReader and FileReader are classess from java.io

    inputFR2 = new FileReader ("file2.txt");

    inputBR2 = new BufferedReader (inputFR2);

    // NOTE ALL text files are READ BACK LINE BY LINE!

    line0 = inputBR0.readLine ();

    line1 = inputBR1.readLine ();

    line2 = inputBR2.readLine ();

    // a simple test to ensure that reading the files only goes

    //as far as the shortest length file if the files are not

    // of the same size

    //A FILE SIZE TEST IVOLVES COUNTING THE NUMBER OF LINES IN A FILE

    String heading = "Student Test1 Test2 Average";

    String form = "";

    while (line0 != null || line1 != null || line2 != null)

    {

    int m1 = Integer.parseInt (line1);

    int m2 = Integer.parseInt (line2);

    double avg = (m1 + m2) / 2.0;

    form = form + line0 + " " + m1 + " " + m2 + " " + avg + "\n";

    line0 = inputBR0.readLine ();

    line1 = inputBR1.readLine ();

    line2 = inputBR2.readLine ();

    }

    JOptionPane.showMessageDialog (null, heading + "\n" + form);

    }

    The problem is after I enter all the values, the problem gets an error if I try to calculate the values.

    I don't understand what is wrong. Can anyone help?

    By the way the error is:

    java.lang.NumberFormatException: For input string: "yrshf"

    (I have no idea where yrshf came from?

    at java.lang.NumberFormatException.forInputString(Unknown Source)

    at java.lang.Integer.parseInt(Unknown Source)

    at java.lang.Integer.parseInt(Unknown Source)

    at ICS_Allan_yao_culminating_assignment.calculate(ICS_Allan_yao_culminating_assignment.java:330)

    at ICS_Allan_yao_culminating_assignment.main(ICS_Allan_yao_culminating_assignment.java:48)

    line 48 is : calculate ();

    Can anyone help?

    It is due this Friday and I still can't get the program to work.......

    1 AnswerProgramming & Design9 years ago
  • Java error catching problem?

    try

    {

    while (res != 0)

    {

    input = JOptionPane.showInputDialog (null, "Enter Menu Selection-->\n0.Create OR append Student Name File\n1. Create OR append Test1 File \n2. Create OR append Test2 File\n3. Calculate Average\n4. Exit System");

    // continue as one big string for menu options

    if (input.equals ("0"))

    file0 ();

    else if (input.equals ("1"))

    file1 ();

    else if (input.equals ("2"))

    file2 ();

    else if (input.equals ("3"))

    calculate ();

    else if (input.equals ("4"))

    {

    System.exit (0);

    }

    else if (input == null)

    {

    JOptionPane.showMessageDialog (null, "Error");

    }

    input = JOptionPane.showInputDialog (null, "wish to continue?\n enter 1.\n Enter 0 to exit");

    res = Integer.parseInt (input);

    }

    }

    catch (NullPointerException NullPointerException1)

    {

    JOptionPane.showMessageDialog ( "You clicked cancel, program ended!");

    }

    for the message of program ended, there is an error message that says no application overload was present for JOptionPane.

    What does this mean and how do you fix it?

    1 AnswerProgramming & Design9 years ago
  • Java array and bubblesorting?

    How do you correctly write the code for bubblesorting an array? The string file was read back into an array. My does not work.

    1 AnswerProgramming & Design9 years ago
  • Java File Program Errors?

    For my program, when you click the cancel button, the file will close, but there is an error message saying "java.lang.NullPointerException

    at MenuNameWithTwoFileAverageWithAppend.main(MenuNameWithTwoFileAverageWithAppend.java:19)"

    What does this mean and how do I fix it?

    2 AnswersProgramming & Design9 years ago
  • java File readback into array and sort?

    // The "Allan_yao_file_2" class.

    import java.awt.*;

    import hsa.Console;

    import java.io.*;

    import java.util.*;

    public class Allan_yao_file_2

    {

    static Console c; // The output console

    static String createdfile;

    public static void main (String[] args) throws IOException

    {

    c = new Console ();

    c.println ("This program will allow you to create a text file. ");

    c.println ("Then, it will allow you to readback it into an array of String values or");

    c.println ("If you readback it into an array of String values, the program will be able");

    c.println ("to print the array of String values in descending order");

    c.println ();

    PrintWriter outputPW;

    FileWriter outputFW;

    outputFW = new FileWriter ("message2.txt");

    outputPW = new PrintWriter (outputFW);

    c.println ("Enter your text now. Use the character '999' as an EOF ON A SEPARATE LINE");

    createdfile = c.readLine ();

    int countLines = 0;

    while (!(createdfile.equals ("999")))

    {

    outputPW.println (createdfile); // print each string on to file

    countLines++;

    createdfile = c.readLine ();

    }

    outputPW.println ("999"); // final string marker - physical EOF

    outputFW.close ();

    outputPW.close ();

    // All files from the java.io.* package MUST be closed in order to have the

    // file successfully created. REMBEMBER THIS!!

    c.println ("FILE HAS SUCCESSFULLY BEEN CREATED");

    BufferedReader inputBR;

    FileReader inputFR;

    // the BufferedReader and FileReader are classess from java.io

    inputFR = new FileReader ("message2.txt");

    inputBR = new BufferedReader (inputFR);

    // NOTE ALL text files are READ BACK LINE BY LINE!

    // LETS COUNT THE NUMBER OF LINES IN THE FILE

    int countLine = 0;

    String line = inputBR.readLine ();

    while (line != null)

    {

    c.println (line);

    countLine++;

    line = inputBR.readLine ();

    }

    inputFR = new FileReader ("message2.txt");

    inputBR = new BufferedReader (inputFR);

    int arrayCount = 0;

    String lineArray[] = new String [countLine];

    line = inputBR.readLine ();

    while (line != null)

    {

    lineArray [arrayCount] = line;

    arrayCount++;

    line = inputBR.readLine ();

    }

    bubbleSort (lineArray);

    // Place your program here. 'c' is the output console

    }

    public static void bubbleSort (int[] x)

    {

    boolean doMore = true;

    while (doMore)

    {

    doMore = false; // assume this is last pass over array

    for (int i = 0 ; i < x.length - 1 ; i++)

    {

    if (x [i] < x [i + 1])

    {

    // exchange elements

    int temp = x [i];

    x [i] = x [i + 1];

    x [i + 1] = temp;

    doMore = true; // after an exchange, must look again

    }

    }

    }

    }

    } // Allan_yao_file_2 class

    the bubblesort says something about overload, i don't understand...

    how do you make it so that the program will readback into an array and sort it.

    by the way, the teacher said we had to use bubble sort.

    help plz. detailed explanation needed....

    1 AnswerProgramming & Design9 years ago
  • Java File Problem? Counting Vowels?

    // The "Allan_yao_file_1" class.

    import java.awt.*;

    import hsa.Console;

    import java.io.*;

    import java.util.*;

    public class Allan_yao_file_1

    {

    static Console c; // The output console

    static String createdfile;

    public static void main (String[] args) throws IOException

    {

    c = new Console ();

    PrintWriter outputPW;

    FileWriter outputFW;

    outputFW = new FileWriter ("message.txt");

    outputPW = new PrintWriter (outputFW);

    c.println ("Enter your text now. Use the character '*' as an EOF ON A SEPARATE LINE");

    createdfile = c.readLine ();

    while (!(createdfile.equals ("999")))

    {

    outputPW.println (createdfile); // print each string on to file

    createdfile = c.readLine ();

    }

    outputPW.println ("999"); // final string marker - physical EOF

    outputFW.close ();

    outputPW.close ();

    // All files from the java.io.* package MUST be closed in order to have the

    // file successfully created. REMBEMBER THIS!!

    c.println ("FILE HAS SUCCESSFULLY BEEN CREATED");

    readbacker ();

    } // Allan_yao_file_1 class

    public static void readbacker () throws IOException

    {

    int counterA = 0;

    int counterE = 0;

    int counterI = 0;

    int counterO = 0;

    int counterU = 0;

    BufferedReader inputBR;

    FileReader inputFR;

    // the BufferedReader and FileReader are classess from java.io

    inputFR = new FileReader ("message.txt");

    inputBR = new BufferedReader (inputFR);

    // NOTE ALL text files are READ BACK LINE BY LINE!

    createdfile = inputBR.readLine ();

    while (!(createdfile.equals ("999")))

    {

    c.println (createdfile);

    createdfile = inputBR.readLine ();

    int lengthOfString = createdfile.length ();

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

    {

    char ch = createdfile.charAt (i);

    if (ch == 'a' || ch == 'A' )

    {

    counterA++;

    }

    if (ch == 'E' || ch == 'e')

    {

    counterE++;

    }

    if (ch == 'i' || ch == 'I' )

    {

    counterI++;

    }

    if (ch == 'O' || ch == 'o' )

    {

    counterO++;

    }

    if (ch == 'u' || ch == 'U' )

    {

    counterU++;

    }

    }

    if (createdfile.equals ("999"))

    {

    c.println ("There are " + counterA + " a's in this file");

    c.println ("There are " + counterE + " e's in this file");

    c.println ("There are " + counterI + " i's in this file");

    c.println ("There are " + counterO + " o's in this file");

    c.println ("There are " + counterU + " u's in this file");

    }

    }

    }

    }

    I don't know why but it seems the first line of my file does not work. I don't know what is the problem???

    for example: I enter these values:

    a

    e

    i

    o

    u

    999

    it doesn't count a , so it doesn't count the vowel of the first line?

    Anyone has any ideas?

    A detailed explanation is appreciated.

    2 AnswersProgramming & Design9 years ago
  • Program file problem?Counting vowels?

    This program can't count right

    i don't know what is wrong

    can anyone help me?????????

    // The "Allan_yao_file_1" class.

    import java.awt.*;

    import hsa.Console;

    import java.io.*;

    import java.util.*;

    public class Allan_yao_file_1

    {

    static Console c; // The output console

    static String createdfile;

    public static void main (String[] args) throws IOException

    {

    c = new Console ();

    PrintWriter outputPW;

    FileWriter outputFW;

    outputFW = new FileWriter ("message.txt");

    outputPW = new PrintWriter (outputFW);

    c.println ("Enter your text now. Use the character '*' as an EOF ON A SEPARATE LINE");

    createdfile = c.readLine ();

    while (!createdfile.equals ("*"))

    {

    outputPW.println (createdfile); // print each string on to file

    createdfile = c.readLine ();

    }

    outputPW.println ("EOF"); // final string marker - physical EOF

    outputFW.close ();

    outputPW.close ();

    // All files from the java.io.* package MUST be closed in order to have the

    // file successfully created. REMBEMBER THIS!!

    c.println ("FILE HAS SUCCESSFULLY BEEN CREATED");

    readbacker ();

    } // Allan_yao_file_1 class

    public static void readbacker () throws IOException

    {

    int counterA = 0;

    int counterE = 0;

    int counterI = 0;

    int counterO = 0;

    int counterU = 0;

    BufferedReader inputBR;

    FileReader inputFR;

    // the BufferedReader and FileReader are classess from java.io

    inputFR = new FileReader ("message.txt");

    inputBR = new BufferedReader (inputFR);

    // NOTE ALL text files are READ BACK LINE BY LINE!

    createdfile = inputBR.readLine ();

    while (!createdfile.equals ("EOF"))

    {

    c.println (createdfile);

    createdfile = inputBR.readLine ();

    int lengthOfString = createdfile.length ();

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

    {

    char ch = createdfile.charAt (i);

    if (ch == 'a' || ch == 'A' )

    {

    counterA++;

    }

    if (ch == 'E' || ch == 'e')

    {

    counterE++;

    }

    if (ch == 'i' || ch == 'I' )

    {

    counterI++;

    }

    if (ch == 'O' || ch == 'o' )

    {

    counterO++;

    }

    if (ch == 'u' || ch == 'U' )

    {

    counterU++;

    }

    }

    if (createdfile.equals ("EOF"))

    {

    c.println ("There are " + counterA + " a's in this file");

    c.println ("There are " + counterE + " e's in this file");

    c.println ("There are " + counterI + " i's in this file");

    c.println ("There are " + counterO + " o's in this file");

    c.println ("There are " + counterU + " u's in this file");

    }

    }

    }

    }

    For instance, if the text file contains nothing, it still counts 1 o and 1 e, i don't know what is wrong

    3 AnswersProgramming & Design9 years ago
  • Java File program help?

    Write a well structured program (minimum 10 programmer comments) that utilizes a minimum of two user-defined methods (parameter lists not required) in a menu format to accomplish the following:

    First Method- Creates a file of string values that contains an appropriate EOF marker written at the end of the file.

    (See demos )

    Second Method- Reads back the string file and counts the number of EACH vowel ( A E I O U both upper and lower case) present. Remember that files are read as Strings, line by line! String methods are required..

    The output should print out the contents of the text file and a break down of each vowel

    1 AnswerProgramming & Design9 years ago
  • Java Array Program Help?

    Write a well structured program that accomplishes the following using a menu option format:

    -create a dynamic list of 25 random integers between 0 and 100.

    -Sort and print out the list in ascending order using the bubble sort

    -Sort and print out the list in descending order using the bubble sort

    -Exit the program

    Example: Enter your selection

    1……. Create a list of 25 random integers

    2……. Sort and print the list in ascending order

    3……. Sort and print the list in descending order

    4……. Exit program

    I really don't understand how this program works......

    Please explain clearly if you want me to choose your answer as best answer.

    1 AnswerProgramming & Design9 years ago
  • Java programming? Array total?

    I basically finished the program, but I need to verify that the total is 100? How do I add them all up?

    import java.awt.*;

    import hsa.Console;

    public class NestedList5_3

    {

    static Console c; // The output console

    // generate 100 numbers between 1 and 10. Count the number of 1's,2's etc

    public static void main (String[] args)

    {

    c = new Console ();

    int num[] = new int [100];

    int count[] = new int [10];

    int i, j, tot = 0;

    for (i = 0 ; i < num.length ; i++)

    {

    num [i] = (int) (Math.random () * 10) + 1;

    for (j = 0 ; j < count.length ; j++)

    {

    if (num [i] == j + 1)

    count [j]++;

    }

    }

    for (j = 0 ; j < 10 ; j++)

    c.println ("number of " + (j + 1) + " is " + count [j]);

    } // main method

    } // NestedList5_3 class

    How do I add the total up which will result to 100?

    2 AnswersProgramming & Design10 years ago
  • Java Array program? Largest and Smallest?

    How do you write a program that generates 40 different random numbers and prints the smallest and largest.

    all must be in a loop (do while)

    must all be printed on different lines

    elements, 1st line

    smallest, 2nd line

    largest, 3 rd line

    2 AnswersProgramming & Design10 years ago
  • Java program? Array Random Number Frequency?

    The assignment requires to write an array program that uses array counters, random numbers generated in arrays and able to calculate the frequency(# of occurrences) of each number.

    random number limit is 1 -49 and create 49 array counters

    what is an array counter?

    how to do write the program?

    1 AnswerProgramming & Design10 years ago
  • Gr.11 Physics Problem? Two unknowns, three intervals?

    The velocity of an uniformly accelearted particle at point P is 50 cm/s. The time for the particle to travel the 100 cm just past point P is twice the time for the object to just 100 cm before point P. Calculate the distance between point P and point when particle is at rest.

    Show all your work plz.

    1 AnswerPhysics10 years ago
  • GUI program problem? (numberguess)?

    This is a program of a number guessing game.

    // The "Allan_yao_4_4_January" class.

    import java.awt.*;

    import javax.swing.*;

    import java.util.*;

    import java.awt.event.*;

    public class Allan_yao_4_4_January extends JFrame implements ActionListener

    {

    private int number1;

    private int guess1;

    private int highest1;

    private int lowest1;

    private JTextField guessInput1;

    private JTextField message1;

    private JLabel text1;

    private JLabel text2;

    private JButton newGame1;

    private Color background1;

    Container container1;

    public Allan_yao_4_4_January ()

    {

    super ("Number Guessing Game");

    highest1 = 100;

    lowest1 = 0;

    text1 = new JLabel ("I have a number between 1 and " + "100.");

    text2 = new JLabel ("Can you guess my " + "number? Enter your Guess:");

    guessInput1 = new JTextField (10);

    guessInput1.addActionListener (this);

    message1 = new JTextField ("<------------------", 15);

    message1.setEditable (false);

    newGame1 = new JButton ("New Game");

    newGame1.addActionListener (this);

    container1 = getContentPane ();

    container1.setLayout (new FlowLayout ());

    container1.add (text1);

    container1.add (text2);

    container1.add (guessInput1);

    container1.add (message1);

    container1.add (newGame1);

    container1.setBackground (Color.white);

    setSize (500, 300);

    setVisible (true);

    theGame1 ();

    } // Constructor

    public void theGame1 ()

    {

    number1 = (int) (Math.random () * 100 + 1);

    }

    // react to new guess

    public void react1 (int guess1)

    {

    // guess is too high

    if (guess1 > number1)

    {

    message1.setText ("Too High");

    // warmer

    if (guess1 < lowest1)

    {

    lowest1 = guess1;

    container1.setBackground (Color.red);

    }

    // colder

    else

    container1.setBackground (Color.blue);

    }

    // guess is too low

    else if (guess1 < number1)

    {

    message1.setText ("Too Low");

    // warmer

    if (guess1 > highest1)

    {

    highest1 = guess1;

    container1.setBackground (Color.red);

    }

    // colder

    else

    container1.setBackground (Color.blue);

    }

    // guess is correct

    else

    {

    message1.setText ("Correct!");

    container1.setBackground (Color.magenta);

    guessInput1.setEditable (false);

    lowest1 = 100;

    highest1 = 0;

    }

    }

    public static void main (String args[])

    {

    Allan_yao_4_4_January app = new Allan_yao_4_4_January ();

    app.setDefaultCloseOperation (EXIT_ON_CLOSE);

    }

    public void actionPerformed (ActionEvent e)

    {

    if (e.getSource () == newGame1)

    {

    container1.setBackground (Color.white);

    message1.setText ("<------------------");

    guessInput1.setText ("");

    guessInput1.setEditable (true);

    theGame1 ();

    repaint ();

    }

    else if (e.getSource () == guessInput1)

    {

    guess1 = Integer.parseInt (guessInput1.getText ());

    react1 (guess1);

    }

    }

    // main method

    } // Allan_yao_4_4_January class

    For some reason, the program will not allow me to enter more than once, therefore, you can only enter a number once.

    If you enter the number a second time, nothing will happen.

    Can anyone help me find the problem?

    2 AnswersProgramming & Design10 years ago