Question

Please help, Array does not print properly. I need to print out the 8 class numbers...

Please help, Array does not print properly. I need to print out the 8 class numbers entered by the user !

Java only using J option pane, you cannot use ulti or anything else only J option pane

Program compiles but does not print the array correctly!

import javax.swing.JOptionPane;

public class programtrial {

   public static void main(String[] args) {
   int newclass = 0;
   int countclass = 0;
   final int class_Max = 8;
   int[] classarray = new int[class_Max];
  
  
   do {
  
for(int i = 0; i < classarray.length; i++){
   do {
   newclass = Integer.parseInt(JOptionPane.showInputDialog("Enter the class number "));
   try {
  
   }
   catch (NumberFormatException e) {
newclass =-1;
}

if( newclass <0) {
JOptionPane.showMessageDialog(null, "Invalid try again");
}

} while(newclass <0);

classarray[countclass] = newclass;
   ++countclass;
   }
  
}while(countclass != class_Max);


   JOptionPane.showMessageDialog(null, classarray);

}}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javax.swing.JOptionPane;

public class programtrial {

    public static void main(String[] args) {
        int newclass = 0;
        int countclass = 0;
        final int class_Max = 8;
        int[] classarray = new int[class_Max];
        do {
            for (int i = 0; i < classarray.length; i++) {
                do {
                    try {
                        newclass = Integer.parseInt(JOptionPane.showInputDialog("Enter the class number "));
                    } catch (NumberFormatException e) {
                        newclass = -1;
                    }
                    if (newclass < 0) {
                        JOptionPane.showMessageDialog(null, "Invalid try again");
                    }
                } while (newclass < 0);
                classarray[countclass] = newclass;
                ++countclass;
            }
        } while (countclass != class_Max);
        String result = "";
        for (int i = 0; i < classarray.length; i++) {
            result += classarray[i] + " ";
        }
        JOptionPane.showMessageDialog(null, result);
    }
}
Add a comment
Know the answer?
Add Answer to:
Please help, Array does not print properly. I need to print out the 8 class numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm attempting to convert ch object array to double array public void calculateSalesPrice() { double salePrice[]...

    I'm attempting to convert ch object array to double array public void calculateSalesPrice() { double salePrice[] = new double[ch.length]; int p = 0; for (int i = 0; i < ch.length; i += 3) { p = i + 1; for(int j = 0;j } } error message:items.java:16: error: cannot find symbol for(int j = 0;j ^ symbol: variable length location: class Object items.java:17: error: array required, but Object found salePrice[j] = (double full program import java.io.File; import java.util.Scanner; import...

  • This is the source code: Please incorporate the Exception Handling import javax.swing.JOptionPane; import java.awt.*; public class...

    This is the source code: Please incorporate the Exception Handling import javax.swing.JOptionPane; import java.awt.*; public class GuessingGame { public static void main(String[] args) { int computerNumber = (int) (Math.random() * 10 + 1); System.out.println("The correct guess would be " + computerNumber); int userAnswer = 0; int count = 0; while (computerNumber != userAnswer) { count++; String response = JOptionPane.showInputDialog(null, "Enter a guess between 1 and 10"); userAnswer = Integer.parseInt(response); String result = null; if (userAnswer == computerNumber) { result =...

  • JAVA Please debug. Has 2 errors. Thanks ---------------------------------------- import javax.swing.*; public class UseCustomerAccount {     public...

    JAVA Please debug. Has 2 errors. Thanks ---------------------------------------- import javax.swing.*; public class UseCustomerAccount {     public static void main(String[] args)     {         int num;         double balance;         String input;                 input = JOptionPane.showInputDialog(null, "Enter an account number");         num = Integer.parseInt(input);         input = JOptionPane.showInputDialog(null, "Enter a balance due");         balance = Double.parseDouble(input);                 try         {             CustomerAccount ca = new CustomerAccount(num, balance);             JOptionPane.showMessageDialog(null, "Customer #" + num + " has a balance of...

  • Hi, for my Java class I have built a number guessing game. I need to separate...

    Hi, for my Java class I have built a number guessing game. I need to separate my code into two classes and incorporate a try-catch statement. Any help would be appreciated! Here is my code. import javax.swing.JOptionPane; import javax.swing.UIManager; import java.awt.Color; import java.awt.color.*; import java.util.Random; public class game { public static void main (String [] args) { UIManager.put("OptionPane.backround", Color.white); UIManager.put("Pandelbackround", Color.white); UIManager.put("Button.background", Color.white); Random nextRandom = new Random(); int randomNum = nextRandom.nextInt(1000); boolean playerCorrect = false; String keyboardInput; int playerGuess...

  • I need to return a dynamic array from a class member function and print out the...

    I need to return a dynamic array from a class member function and print out the results in main. using pointers and dynamic allocation is required. class example{ int *test public: example(int a){ test = new int[a]; for(int i=0;i<a;i++) test[i]=i; } int *send(){ return test;} } int main(){ example a(3); int *practice = a.send(); int psize = sizeof(a)/sizeof(a[0]); for(int i=0;i<psize;i++) cout <<practice[i] << endl; return 0; }

  • I tried to add exception handling to my program so that when the user puts in...

    I tried to add exception handling to my program so that when the user puts in an amount of change that is not the integer data type, the code will catch it and tell them to try again, but my try/catch isnt working. I'm not sure how to fix this problem. JAVA code pls package Chapter9; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUIlab extends JFrame implements ActionListener {    private static final int WIDTH = 300;    private...

  • Array with Iterator. Java style Implement an array data structure as a class JstyArray<E> to support...

    Array with Iterator. Java style Implement an array data structure as a class JstyArray<E> to support the Iterable interface such that the following code works: JstyArray<Integer> data; data = new JstyArray<Integer>(10); for (int i = 0; i < 10; ++i) { data.set(i, new Integer(i) ); } int sum = 0; for ( int v : data ) { if (v == null) continue; // empty cell sum += v; } The iterator provided by this class follows the behaviour of...

  • write a program which include a class containing an array of words (strings).The program will search...

    write a program which include a class containing an array of words (strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value. enhancements: make the array off words dynamic, so that the use is prompter to enter the list of words. make the word searcher for dynamic, so that a different word can be searched for each...

  • Having trouble with a Zoo Monitoring system. Using NetBeans. i have worked out most of the...

    Having trouble with a Zoo Monitoring system. Using NetBeans. i have worked out most of the bugs but now its only printing the first few lines of the text file (it prints the lines that begin with "Details" and not continuing to the rest to find the lines with ***** in them to pop up the Joption pane with the alert for that line. below is the code for both java files, as well as the .txt files its reading...

  • //please help I can’t figure out how to print and can’t get the random numbers to...

    //please help I can’t figure out how to print and can’t get the random numbers to print. Please help, I have the prompt attached. Thanks import java.util.*; public class Test { /** Main method */ public static void main(String[] args) { double[][] matrix = getMatrix(); // Display the sum of each column for (int col = 0; col < matrix[0].length; col++) { System.out.println( "Sum " + col + " is " + sumColumn(matrix, col)); } } /** getMatrix initializes an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT