sorting price in ascending order

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

41 Replies - 685 Views - Last Post: 03 June 2019 - 10:17 AM Rate Topic: -----

#31 arexxa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 31-May 19

Re: sorting price in ascending order

Posted 03 June 2019 - 01:50 AM

im done with the searching problems. so it work. but right now my problem is my sorting doesnt work. can you help me? this is the code:

public void bubbleSort(){
        lastNode = new ListNode(o);
        lastNode.next = head;
        head = lastNode;
        
        while(lastNode.next != null){
            currNode = lastNode.next;
            firstNode = lastNode;
            a = currNode.next;
            while(a != null){
                if(a.data.calcBed() < currNode.data.calcBed()){
                    ListNode temp = a.next;
                    a.next = firstNode.next;
                    firstNode.next = currNode.next;
                    currNode.next = temp;
                    firstNode = a;
                    a = temp;
                }
                else{
                    a = a.next;
                    currNode = currNode.next;
                    firstNode = firstNode.next;
                }
            }
            lastNode = lastNode.next;
        }
        head = head.next;
    }



im done with the searching problems. so it work. but right now my problem is my sorting doesnt work. can you help me? this is the code:

public void bubbleSort(){
        lastNode = new ListNode(o);
        lastNode.next = head;
        head = lastNode;
        
        while(lastNode.next != null){
            currNode = lastNode.next;
            firstNode = lastNode;
            a = currNode.next;
            while(a != null){
                if(a.data.calcBed() < currNode.data.calcBed()){
                    ListNode temp = a.next;
                    a.next = firstNode.next;
                    firstNode.next = currNode.next;
                    currNode.next = temp;
                    firstNode = a;
                    a = temp;
                }
                else{
                    a = a.next;
                    currNode = currNode.next;
                    firstNode = firstNode.next;
                }
            }
            lastNode = lastNode.next;
        }
        head = head.next;
    }


Was This Post Helpful? 0
  • +
  • -

#32 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: sorting price in ascending order

Posted 03 June 2019 - 03:57 AM

Print out the order of the list before the sort is called and again after the sort to show the problem and post the output here so we can see.

This post has been edited by NormR: 03 June 2019 - 04:09 AM

Was This Post Helpful? 0
  • +
  • -

#33 arexxa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 31-May 19

Re: sorting price in ascending order

Posted 03 June 2019 - 04:14 AM

i do what you have told me to do. the output only take the first item in the linkedlist if i just simply call the method and display..but when i do looping condition like this:

        //display the item in the linked
        System.out.println("\n********THE DETAILS IN bedMatt********");
        a = bedMatt.getFirst();
        while(a != null){
            System.out.println(a.toString());
            a = bedMatt.getNext();
        }
        System.out.println("\n**************************************");

        System.out.println("Sorting price in ascending order");
        bedMatt.bubbleSort();
        a = bedMatt.getFirst();
        System.out.println(a.toString());



