#I need help with a Project for class

1 messages · Page 3 of 1

deep ravine
#

thats another check you can do, yeah

#
if(obj == this) {
    return true;
}```
#

although you shouldnt return false if its not

#

not something to worry about rn. all you need to worry about is the serials

left tartan
#

the this thing

#

before i had SRN there

#

would saying obj == this.SRN

deep ravine
#

nope

left tartan
#

no, its wrong

#

or no it won't be wrong?

deep ravine
#

that would be comparing the appliance itself to a serial number

#

rather than comparing 2 serial numbers

left tartan
#

oh

#

yeah ur right

deep ravine
#

the problem is, you cant access SRN from obj

#

obj.SRN does not work

#

otherwise you could just do this.SRN == obj.SRN (but using equals instead of ==)

left tartan
#

maybe i don't need to access it

deep ravine
#

you do

#

you want to access the serial from the object being compared

left tartan
#

then i don't know

deep ravine
#

thats the only way you'll be able to compare the serials

#

you need to introduce a new variable

#

remember Appliance o?

left tartan
#

yea

#

ok

#

so are u saying find a way to store the other serial number in o

deep ravine
#

we need to somehow access the serial number from obj

#

but the variable obj is Object

#

the actual value is Appliance, the variable obj will reference an Appliance object

#

but obj... its an Object

#

so, introduce a new variable, and assign obj to it

#
Appliance app = obj;```
#

Java wont let you do that directly, you gotta "cast"

left tartan
#

casting is just the parenthesis right

deep ravine
#
(Appliance) obj```
#

yup

left tartan
#

yup u just right that

#

no eqaul to?

#

Appliance app = (Appliance) obj ?

deep ravine
#

all this does is give you access to SRN

#

obj always had SRN. but since the variable datatype was Object, it wasnt visible

#

so you created a new variable, with the proper datatype

#

now you can access SRN

#

you still gotta check if the serials are equal

#

but now you have access to SRN, with your new variable

#

btw, once you're finished, make sure you look over this code like 20 times, make sure you understand every last drop

#

because these struggles are only temporary, if you take that route

#

otherwise, these struggles can last years

left tartan
#
 @Override
    public boolean equals(Object obj){
        if(obj instanceof Appliance){
            return true;
        }
            else{  
                return false;
            }
    
Appliance app = (Appliance) obj;
if(obj.equals(app))
return true;
}
deep ravine
left tartan
#

oh right the brackets

deep ravine
#

you need to think of the if, the branching thats going on

#

you should only compare if its an appliance

#

and you shouldnt just return true, you should only return true if the SRNs are equal

left tartan
#

oh i think i wrote it wrong

#

at least this part i need to know

#

Appliance app = (Appliance) obj;

#

did i properly cast it

deep ravine
#

yup

left tartan
#

ok so after i did that

#

i can use app to check with obj right

deep ravine
#

wait

left tartan
#

yea

deep ravine
#

you should only do that if obj is actually an appliance

#

show your current code

left tartan
#

right

#
 @Override
    public boolean equals(Object obj){
        if(obj instanceof Appliance){
            return true;
        }
            else{  
                return false;
            }
    
Appliance app = (Appliance) obj;
if(obj.equals(app))
return true;
}```
kind pathBOT
left tartan
#

its currently that rn

deep ravine
#

step through it

left tartan
#

if it returns true

#

it'll end?

#

before it reaches the other code

deep ravine
#

nah, step by step man, break it down, line by line

#

lets pretend someone calls this method. they pass in a Dog

#

first thing that happens? java if(obj instanceof Appliance)

left tartan
#

ok if obj in part of appliance, return true

deep ravine
#

but its a Dog being passed in

left tartan
#

then false

deep ravine
#

its not gonns return true, itll go to the else

#

correct

left tartan
#

wait

deep ravine
#

now, pretend an Appliance is passed in

left tartan
#

obj u said

#

can be anything

#

if it can be anything

#

it'll always be true

deep ravine
#

hm?

left tartan
#

no hold on i migth've mixed it up

deep ravine
#

line by line, think of it, don't jump to conclusions

left tartan
deep ravine
#

yes

left tartan
#

no but tis checking

#

that line isn't the problem

deep ravine
#

obj = new Dog(), it references a dog. what happens in your code? line by line

#

i know its not

#

your understanding is the problem

#

thats why we are stepping through

#

first thing that happens, first line

left tartan
#

ok if it gets dog

#

it'll go to else

#

like u said

deep ravine
#

yup, easy, method ends

left tartan
#

and then it ends

deep ravine
#

now, obj = new Appliance()

#

first thing that happens?

#

it gets checked, still

#
if(obj instanceof Appliance)```
#

but now its actually true

#

so what happens next?

left tartan
#

the idea is to make it go onto the rest of the code

humble oasis
#

Please press ctrl+a and then ctrl+i in your java files. It will format them for you

deep ravine
deep ravine
#

now this is true. what happens next?

#

what does the code say?

left tartan
#

i think it goes into that block of code

deep ravine
#

it does. what does that block do?

left tartan
#

make a new appliance

left tartan
#

appliance app

deep ravine
#

whats in the block?

#
if(obj instanceof Appliance) {
    // it is an appliance
}```
#

what does your code do if its an appliance?

left tartan
#

return true

deep ravine
#

yup, method ends

#

so if its a dog or something, it goes to else, returns false, method ends

#

if its actually an appliance, it returns true, method ends

left tartan
#

the method shouldn't end

#

doesn't that mean i should reverse it

deep ravine
#

it shouldnt return true right away

#

you're right

#

all the code thats at the bottom

left tartan
#

like this

#

if (!(obj instanceof Appliance)) {
return false;

deep ravine
#

thats what you want to run

#

nope

left tartan
#

else true

#

oh

deep ravine
#

the code that you want to be ran

#

all that stuff you put at the bottom

left tartan
#

if out of scope

deep ravine
#

instead of just returning true, you want that code to run

left tartan
#

u were trying to say it would never go in because its outa scope?

deep ravine
#

so put that code in the block

#

yes

#

right now, the code you put at the bottom, its unreachable

#

because if its not an appliance, it returns false

#

if it is, it returns true

#

theres no way for the code at the bottom to be reached

left tartan
#
 @Override
    public boolean equals(Object obj){
        if(obj instanceof Appliance){
            return true;
        Appliance app = (Appliance) obj;
        if(obj.equals(app))
        return true;
        }
            else{  
                return false;
            }
}```
deep ravine
#

when do you want the code on the bottom to run?

left tartan
#

when its tru so

#

i need to move it up there

deep ravine
#

yes

#

exactly

#

you also need to fix your braces

#
if(...) {

} else {

}```
#

you have ```java
if(...) {

else {

}```

left tartan
#
 @Override
    public boolean equals(Object obj){
        if(obj instanceof Appliance){
            return true;
        Appliance app = (Appliance) obj;
        if(obj.equals(app)){
        return true;
        }
            else{  
                return false;
            }
}```
deep ravine
#

you are closer

#

read it line by line, again

#

pretend obj is an appliance

#

what happens?

#

start at the very first line

#

"it checks ..."

left tartan
#

ok so i'm trying to to compare obj that is an appliance to another one

deep ravine
#

"then ..."

left tartan
#

app

left tartan
deep ravine
#

crystal

#

line by line

left tartan
#

and it is

left tartan
#

so it returns true

deep ravine
#

yes, so obj instanceof Appliance is true

#

yup

#

it returns true, exits the method

left tartan
#

does its in the block of the if statment

#

so it should

#

what

deep ravine
#

thats what you wrote

#
if(obj instanceof Appliance) 
    return true;```
#

the code is going to do what you tell it. and thats what you told it

#

see the problem?

left tartan
#

ur gonna have to slap me

#

cause it's not clicking 😭

#

why won't it go to next code

deep ravine
#

because you told it to return

left tartan
#

oh yeah

#

without doing anything

#

i told it to return

deep ravine
#

exactly

left tartan
#
 @Override
    public boolean equals(Object obj){
        if(obj instanceof Appliance){
  Appliance app = (Appliance) obj;
        if(obj.equals(app)){
            return true;
         }
            else{  
                return false;
            }
}```
#

ok so if its an appliance

#

it'll do Appliance app = (Appliance) obj;

#

this

#

then check with it

#

or so if(obj.equals(app)){

#

i should if i wrote that right

humble oasis
#

Once you know obj is of type appliance why do you make app and then compare it to obj

left tartan
#

to see if it equal each other

deep ravine
#

question is, do you understand what your code is doing?

#

line by line

left tartan
#

alright can explain this one to make sure

#

Appliance app = (Appliance) obj;

#

this is casting to applaince

#

casting the obj

#

but i guess its going in app

#

so i'm comparing the wrong thing

#

am i just comparing the same thing

deep ravine
left tartan
#

but hasn't obj been cast

#

to appliance

#

does that not mean it becomes a appliance too through app?

deep ravine
#

its already an appliance. you gotta think of "data/values" and "variables" separately

#
Object app = new Appliance();
Object dog = new Dog();
Object tv = new TV();```
left tartan
#

so what ur saying is i'm comparing a vairble to a datatype?

humble oasis
#

In java, every class/object is considered of the type Object

You can pass a Double, String or whatever object you want into your equal function

#

But they will still have the type they originally had

#

It doesn't change

#

obj will remain the type you passed in, so all the methods will be the same

deep ravine
#

im saying obj is already an appliance. we just need to view it differently. instead of viewing it as an Object, you needed to view it as an Appliance

humble oasis
#

Once you know it's of type appliance, you already know it will have the same fields and methods

left tartan
#

okay

deep ravine
#
Object obj = new Appliance();
// cannot access Appliance things 

Appliance app = obj;
// same data, but now seen as an Appliance```
left tartan
#

but that makes it sound like

#

obj a

#

would be same thing as appliance a

humble oasis
#

It can be

#

All Appliance are Object but not all Object are Appliance

deep ravine
#

they reference the same data

left tartan
#

but i can't just right obj a can i?

deep ravine
#

not sure what you mean

left tartan
#
Object obj = new Appliance();```
#

this thing

#

is this how u would write it

#

if u wanna declare a "appliance" varible

deep ravine
#

its abstraction

left tartan
#

ok

#

if i write

#

obj x.equals(appliance y)

#

that wouldn't be right would it?

#

if they can declare the same variles

#

But I’m asking I can’t just write obj x right?

#

Or can I

#

I understand it’s na appliance now

#

It can declare a appliance variable, a serial number

#

But it that how u would write it?

left tartan
left tartan
#

I'll continue this later I've really gotta go now since i got school tmw

#

I'll be back

left tartan
# left tartan obj x.equals(appliance y)

before i go though i was gonna say

after obj can now act like a appliance, it can make varibles like one, but appliance cant do that with object cause its not vice versa and sp since obj can make appliance varibles, u can decalre obj (some varible) and appliance (some varible) and see if they equal each other, just i'm not sure abotu the right syntex

kind pathBOT
#

@left tartan

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

uncut marsh
#

do you still need help

left tartan
#

Yes I saw that for the equals, we could just use the code the professor provided for that part

#

This is what I have so far

#

btw

#

i got the sort thing fixed

#

it was just a cause of a simple curly bracket

#

now all the letters can be in order, just that now null prints in between 💀 so that might be cause of the mutple arrays

kind pathBOT
left tartan
#

and this my appliance class

#

public class Appliance {


    private String SRN;


    public Appliance (String SRN) {
        this.SRN = SRN;

    }

    @Override
    public String toString() {
        return SRN;
    }

    public int compareTo (Appliance x) {
        return this.SRN.compareTo(x.SRN);

    }
    @Override
    public boolean equals(Object other){
        return other != null && getClass() == other.getClass() && SRN.equals(((Appliance) other).SRN);

    }


        public char convert(){
            return SRN.charAt(0);
        }

        public String getSRN() {
            return SRN;
        }

        public void setSRN(String SRN) {
            this.SRN = SRN;
        }


    }```
#

so far this is what i have

#

But i'm in class rn so i can't work on it atm so i'll be back once i'm home

#

oh right for the equals

#

lemme show the slide

left tartan
# left tartan

btw I think I might change the 3 separte arrays for each

#

cause i could maybe just check the letter in just one array and make that go in one the 3 collums in the gui somehow

#

or at least i hope i can

#

thats where i'm at now, i'll be back later

uncut marsh
#

@left tartan Do you know what are you doing here?:

Appliance twoDArr[][] = getTableArray();
for (var i: twoDArr) {
    for (var j: i) {
        System.out.println(j);
    }
}```
#

This is where you get nulls right? It's easy to know

deep ravine
#

please use descriptive names, too. short-hand names caused some confusion with your last problem, confusing o and y

#

descriptive names will make it easier to help, and also show us that you actually understand your code

uncut marsh
#

And make you able to understand your code if you didn't touch it for weeks or months

#

because it provides better context

left tartan
uncut marsh
left tartan
#

Ye it has the space of all of it together in each

uncut marsh
#

anyways, I don't think it matters a lot, because the assignment says it's ok to have partially filled arrays

left tartan
#

Oh yea

#

But if I’m to use the 2d array now to print that onto the gui

#

Actually maybe not

#

Cause if it checks just the letter

#

It should put it in one of the three boxes on there

uncut marsh
left tartan
#

And null just well disappears

#

Cause the gui is suppose to have three Collums separating each with their letter

left tartan
#

And so if I make it check

#

I can just tell it which text panel to go to

#

Or that’s the plan

uncut marsh
left tartan
#

Oh alright

#

Yeah I’ll see

uncut marsh
#

let's go to the constructor

left tartan
#

I’ll be back in a few hours man I have calc rn 😭

left tartan
#

Ye I shall be back

uncut marsh
#

I might made the getTableArray wrong, as I made, per column and not per row

#

ping me when you're ready

uncut marsh
#

@left tartan are you free?

left tartan
#

i have a class online rn

#

it ends at 8:30

#

actually that doesn't help if i say that cause diff timezones

#

bascially ends in an hour and 10 minutes from now

uncut marsh
#

ok

left tartan
#

alright i'm back

#

rn what i have legt to do is print the appliances onto the gui i believe

#

@uncut marsh

#

as of rn now this is what i got

uncut marsh
#

I'm a bit busy rn

#

but basically

#

You create a JScrollPane

#

add the table in the scroll pane

#

then add the scroll pane in the frame

#

I'll explain that later

left tartan
#

is that in the table one

#
    static Appliance[][] getTableArray() {
        SelectionSort();
        Appliance[] refrigerators = new Appliance[arr.length];
        Appliance[] dishwashers = new Appliance[arr.length];
        Appliance[] microwaves = new Appliance[arr.length];

        int r = 0, d = 0, m = 0;
        for(int i = 0; i < arr.length;i++){
            if (arr[i].convert() == 'R') {
                refrigerators[r] = arr[i];
                r++;
            }
            if (arr[i].convert() == 'D') {
                dishwashers[d] = arr[i];
                d++;
            }
            if (arr[i].convert() == 'M') {
                microwaves[m] = arr[i];
                m++;
            }
        }
        return new Appliance[][]{refrigerators, dishwashers, microwaves};
    }```
#
    public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setVisible(true);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public static void fillGUI() {
        


    }```
#

or should i put that in the empty method

#

I'll go and work on it then and see what i can do

uncut marsh
# left tartan ```java static Appliance[][] getTableArray() { SelectionSort(); ...

the table one is wrong:

what it does is to send an array of three arrays, each one with one type.

But the table will read as, "Ok. Let's take each array and convert it to a row!"

that will make it as a single row of refrigerators, a single row of microwaves, etc.

we will change it to modify the 2 dimensional array directly instead of adding the three arrays

left tartan
#

oh alright

uncut marsh
#

Ok I'm free now

uncut marsh
#

it will show in the center

left tartan
uncut marsh
#

I recommend putting setVisible last

left tartan
#

alright

uncut marsh
#

we will make fillGUI

#

there are two ways

left tartan
#

yea

uncut marsh
#
  1. we make the frame a private static variable like arr
#
  1. we pass frame to fillGUI
#

both work

left tartan
#

second one

#

mostly cause i already put frame in the parameters so mgiht as well

#
public static void fillGUI(JFrame body) {
        

}```
#

alright so

uncut marsh
#

call fillGUI before setVisible()

#

in makeGUI

#

then let's create a JTable

#

oh before that

#

create an array of Strings

#

for the column names

left tartan
#

can't i just append to make the column?

uncut marsh
left tartan
#

i'm not too familiar i was trying to tell from the slides

#

i'll send what he sent

uncut marsh
#

Oh we aren't using containers 💀

left tartan
#

oh its not append

#

grid layout

uncut marsh
#

we create a String[]

left tartan
uncut marsh
#

and in the JTable constructor, we use the 2d array and the column names

#

💀

left tartan
#

alright thats all i've got 💀

uncut marsh
#

that's a bit more complicated

#

your professor never told about JTable?

left tartan
#

no

uncut marsh
#

💀

left tartan
#

heard it from u the first time

uncut marsh
#

well we have to do that way 😭

left tartan
#

welp

#

alrighty

#

ok so

uncut marsh
#

we will have the 2D array as it is now

#

it works for this way

left tartan
#

ye

uncut marsh
#

make the layout thing with 3 columns

#

empty

#

and show your progress

#

we will fill it after

left tartan
#

is it just add?

#

and it creates another panel?

uncut marsh
#

GridLayout(1, 3)

left tartan
#

oh right i gotta do 1,3

uncut marsh
#

for 3 columns

left tartan
#

okay

#
    public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);

    }

    public static void fillGUI(JFrame body) {
        body.setLayout(new GridLayout(1,3);)
        


    }```
uncut marsh
#

you named it body

left tartan
#

oh right

uncut marsh
#

I think that is last

#

before we have to create the content panes

#

first

left tartan
#

okay

#

wait no

#

not this one

left tartan
uncut marsh
#

so 3 text areas

#

one content pane

left tartan
#

actually it might've been that

#

cause that adding text

#
    public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);

    }

    public static void fillGUI(JFrame body) {
    Container myContentPane = gui.getContentPane();
    TextArea refeg = new TextArea();
    TextArea dishWash = new TextArea();
    TextArea micro = new TextArea();
    myContentPane.add(Refeg, BorderLayout.EAST);
    myContentPane.add(dishWash, BorderLayout.WEST);
    myContentPane.add(micro, BorderLayout.CENTER);



        body.setLayout(new GridLayout(1,3);)
        


    }```
uncut marsh
#

yeah then myContentPane.add() thing

#

3 times

left tartan
#

i thought gridlayout was the other alternative

deep ravine
#

theres a few things here

left tartan
#

this east west stuff

deep ravine
#

first, i would never recommend relying on the existing content pane. that exists for formality reasons

#

introduce your own panel, then set that panel as the content pane

#

otherwise you can wind up with some funky results, such as when using BoxLayout

left tartan
#

would changing the borderlayout to gridlayout be fine

#

wait i put it on the bottom

deep ravine
#

if you need gridlayout instead of borderlayout, sure

#

just make sure you understand what they do

left tartan
#

they do the same thing right?

deep ravine
#

not even close lmao

#

they are completely different layouts

left tartan
#

but they both give u mutiple panels

deep ravine
#

yeah, so do 99% of layouts

#

so does FlowLayout

left tartan
#

oh there is more

#

its not just those two

deep ravine
#

so does GridBagLayout

left tartan
#

well of course

deep ravine
#

there are tons

left tartan
#

java got alot of stuff

deep ravine
left tartan
#

and so i think i'd better use gridlayout

#

seemed more simple maybe

deep ravine
uncut marsh
deep ravine
#

tons of layouts

uncut marsh
#

in your assignment

left tartan
left tartan
deep ravine
#

if your assignment says GridLayout, use GridLayout

#

read your assignment 😂

left tartan
#

indeed it does 💀

#

i thoght he was saying that generally

deep ravine
#

if you cant handle requirements from a school assignment, you will fail with real-world assignments

left tartan
#

so i just misread it

deep ravine
#

time to put more priority on that

left tartan
#

yea

#

ok so with gridlayout

#

i just need to say it once so thats means i just write java body.setLayout(new GridLayout(1,3);)

#

instead of contentpane border

#
    public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);

    }

    public static void fillGUI(JFrame body) {
    Container myContentPane = gui.getContentPane();
    TextArea refeg = new TextArea();
    TextArea dishWash = new TextArea();
    TextArea micro = new TextArea();
    body.setLayout(new GridLayout(1,3);)
    myContentPane.add(refeg);
    myContentPane.add(dishWash);
    myContentPane.add(micro);    

    }```
#

ok so now i do the adding

uncut marsh
#

i think

#

I never used that

left tartan
#

the gridlayout?

#

maybe

#

i can't tell either

uncut marsh
#

nah lets continue

#

if something is wrong we will fix it

left tartan
#

czuse they have it like this

left tartan
#
    public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);

    }

    public static void fillGUI(JFrame body) {
    Container myContentPane = gui.getContentPane();
    TextArea refeg = new TextArea();
    TextArea dishWash = new TextArea();
    TextArea micro = new TextArea();
    body.setLayout(new GridLayout(1,3);)
    myContentPane.add(refeg);
    myContentPane.add(dishWash);
    myContentPane.add(micro);    
    for(int i =0;i < arr.length;i++){


    }```
#

ok so now since we have the different panels

uncut marsh
#

before adding

left tartan
#

yea

uncut marsh
#

we have to append

#

there are two ways

left tartan
#

ok what does append do

#

put words in a box?

uncut marsh
#

you append "A": A

left tartan
#

oh yea so it puts words in the textarea right

uncut marsh
#

you append "B" : AB

#

yeah

left tartan
#

okie dokie

uncut marsh
#

there are two ways

#
  1. we use the the if arr[i].convert() == 'R' logic there and delete the getTableArray
  2. we use the getTableArray
left tartan
#

wait is that jtable thing

uncut marsh
left tartan
#

if he didn't ever mention in to us, i assume we can't use it

#

ah ye

#

so first option it is

uncut marsh
#

so make a for loop that iterates from 0 to arr.length

#

again

left tartan
#
    public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);

    }

    public static void fillGUI(JFrame body) {
    Container myContentPane = gui.getContentPane();
    TextArea refeg = new TextArea();
    TextArea dishWash = new TextArea();
    TextArea micro = new TextArea();
    body.setLayout(new GridLayout(1,3);)
    for(int i =0;i < arr.length;i++){

    if ( (arr[i].convert() == 'R')){

    }
    if ( (arr[i].convert() == 'D')){

    }
    if ((arr[i].convert() == 'M') ){

    }

    }
    myContentPane.add(refeg);
    myContentPane.add(dishWash);
    myContentPane.add(micro);    


    }```
uncut marsh
#

should be before the myContentPane.add()

left tartan
#

oh yeah

uncut marsh
#

there we use the logic that we applied in the getTableArray function

#

if (arr[i].convert() ==

#

etc

left tartan
#
static Appliance[][] getTableArray() {
        SelectionSort();
        Appliance[] refrigerators = new Appliance[arr.length];
        Appliance[] dishwashers = new Appliance[arr.length];
        Appliance[] microwaves = new Appliance[arr.length];

        int r = 0, d = 0, m = 0;
        for(int i = 0; i < arr.length;i++){
            if (arr[i].convert() == 'R') {
                refrigerators[r] = arr[i];
                r++;
            }
            if (arr[i].convert() == 'D') {
                dishwashers[d] = arr[i];
                d++;
            }
            if (arr[i].convert() == 'M') {
                microwaves[m] = arr[i];
                m++;
            }
        }
        return new Appliance[][]{refrigerators, dishwashers, microwaves};
    }```
#

so the if there

uncut marsh
#

yeah

left tartan
#

3 ifs then

uncut marsh
#

we will change the content of the ifs

uncut marsh
#

empty ifs

#

nono

left tartan
#

empty

#

right

uncut marsh
#

if (arr[i].convert() == 'R') {}

#

if without the body, but with the statement

#

@left tartan

left tartan
#
    public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);

    }

    public static void fillGUI(JFrame body) {
    Container myContentPane = gui.getContentPane();
    TextArea refeg = new TextArea();
    TextArea dishWash = new TextArea();
    TextArea micro = new TextArea();
    body.setLayout(new GridLayout(1,3);)
    for(int i =0;i < arr.length;i++){

    if ((arr[i].convert() == 'R')){
    refeg.append();
    }
    if ((arr[i].convert() == 'D')){
    dishWash.append();
    }
    if ((arr[i].convert() == 'M') ){
    mircro.append();
    }

    }
    myContentPane.add(refeg);
    myContentPane.add(dishWash);
    myContentPane.add(micro);    


    }```
uncut marsh
#

good

#

depending if its R D or M

#

we will use .append

left tartan
#

it'll place it in a certain pane

uncut marsh
#

yes

left tartan
uncut marsh
#

it will add it to the textArea

#

wait

#

let me check the presentation

left tartan
#

u mean this part?

uncut marsh
#

oh yeah

#

.append

kind pathBOT
# uncut marsh .append

Looks like you attempted to use a command? Please note that we only use slash-commands on this server 🙂

Try starting your message with a forward-slash / and Discord should open a popup showing you all available commands.
A command might then look like /foo 👍

left tartan
#

or this was the other one

uncut marsh
#

I mean .append not .concat

left tartan
#

oh ye

uncut marsh
#

my bad

left tartan
#

alright so

#

in the ifs

#

once it does the condition

#

the textarea.append

#

textarea being the names

uncut marsh
#

each textarea is a column

#

if its a 'R', we add it to the refeg column

#

you put .append()

#

but .append() what

left tartan
#

yeah append the serieal number

#

so i gotta put that in there

#

wait its text

uncut marsh
#

yes

left tartan
#

i gotta use the array somehow

uncut marsh
#

"I gotta sue the array somehow" sounds funny

left tartan
#

lol

#

ok but in the table thingy we had it return a 2d array

#

hold on

#

our 3 separte arrasy we made

#

that still stays there or no?

uncut marsh
#

we won't use it

left tartan
#

everything?

#
static Appliance[][] getTableArray() {
        SelectionSort();
        Appliance[] refrigerators = new Appliance[arr.length];
        Appliance[] dishwashers = new Appliance[arr.length];
        Appliance[] microwaves = new Appliance[arr.length];

        int r = 0, d = 0, m = 0;
        for(int i = 0; i < arr.length;i++){
            if (arr[i].convert() == 'R') {
                refrigerators[r] = arr[i];
                r++;
            }
            if (arr[i].convert() == 'D') {
                dishwashers[d] = arr[i];
                d++;
            }
            if (arr[i].convert() == 'M') {
                microwaves[m] = arr[i];
                m++;
            }
        }
        return new Appliance[][]{refrigerators, dishwashers, microwaves};
    }```
uncut marsh
#

the function getTableArray yes

left tartan
#

alright

uncut marsh
#

so you have

#
if ((arr[i].convert() == 'R')){
    refeg.append();
}```
#

refeg.append()

left tartan
#
   public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);

    }

    public static void fillGUI(JFrame body) {
    Container myContentPane = gui.getContentPane();
    TextArea refeg = new TextArea();
    TextArea dishWash = new TextArea();
    TextArea micro = new TextArea();
    body.setLayout(new GridLayout(1,3);)
    for(int i =0;i < arr.length;i++){

    if ((arr[i].convert() == 'R')){
    refeg.append(arr[i].toString());
    }
    if ((arr[i].convert() == 'D')){
    dishWash.append(arr[i].toString());
    }
    if ((arr[i].convert() == 'M') ){
    mircro.append(arr[i].toString());
    }

    }
    myContentPane.add(refeg);
    myContentPane.add(dishWash);
    myContentPane.add(micro);    


    }```
uncut marsh
#

you need to append something

left tartan
#

right

#

the srn in the array

#
    public static void main (String[] args) {
        readfile();
        SelectionSort();

        for (int i =0; i < arr.length; i++) {
            Appliance a = arr[i];
            System.out.println(a);
        }    

        Appliance twoDArr[][] = getTableArray();
        for (var i: twoDArr) {
            for (var j: i) {
                System.out.println(j);
            }
        }

        makeGUI();


    }```