but if i do like this,there is the error where nullPointerException
        System.out.println("Sorting price in ascending order");
        bedMatt.bubbleSort();
        a = bedMatt.getFirst();
        while(a != null){

        System.out.println(a.toString());



i do what you have told me to do. the output only take the first item in the linkedlist if i just simply call the method and display..but when i do looping condition like this:

        //display the item in the linked
        System.out.println("\n********THE DETAILS IN bedMatt********");
        a = bedMatt.getFirst();
        while(a != null){
            System.out.println(a.toString());
            a = bedMatt.getNext();
        }
        System.out.println("\n**************************************");

        System.out.println("Sorting price in ascending order");
        bedMatt.bubbleSort();
        a = bedMatt.getFirst();
        System.out.println(a.toString());



but if i do like this,there is the error where nullPointerException occur at the line getNext()
        System.out.println("Sorting price in ascending order");    
        bedMatt.bubbleSort();
        a = bedMatt.getFirst();
        while(a != null){
            System.out.println(a.toString());
            a = bedMatt.getNext();
        }


Was This Post Helpful? 0
  • +
  • -

#34 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: sorting price in ascending order

Posted 03 June 2019 - 04:33 AM

Sorry, it is hard to see what is happening with only a few lines of code. Can you post ALL of the code for the program so it can be compiled and executed for testing so we can see what is happening.
Was This Post Helpful? 0
  • +
  • -

#35 arexxa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 31-May 19

Re: sorting price in ascending order

Posted 03 June 2019 - 05:08 AM

class bedMattress:
public class bedMattress
{
    private String type;
    private String typeBed;
    private String typeMattress;

    //normal constructor
    public bedMattress(String type,String typeBed,String typeMattress)
    {
        this.type = type;
        this.typeBed=typeBed;
        this.typeMattress=typeMattress;
    }
    
    //mutator
    public void setType(String type){
        type = type;
    }
    public void setBed(String typeBed)
    {
        typeBed=typeBed;
    }
    public void setPriceBed(double priceBed)
    {
        priceBed=priceBed;
    }
    public void setMattress(String typeMattress)
    {
        typeMattress=typeMattress;
    }
    public void setPriceMattress(double priceMattress)
    {
        priceMattress=priceMattress;
    }
    
    //accessor
    public String getType(){
        return type;
    }
    public String getBed()
    {
        return typeBed;
    }
    public String getMattress()
    {
        return typeMattress;
    }
    
    //method
    public double calcBed()
    {
        double priceBed=0.00;
        if(typeBed.equalsIgnoreCase("Cabin"))
        {
            priceBed=239;
            typeBed="Cabin";
        }
        else if(typeBed.equalsIgnoreCase("Bunk"))
        {
            priceBed=279;
            typeBed="Bunk";
        }
        else if(typeBed.equalsIgnoreCase("Ottoman"))
        {
            priceBed=289;
            typeBed="Ottoman";
        }
        else if(typeBed.equalsIgnoreCase("Guest"))
        {
            priceBed=299;
            typeBed="Guest";
        }
        else if(typeBed.equalsIgnoreCase("Divan"))
        {
            priceBed=329;
            typeBed="Divan";
        }
        else if(typeBed.equalsIgnoreCase("Sleigh"))
        {
            priceBed=349;
            typeBed="Sleigh";
        }
        else
        {
            priceBed=0.00;
        }
        return priceBed;
    }  
    
    public double calcMattress()
    {      
        double priceMattress=0.00;
        if(typeMattress.equalsIgnoreCase("Foam"))
        {
            priceMattress=890;
            typeMattress="Foam";
        }
        else if(typeMattress.equalsIgnoreCase("Innerspring"))
        {
            priceMattress=950;
            typeMattress="Innerspring";
        }
        else if(typeMattress.equalsIgnoreCase("MemoryFoam"))
        {
            priceMattress=1370;
            typeMattress="MemoryFoam";
        }
        else if(typeMattress.equalsIgnoreCase("Hybrid"))
        {
            priceMattress=1975;
            typeMattress="Hybrid";
        }
        else if(typeMattress.equalsIgnoreCase("Latex"))
        {
            priceMattress=2200;
            typeMattress="Latex";
        }
        else
        {
            priceMattress=0.00;
        }
        return priceMattress;
    }
    
    public String toString()
    {
        return   "\nBed     : "+ typeBed + "\t\tPrice of Bed     : RM" + calcBed()
                +"\nMattress: "+ typeMattress + "\t\tPrice of Mattress: RM" + calcMattress();
    }
}



class LinkedList:
public class LinkedList{
    private ListNode firstNode;
    private ListNode lastNode;
    private ListNode currNode;
    private ListNode head;
    private ListNode a;
    private String type;
    bedMattress o;

    
    public LinkedList(String t){
        type = t;
        firstNode = lastNode = currNode = null;
    }
    
    public LinkedList(){
        this("linked list");
    }
    
    public void insertAtFront(bedMattress insertItem){
        if(isEmpty())
            firstNode = lastNode = new ListNode(insertItem);
        else
            firstNode = new ListNode(insertItem,firstNode);
    }
    
    public void insertAtBack(bedMattress insertItem){
        if(isEmpty())
            firstNode = lastNode = new ListNode(insertItem);
        else
            lastNode = lastNode.next = new ListNode(insertItem);
    }
    
    public void insertAfter(bedMattress insertItem, ListNode next){
        ListNode tmp = firstNode;
        while(tmp != null && !tmp.data.equals(insertItem))
            tmp = tmp.next;
        
        if(tmp != null){
            tmp.next = new ListNode(insertItem,tmp.next);
        }
    }
    
    public Object removeFromFront() throws EmptyListException{
        Object removeItem = null;
        if(isEmpty())
            throw new EmptyListException(type);
            
        removeItem = firstNode.data;
        
        if(firstNode.equals(lastNode))
            firstNode = lastNode = null;
        else
            firstNode = firstNode.next;
            
        return removeItem;
    }
    
    public Object removeFromBack()throws EmptyListException{
        Object removeItem = null;
        if(isEmpty())
            throw new EmptyListException(type);
            
        removeItem = lastNode.data;
        
        if(firstNode.equals(lastNode))
            firstNode = lastNode = null;
        else{
            ListNode current = firstNode;
            while(current.next != firstNode)
                current = current.next;
            lastNode = current;
            current.next = null;
        }
        return removeItem;
    }
    
    public boolean isEmpty(){
        return firstNode == null;
    }
    
    public Object getFirst(){
        if(isEmpty())
            return null;
        else{
            currNode = firstNode;
            return currNode.data;
        }
    }
    
    public bedMattress getNext(){
        if(currNode != lastNode){
            currNode = currNode.next;
            return currNode.data;
        }
        else
            return null;
    }
    
    public void bedDetail(String search){
        currNode = firstNode;
        while(currNode!= null){
            if(currNode.data.getBed().equalsIgnoreCase(search)){
                System.out.println("Type of Bed: " + currNode.data.getBed());
                System.out.println("Bed Price:RM " + currNode.data.calcBed());
            }
            currNode = currNode.next;
        }
    }
    
    public void mattDetail(String search){
        currNode = firstNode;
        while(currNode!= null){
            if(currNode.data.getMattress().equalsIgnoreCase(search)){
                System.out.println("Type of Mattress: " + currNode.data.getMattress());
                System.out.println("Mattress Price:RM " + currNode.data.calcMattress());
            }
            currNode = currNode.next;
        }
    }
        
    public void bubbleSort(){
        lastNode = new ListNode(o);
        lastNode.next = head;
        head = lastNode;
        
        while(lastNode.next != null){
            currNode = lastNode.next;
            firstNode = lastNode;
            a = currNode.next;
            while(a != null){
                if(a.data.calcBed() < currNode.data.calcBed()){
                    ListNode temp = a.next;
                    a.next = firstNode.next;
                    firstNode.next = currNode.next;
                    currNode.next = temp;
                    firstNode = a;
                    a = temp;
                }
                else{
                    a = a.next;
                    currNode = currNode.next;
                    firstNode = firstNode.next;
                }
            }
            lastNode = lastNode.next;
        }
        head = head.next;
    }
}
        



class ListNode:
public class ListNode{
    bedMattress data;
    ListNode next;
    
    ListNode(bedMattress o){
        this(o,null);
    }
    
    ListNode(bedMattress o, ListNode nextNode){
        data = o;
        next = nextNode;
    }
    
    bedMattress getbedMattress(){
        return data;
    }
    
    ListNode getLink(){
        return next;
    }
}



class Exceptional:
public class EmptyListException extends RuntimeException{
    public EmptyListException(String type){
        super("The " + type + "is empty");
    }
}



class queue:
import java.util.LinkedList;
public class Queue
{   
    protected LinkedList list;
    
    public Queue(){
        list=new LinkedList();
    }
    
    public boolean isEmpty(){
        return list.isEmpty();
    }
    
    public int size(){
        return list.size();
    }
    
    public void enqueue(Object element){
        list.addLast(element);
    }
    
    public Object dequeue(){
        return list.removeFirst();
    }
    
    public Object front(){
        return list.getFirst();
    }
    
    public Object rear(){
        return list.getLast();
    }
}



test class:
import javax.swing.*;
import java.util.*;
public class Test1{
    public static void main(String[] args){
        LinkedList bedMatt = new LinkedList();
        Queue bedMattQ = new Queue();
        String type=" ", typeBed=" ", typeMattress=" ";
        int countBed = 100, countMatt=100;
        Object a;
        
        //USER INPUT
        for(int i = 0; i<4; i++){
            type = JOptionPane.showInputDialog("Insert type [Bed || Mattress] ");
            if(type.equalsIgnoreCase("Bed")){
                typeBed = JOptionPane.showInputDialog("Insert type of bed ");
                countBed++;
            }
            else if(type.equalsIgnoreCase("Mattress")){
                typeMattress = JOptionPane.showInputDialog("Insert type of mattress ");
                countMatt++;
            }
            
            bedMattress bm = new bedMattress(type,typeBed,typeMattress);
            bedMatt.insertAtBack(bm);
            bedMattQ.enqueue(bm);
        }
        System.out.print("\nTOTAL BED OF ALL TYPE: " + countBed);
        System.out.print("\nTOTAL MATTRESS OF ALL TYPE: " + countMatt);
        System.out.println();
        
        //DISPLAY THE LIST IN bedMatt
        System.out.println("\n********THE DETAILS IN bedMatt********");
        a = bedMatt.getFirst();
        while(a != null){
            System.out.println(a.toString());
            a = bedMatt.getNext();
        }
        System.out.println("\n**************************************");
        
        //SEARCHING FOR TYPE OF BED
        bedMattress temp = (bedMattress)bedMatt.getFirst();
        String srcB = JOptionPane.showInputDialog("Search for bed: ");
        System.out.println("\nSearching for bed selected....");
        bedMatt.bedDetail(srcB);
        //SEARCHING FOR TYPE OF MATTRESS
        String srcM = JOptionPane.showInputDialog("Search for mattress: ");
        System.out.println("\nSearching for mattress selected....");
        bedMatt.mattDetail(srcM);
        
        //CALCULATING THE MAXIMUM PRICE OF BED AND MATTRESS
        System.out.println("\n--------------MAXIMUM PRICCE-------------");
        temp = (bedMattress)bedMatt.getFirst();
        double highBed = 0.00;
        String outBed = "TYPE OF BED: " + temp.getBed() + "\tPRICE: RM" + temp.calcBed();
        while(temp != null){
            if(temp.calcBed() > highBed){
                highBed = temp.calcBed();
                outBed = "TYPE OF BED: " + temp.getBed() + "\tPRICE: RM" + highBed;
            }
            temp = (bedMattress)bedMatt.getNext();
        }
        System.out.println("\nTHE HIGHEST PRICE FOR BED"+"\n"+outBed);
        
        temp = (bedMattress)bedMatt.getFirst();
        double highMatt = 0.00;
        String outMatt = "TYPE OF MATTRESS: " + temp.getMattress() + "\tPRICE: RM" + temp.calcMattress();
        while(temp != null){
            if(temp.calcMattress() > highMatt){
                highMatt = temp.calcMattress();
                outMatt = "TYPE OF MATTRESS: " + temp.getMattress() + "\tPRICE: RM" + highMatt;
            }
            temp = (bedMattress)bedMatt.getNext();
        }
        System.out.println("\nTHE HIGHEST PRICE FOR MATTRESS"+"\n"+outMatt);
        System.out.println("------------------------------------------");

        //SEPARATE THE LIST OF BED AND MATTRESS IN TWO DIFFERENTS QUEUE
        Queue bedQ = new Queue();
        Queue mattQ = new Queue();
        while(!bedMattQ.isEmpty()){
            bedMattress temp1 = (bedMattress)bedMattQ.dequeue();
            if(temp1.getType().equalsIgnoreCase("Bed")){
                bedQ.enqueue(temp1);
            }
            else if(temp1.getType().equalsIgnoreCase("Mattress")){
                mattQ.enqueue(temp1);
            }
        }
        
        //DISPLAY THE LIST OF BED AND MATTRESS AND THE TOTAL SUM OF PRICE FOR BOTH TYPE
        System.out.println("------------------------------------------");
        System.out.println("******************************************");
        String outB = "LIST OF BED!!!\nTYPE\tTYPE OF BED\tPRICE(RM)\n";
        String outM = "LIST OF MATTRESS!!!\nTYPE\tTYPE OF MASTTRESS\tPRICE(RM)\n";
        double sumBed = 0.00,sumMatt = 0.00;
        while(!bedQ.isEmpty()){
            temp = (bedMattress)bedQ.dequeue();
            outB += temp.getType() + "\t" + temp.getBed() + "\t\t" + temp.calcBed() + "\n";
            sumBed += temp.calcBed();
        }
        System.out.println(outB);
        System.out.println("###TOTAL PRICE OF BED IN bedQ: RM" + sumBed);
        System.out.println();
        
        while(!mattQ.isEmpty()){
            temp = (bedMattress)mattQ.dequeue();
            outM += temp.getType() + "\t" + temp.getMattress() + "\t\t" + temp.calcMattress() + "\n";
            sumMatt += temp.calcMattress();
        }
        System.out.println(outM);
        System.out.println("###TOTAL PRICE OF MATTRESS IN mattQ: RM" + sumMatt);
        System.out.println("******************************************");
        System.out.println();    
    
        //SORTING IN ASCENDING ORDER
        System.out.println("Sorting price in ascending order");
        bedMatt.bubbleSort();
        a = bedMatt.getFirst();
        while(a != null){
            System.out.println(a.toString());
            a = bedMatt.getNext();
        }    
    }
}


Was This Post Helpful? 0
  • +
  • -

#36 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: sorting price in ascending order

Posted 03 June 2019 - 06:06 AM

The code requires too much precise user input for easy testing. The JOptionPane prompts allow freely formatted input but the code requires precise inputs.
It will take some time to come up with a testing scheme.

Please post the inputs you are using for testing so that I can include them in my testing scheme.
Was This Post Helpful? 0
  • +
  • -

#37 arexxa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 31-May 19

Re: sorting price in ascending order

Posted 03 June 2019 - 07:15 AM

the input that i enter is:

type=bed
type of bed = cabin
type = bed
type of bed = bunk

type = mattress
type of mattress = foam
type = mattress
type of mattress = hybrid
Was This Post Helpful? 0
  • +
  • -

#38 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: sorting price in ascending order

Posted 03 June 2019 - 09:08 AM

Ok, that is some of the required input. What is the rest of the input to the program?
I need ALL of what you type into the JOptionPane windows for testing.
Was This Post Helpful? 0
  • +
  • -

#39 arexxa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 31-May 19

Re: sorting price in ascending order

Posted 03 June 2019 - 09:11 AM

type: bed
type of bed:
cabin
bunk
ottoman
guest
divan
sleigh

tpe: mattress
type of mattress:
foam
innerspring
memoryFoam
hybrid
latex
Was This Post Helpful? 0
  • +
  • -

#40 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: sorting price in ascending order

Posted 03 June 2019 - 09:19 AM

Sorry, that is not what I am asking for.
I need the exact text that you enter into the JOptionPane windows.
After I input this:

Quote

bed
cabin
bed
bunk

mattress
foam
mattress
hybrid

The program wants more input. What do you enter next?

Also can you copy the full contents of the console window from when you execute the program that shows the problem and paste it here?

This post has been edited by NormR: 03 June 2019 - 09:21 AM

Was This Post Helpful? 0
  • +
  • -

#41 arexxa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 31-May 19

Re: sorting price in ascending order

Posted 03 June 2019 - 09:37 AM

View Postarexxa, on 03 June 2019 - 09:11 AM, said:

type: bed
type of bed:
cabin
bunk
ottoman
guest
divan
sleigh

tpe: mattress
type of mattress:
foam
innerspring
memoryFoam
hybrid
latex


this is the input for detail.. then program ask to search for bed, i input bunk
then search for mattress, i input foam.

this is the output from console:

TOTAL BED OF ALL TYPE: 102
TOTAL MATTRESS OF ALL TYPE: 102

********THE DETAILS IN bedMatt********

Bed : bunk Price of Bed : RM279.0
Mattress: Price of Mattress: RM0.0

Bed : cabin Price of Bed : RM239.0
Mattress: Price of Mattress: RM0.0

Bed : cabin Price of Bed : RM239.0
Mattress: foam Price of Mattress: RM890.0

Bed : cabin Price of Bed : RM239.0
Mattress: hybrid Price of Mattress: RM1975.0

**************************************

Searching for bed selected....
Type of Bed: Bunk
Bed Price:RM 279.0

Searching for mattress selected....
Type of Mattress: Foam
Mattress Price:RM 890.0

--------------MAXIMUM PRICCE-------------

THE HIGHEST PRICE FOR BED
TYPE OF BED: Bunk PRICE: RM279.0

THE HIGHEST PRICE FOR MATTRESS
TYPE OF MATTRESS: Hybrid PRICE: RM1975.0
------------------------------------------
Sorting price in ascending order

Bed : Bunk Price of Bed : RM279.0
Mattress: Price of Mattress: RM0.0

Bed : Cabin Price of Bed : RM239.0
Mattress: Price of Mattress: RM0.0

Bed : Cabin Price of Bed : RM239.0
Mattress: Foam Price of Mattress: RM890.0

Bed : Cabin Price of Bed : RM239.0
Mattress: Hybrid Price of Mattress: RM1975.0

View Postarexxa, on 03 June 2019 - 09:36 AM, said:

View Postarexxa, on 03 June 2019 - 09:11 AM, said:

type: bed
type of bed:
cabin
bunk
ottoman
guest
divan
sleigh

tpe: mattress
type of mattress:
foam
innerspring
memoryFoam
hybrid
latex


this is the input for detail.. then program ask to search for bed, i input bunk
then search for mattress, i input foam.

this is the output from console:

TOTAL BED OF ALL TYPE: 102
TOTAL MATTRESS OF ALL TYPE: 102

********THE DETAILS IN bedMatt********

Bed : bunk Price of Bed : RM279.0
Mattress: Price of Mattress: RM0.0

Bed : cabin Price of Bed : RM239.0
Mattress: Price of Mattress: RM0.0

Bed : cabin Price of Bed : RM239.0
Mattress: foam Price of Mattress: RM890.0

Bed : cabin Price of Bed : RM239.0
Mattress: hybrid Price of Mattress: RM1975.0

**************************************

Searching for bed selected....
Type of Bed: Bunk
Bed Price:RM 279.0

Searching for mattress selected....
Type of Mattress: Foam
Mattress Price:RM 890.0

--------------MAXIMUM PRICCE-------------

THE HIGHEST PRICE FOR BED
TYPE OF BED: Bunk PRICE: RM279.0

THE HIGHEST PRICE FOR MATTRESS
TYPE OF MATTRESS: Hybrid PRICE: RM1975.0
------------------------------------------
Sorting price in ascending order

Bed : Bunk Price of Bed : RM279.0
Mattress: Price of Mattress: RM0.0

Bed : Cabin Price of Bed : RM239.0
Mattress: Price of Mattress: RM0.0

Bed : Cabin Price of Bed : RM239.0
Mattress: Foam Price of Mattress: RM890.0

Bed : Cabin Price of Bed : RM239.0
Mattress: Hybrid Price of Mattress: RM1975.0



error occur at sorting where NullPointerException
Was This Post Helpful? 0
  • +
  • -

#42 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: sorting price in ascending order

Posted 03 June 2019 - 10:17 AM

Quote

error occur at sorting where NullPointerException

Please copy the full text of the console that shows the exception and paste it here.


For anyone else following this thread that would like to try debugging it,
here is the class I use to provide all input required by the program.
Put this class inside of the class that uses JOptionPane.

   //-----------------------------------------------------------
   //  Following class for testing
   static class JOptionPane {        //  3/12/13
      static String[] retVals = {"bed", "cabin","bed", "bunk", 
                                 "mattress", "foam", "mattress", "hybrid",
                                 "bunk", "foam"};  //  the responses to be returned by showInput
      static int idx = 0;  // index to above

      static public String showInputDialog(Object obj, String msg) {
         return showInputDialog(msg);
      }
      static public String showInputDialog(Object obj, String msg, String t, int i) {
         return showInputDialog(msg);
      }
   

      static public String showInputDialog(String msg) {
         System.out.println(msg + " >Return val="+retVals[idx]);
         return retVals[idx++];
      }

      static public void showMessageDialog(Object obj1, String msg) {
            System.out.println(msg);
      }
   
      static public void showMessageDialog(Object parent, Object msg, String title, int type) {
            System.out.println(msg);
      }
   
      static int INFORMATION_MESSAGE = 1;
      static int QUESTION_MESSAGE = 2;
      static int ERROR_MESSAGE = 3;
   }   //  end JOptionPane class for testing <<<<<<<<<<<<<<<<<<



This post has been edited by NormR: 03 June 2019 - 03:54 PM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3