#

so the twoDArr

uncut marsh
#

remember we used arr[i].convert()

left tartan
#

oh

uncut marsh
#

it appends the array element

#

we already have toString so I think its fine

left tartan
#
    @Override
    public String toString() {
        return SRN;
    }

    public int compareTo (Appliance x) {
        return this.SRN.compareTo(x.SRN);

    }
    @Override
    public boolean equals(Object other){
        return other != null && getClass() == other.getClass() && SRN.equals(((Appliance) other).SRN);
    }


    public char convert(){
        return SRN.charAt(0);
    }```
uncut marsh
#

yeh

left tartan
#

oh so the convert

#

i need to ask because i wanna be sure

#

we gotta append the serieal number in the panel

uncut marsh
#

yes

left tartan
#

that serial number will go through convert and gime the first letter

#

and in the if statement we cheek what letter it is

#

but that whole serial number

#

how do we retrive it

uncut marsh
left tartan
#

ohhh

#

ok that actaully makes sense

#
   public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setVisible(true);

    }

    public static void fillGUI(JFrame body) {
    Container myContentPane = gui.getContentPane();
    TextArea refeg = new TextArea();
    TextArea dishWash = new TextArea();
    TextArea micro = new TextArea();
    body.setLayout(new GridLayout(1,3);)
    for(int i =0;i < arr.length;i++){

    if ((arr[i].convert() == 'R')){
    refeg.append(arr[i].toString());
    }
    if ((arr[i].convert() == 'D')){
    dishWash.append(arr[i].toString());
    }
    if ((arr[i].convert() == 'M') ){
    mircro.append(arr[i].toString());
    }

    }
    myContentPane.add(refeg);
    myContentPane.add(dishWash);
    myContentPane.add(micro);    


    }```
uncut marsh
#

let's check if its working

#

run the code

left tartan
#

its red

uncut marsh
#

what

left tartan
#

what did i write wrong

uncut marsh
#

also

left tartan
#

ok lemme check what to import

uncut marsh
#

it's body not gui

left tartan
#

wait

#

isn't this in Jframe?

uncut marsh
#

what

uncut marsh
#

with this

left tartan
#

the stuff like container or text area

#

or grid layout

uncut marsh
#

and they're added to a JFrame

left tartan
#

this thing right

uncut marsh
#

yes

left tartan
#

but i have it

uncut marsh
#

wait

#

they're actually part of awt

left tartan
#

maybe if i remove extends JFrame

#

oh

uncut marsh
#
import java.awt.GridLayout;
import java.awt.TextArea;```
uncut marsh
left tartan
uncut marsh
#

you named JFrame body

#

and you're using gui

uncut marsh
#

try it

left tartan
#

only this shows up

#

i thought the words would show up

uncut marsh
#

let's see

left tartan
#

are we not up to it yet?

#

lemme send the hwole code

uncut marsh
#

that isnt saving

left tartan
left tartan
uncut marsh
#

the name

#

not body

#

change it to gui

#

and the issue magically disappears

left tartan
#

but

uncut marsh
left tartan
#

ok

#

even in the parameters?

uncut marsh
#

yes

left tartan
#

ok

#

re

#

alrigth lets se

#

😭

#

u know what

#

does that mean anything

uncut marsh
#

strange

left tartan
#

it shwos up everytime

#

i run

uncut marsh
#

continue

left tartan
#

oh alright 😭

#

still blank sadly

uncut marsh
#

can you restart eclipse

left tartan
#

alright

uncut marsh
#

to see if the problem fixes

left tartan
#

even though i know i saved it

#

incase

#

casue im stupid

kind pathBOT
left tartan
#
public class Appliance {

    private String SRN;

    public Appliance (String SRN) {
        this.SRN = SRN;

    }

    @Override
    public String toString() {
        return SRN;
    }

    public int compareTo (Appliance x) {
        return this.SRN.compareTo(x.SRN);

    }
    @Override
    public boolean equals(Object other){
        return other != null && getClass() == other.getClass() && SRN.equals(((Appliance) other).SRN);
    }


    public char convert(){
        return SRN.charAt(0);
    }

    public String getSRN() {
        return SRN;
    }

    public void setSRN(String SRN) {
        this.SRN = SRN;
    }
}```
#

ok lemme restart

#

ok i ran it again

uncut marsh
#

wait

left tartan
#

after opening eclipse again

#

ye

uncut marsh
#

I now checked your code

#

you didn't call fillGUI

#

you have to call it before setVisible

#

@left tartan

#

does it work now

left tartan
#

oh

uncut marsh
left tartan
#

in makegui

uncut marsh
#

yes

left tartan
uncut marsh
left tartan
#

ok

#

the gui right

uncut marsh
left tartan
#

woah

#

now to make it vertical

#

damn thats cool

uncut marsh
#

in the append

#

you have

#

arr[i].toString()

#

to add it

#

use +

#

to add strings

left tartan
#

in each of the ifs?

uncut marsh
#

yes

#

-or-

#

well not really, yes in the ifs

left tartan
#

not the plus sign but

uncut marsh
#

in the append

#

arr[i].toString() + '\n'

left tartan
#
    public static void fillGUI(JFrame gui) {
        Container myContentPane = gui.getContentPane();
        TextArea refeg = new TextArea();
        TextArea dishWash = new TextArea();
        TextArea micro = new TextArea();
        gui.setLayout(new GridLayout(1,3));
        for(int i =0;i < arr.length;i++){

            if ((arr[i].convert() == 'R')){
                refeg.append(arr[i].toString()+ "\n");
            }
            if ((arr[i].convert() == 'D')){
                dishWash.append(arr[i].toString() + "\n");
            }
            if ((arr[i].convert() == 'M') ){
                micro.append(arr[i].toString()+ "\n");
            }

        }
        myContentPane.add(refeg);
        myContentPane.add(dishWash);
        myContentPane.add(micro);
    }```
kind pathBOT
left tartan
#

like that?

uncut marsh
#

instead of spaces

#

its

#

\n

left tartan
#

oh right new line

#

we can type in it too

uncut marsh
#

another thing

left tartan
#

ye

uncut marsh
#

add a safety check in the convert() method

#

let's say

#

oh we got a line

#

the line being

#

""

#

let's try to access the first element

#

StringIndexOutOfBoundsException

left tartan
#

oh that sounds familar

uncut marsh
left tartan
#

this thing right

uncut marsh
#

before trying to access charAt(0)

left tartan
uncut marsh
#

so we are in the convert() method

left tartan
#
public char convert(){
if (SRN.length() == 0) return X;
        return SRN.charAt(0);
    }```
uncut marsh
#

before returning

left tartan
#

with an if?

uncut marsh
#

if (SRN.length() == 0)

left tartan
#

like that

uncut marsh
#

yes

#

lets return a character that we will use as "lol not found"

#

it could be space

#

X

#

N

#

etc

left tartan
#

X then

uncut marsh
#

yeah return 'X'

left tartan
#

like literally?

#
public char convert(){
if ((SRN.isEmpty()) return X;
        return SRN.charAt(0);
    }```
uncut marsh
#

yes

#

that works

left tartan
#

interesting

uncut marsh
#

I think it's done

left tartan
#

ok if it equals 0, that means the string isn't a word?

#

could u explain this line again

uncut marsh
#

an empty String

#

we can also use

#

.isEmpty()

left tartan
#

ohh

#

we haven't learned that

#

so i guess i'll just type x

uncut marsh
#

literally does the same thing

left tartan
#

should i write it then

uncut marsh
left tartan
#

oh its separte

uncut marsh
left tartan
#

does that still go in covnert

uncut marsh
#

if (SRN.isEmpty())

#

or the one before

#

choose the one you prefer

left tartan
#

the second

#

its more understandable for me

uncut marsh
#

well then use it

left tartan
#
public char convert(){
if ((SRN.isEmpty()) return X;
        return SRN.charAt(0);
    }```
#

or its ok like that

uncut marsh
#

isEmpty() is part of String

#

SRN is a String

left tartan
#

alright

#

won't just writing x

#

gimme a problem

uncut marsh
#

it doesn't have a case for X

#

so it won't add it to any column

#

it will be in the array though

left tartan
#

yeah but

#

i meant cause it shows this

uncut marsh
#
String str = "X";
char chr = 'X';```
#

you're returning a char, not a String

#

so it needs simple quotes

left tartan
#

alright

#

ok good

#

but now one more problem

#

i can edit this panel

#

i don't think i'm supose to be able to do that

#

what do i do about that

uncut marsh
#

lol

left tartan
#

thats true lol

#

but i doubt he'd be okay with a file that isn't protected or something

#

i was trying to do

#

.setEditable(false);

uncut marsh
#

yes

#

with the three

left tartan
#

but its just red 💀

#

the three?

#

oh the panels

#

i put it there

#
public static void makeGUI() {
        JFrame gui = new JFrame();
        gui.setEditable(false);
        gui.setTitle("Appliances");
        gui.setSize(640, 480);
        gui.setLocation(100,100);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fillGUI(gui);
        gui.setVisible(true);

    }```
uncut marsh
#

after the for loop

left tartan
#

there?

uncut marsh
left tartan
#

wdym

#

isn't that saying make the gui not editable?

#

the box that pops up

uncut marsh
#

its just the empty frame

left tartan
#

wait really

#

gui is empty?

uncut marsh
#

it doesn't belong there

left tartan
#

ohh

uncut marsh
left tartan
#

we tell gui what to have

#

in the other method

#

before that

#

its empty

uncut marsh
#

yes

#

but

#

setEditable

#

is not a JFrame method

left tartan
#

no wonder it wasn't in this presentation

uncut marsh
#

how did you found out about setEditable

left tartan
#

asked classmates jsut now

#

they said thats what they used

uncut marsh
#

set editable is a TextArea method

#

not JFrame

#

or Container

left tartan
#

oh

#

wait but how would that work

#

textarea

uncut marsh
#
refeg.setEditable(false);
dishWash.setEditable(false);
micro.setEditable(false);``` 😭
left tartan
#

ok right those applainces are ebing printed

#

is only makes sense to write don't edit after u put them in a panel

#

or while u put them there

uncut marsh
#

yes

left tartan
#

and because those were made from the datatype textarea

#

doign .not edit and stuff

#

since tis part of it

#

works

#

ok

#

ok i shouldn't write that when they are being declared right

#

while they are being added?

#
  public static void fillGUI(JFrame gui) {
        Container myContentPane = gui.getContentPane();
        TextArea refeg = new TextArea();
        TextArea dishWash = new TextArea();
        TextArea micro = new TextArea();
        gui.setLayout(new GridLayout(1,3));
        for(int i =0;i < arr.length;i++){

            if ((arr[i].convert() == 'R')){
                refeg.append(arr[i].toString()+ "\n");
            }
            if ((arr[i].convert() == 'D')){
                dishWash.append(arr[i].toString() + "\n");
            }
            if ((arr[i].convert() == 'M') ){
                micro.append(arr[i].toString()+ "\n");
            }

        }
        myContentPane.add(refeg.setEditable(false))
        myContentPane.add(dishWash.setEditable(false));
        myContentPane.add(micro.setEditable(false));
    }```
uncut marsh
#

@left tartan setEditable is a void method

#

you can't add nothing to the pane

#

they should be outside

left tartan
#

doesn't that mean

#

i just the names

#

and then put dont edit

#

after everything in that method

uncut marsh
#
refeg.setEditable(false);
dishWash.setEditable(false);
micro.setEditable(false);
myContentPane.add(refeg);
myContentPane.add(dishWash);
myContentPane.add(micro);```
left tartan
#

yeah its green

#

so it was that

#

and u say it before

deep ravine
#

these swing things can get confusing. Nemux seems to be on a good track

#

you guys lmk if you need extra input

left tartan
#

cause the thing prints after

#

yay it's edit proof

uncut marsh
#

now it's done right

left tartan
#

i beleive so

uncut marsh
#

A question

left tartan
#

no edit, all of them printed

#

and sorted

#

yea

uncut marsh
#

does your prof ask you how you do that x in class?

left tartan
#

no

#

wait what x

uncut marsh
#

anyways you have to understand

left tartan
#

u mean the one in the panel?

#

isn't that the close thigny

uncut marsh
#

x can be anything

left tartan
#
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);```
left tartan
#
public char convert(){
        if ((SRN.isEmpty())) return 'X';
        return SRN.charAt(0);
    }```
uncut marsh
#

that you have to understand what you doing here so that you can apply your knowledge later

#

e.g if you have an exam

left tartan
#

yea

uncut marsh
#

ask me any questions about your code

left tartan
#

ok lemme put it all here again

uncut marsh
#

if you don't understand what its doing or how

left tartan
#

and look

kind pathBOT
left tartan
#
public class Appliance {

    private String SRN;

    public Appliance (String SRN) {
        this.SRN = SRN;

    }

    @Override
    public String toString() {
        return SRN;
    }

    public int compareTo (Appliance x) {
        return this.SRN.compareTo(x.SRN);

    }
    @Override
    public boolean equals(Object other){
        return other != null && getClass() == other.getClass() && SRN.equals(((Appliance) other).SRN);
    }


    public char convert(){
        if ((SRN.isEmpty())) return 'X';
        return SRN.charAt(0);
    }

    public String getSRN() {
        return SRN;
    }

    public void setSRN(String SRN) {
        this.SRN = SRN;
    }
}```
kind pathBOT
left tartan
#

gimme a minu

#

i ma read it all

#

ok so

#

starting with the main

#
    public static void main (String[] args) {
        readfile();
        SelectionSort();

        for (int i =0; i < arr.length; i++) {
            Appliance a = arr[i];
            System.out.println(a);
        }    

        makeGUI();
    }```
#

its reading the file to get the serial numbers

#

putting them in array

uncut marsh
#

yes

left tartan
#

the selectionsort sorts in the array in chronological order

#

after thats done

left tartan
#

right yeah

#

hmm

#

selectionsort only sorts them in that order

#

there is still checking the letter

#

and put them in each panel

#

so

#

actaully lemme check where

#

in fillgui

#

which is called in makegui

#

and thats called

#

in the main

#

after the for loop

uncut marsh
#

yes

left tartan
#

this may be a stupid question but

#

the print is before the makegui

uncut marsh
#

yes, it prints to the console

#

before creating the gui

left tartan
#

doesnt the forloop print

#

ohhh

uncut marsh
#

so you don't actually need it

left tartan
#

so thats why it still printed the numbers there

uncut marsh
#

in your assignment

#

it was just to check if the array was ordered

left tartan
#

oh alright

uncut marsh
#

before we created the gui

#

you can delete it if you want

left tartan
#

can i keep it there

#

yea

#

ok cool

#

i guess lets go over the count part again

#
public static void readfile (){
        String filename = "Project1.txt";
        TextFileInput in = new TextFileInput(filename);
        String line;
        int count = 0;
        while ((line = in.readLine()) != null){ 
            count++; 
        }
        in = new TextFileInput(filename);
        arr = new Appliance[count];
        while ((line = in.readLine()) != null){ 
            count --; 
            arr[count] = new Appliance(line);
        }

        in.close();
    }```
#

ok so

#

first we have something filename that has a link or holds the txt file

#

the TextFileInput helps looks into the whole file

#

its reading all of it

#

and now line

#

is gonna have a single line in the file

#

it reads line by line

#

and since its in the whileloop

#

it'll keep reading line by line until it reaches the end of the file

#

and once it does

#

a counter we made

#

will iterate to the number of lines we passed

#

or read

#

ok now

#

we use in again to read the whole thing?

uncut marsh
left tartan
#

why are we reading the whole thing again?

uncut marsh
#

counts the amount of lines

left tartan
#

right

uncut marsh
#

by iterating it

#

then we create the array with the length of the lines we read before

left tartan
#

we need to go back into the begining

uncut marsh
#

thats why you create a new TextFileInput

#

to "reset" the counter it has

left tartan
#

right the arr = new Appliance[count]

uncut marsh
#

initializes the static variable

#

so we can use it

#

but it starts as everythin null

#

so we have to fill it

#

in the next loop

left tartan
#

wdym

uncut marsh
left tartan
#

oh

#

the line counter

uncut marsh
#

the counter BufferedReader has

uncut marsh