#I need help with a Project for class

1 messages · Page 2 of 1

deep ravine
#

place a breakpoint on line 13

#

run in debug mode

#

it should pause/suspend the app once execution has reached your breakpoint

left tartan
#

wait so it's nto already in debug mode?

deep ravine
#

it was

left tartan
#

it just copied something

deep ravine
#

you just arent using it properly

left tartan
deep ravine
#

place a breakpoint

left tartan
deep ravine
#

should see a dot appear next to the line number

left tartan
#

i thought debugging ur code was just manually finding all the stuff u were missing urself

#

what do u do with breakpoint

#

i'm gonna try deleting it

#

the debug thingy

#

and click it again

uncut marsh
#

you run in debug mode

left tartan
#

ok

#

alright so after putting the breakpoint on there, u go to window, run

#

and then dubug

#

sorry not window

#

just run

#

and then debug

#

thats supose to say line 13 isn't it

#

i clicked enable breakpoint

uncut marsh
#

maybe its different on your ide

#

but if you click it it goes line by line

left tartan
#

ok we just went over nodes today

#

no polumoriigism

#

just continued this today in class

#

right anyways

left tartan
#

i got no idea what i'm clciking

#

hold on i ma search it up

#

i'll be back

uncut marsh
left tartan
#

Ok lemme see if I can find something like that on eclipse

#

Bruh I asked the professor and he’s like we’ll learn about debugging in eclipse in the future lecture 💀

uncut marsh
#

this is what you have ```java
import java.util.Arrays;
import javax.swing.*;

public class Project1 {

public static void main (String[] args) {
    readfile();
    Arrays.toString(arr);
    System.out.println(Arrays.toString(arr));
}  
public static Appliance [] arr;

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

    in.close();
}

}```

left tartan
#

Yeah I ma just figure the debug thing later

uncut marsh
#

make count start in 0

#

int count = 0;

#

just after the count, and before the array, create another while loop

#
while ((line = in.readLine()) != null){  

}```
#

and there you put count++;

left tartan
#

Alright I’ll get to that

#

I’m about to go home rn so I’m in the bus, I’ll continue this when I’m home, I’ll be back later

left tartan
#

so that first one stays?

uncut marsh
#

the first one

left tartan
#

alright

uncut marsh
#

will get the line count

#

the second will fill the array

left tartan
#
import java.util.Arrays;
import javax.swing.*;

public class Project1 {
    
    public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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);
          int count = in.getLineCount() +1 ;
          arr = new Appliance[count];
            while ((line = in.readLine()) != null){  
            arr[count] = new Appliance(line);
            count --;
        }
          
  
        in.close();
    }
        
}```
uncut marsh
#
  1. declare count
  2. the loop with count++
  3. in = new TextFileInput(filename); // to reset the line buffer
  4. declare the array with new Appliance[count];
  5. the loop filling the array
left tartan
#

wait so that loop i just created should be before the other loop

left tartan
#
import java.util.Arrays;
import javax.swing.*;

public class Project1 {
    
    public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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();
    }
        
}```
uncut marsh
#

delete this: int count = in.getLineCount() +1 ;

#

now put the count-- before arr[count] in second loop

#

now it should work

left tartan
#

lets index 20 out of bounds for lenght 20

left tartan
#

cause i ran it without out that

#

lets see

#

oo it prints

#

horizontal lol

#

a simple /n should do

uncut marsh
#

yeah

#

but now it means it works

left tartan
#

yea thats good

uncut marsh
#

now we have to create the GUI

left tartan
#

right

#

first though

#

i may be overthinking this but

#

how does the program know when to add a comma

uncut marsh
#

[a, b, c]

left tartan
#

wow

#

its like the undo tokenizer file

uncut marsh
#

does your professor let you send many .java files?

left tartan
#

ye he said to submit two

uncut marsh
#

only two?

left tartan
#

ye

uncut marsh
#

damn

left tartan
uncut marsh
#

the code will look ugly but its what we have

left tartan
#

because the textfileinput

#

he has it already

#

so we dont have to submit it

#

same thing with any other file he gave us

#

txt file that is

uncut marsh
#

by the way

left tartan
#

ye

uncut marsh
#

do you know you can create many classes

#

in a single .java file

left tartan
#

like everything in one file?

#

i used to think it worked like that until a few days ago

#

where i discovrerd u can use code form other files

uncut marsh
#

anyways

left tartan
#

and it doesn't have to be in a main method

#

ye

uncut marsh
#

we can proceed in two ways

#
  1. create the JFrame in Main and do the stuff
#
  1. create a new class that extends JFrame
left tartan
#

first one 💀

uncut marsh
#

idk if Main can extend JFrame

#

try adding extends JFrame

#

and run

left tartan
#

to main?

uncut marsh
#

yes

left tartan
#
import java.util.Arrays;
import javax.swing.*;

public class Project1 {
    
    public static void main extends JFrame(String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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();
    }
        
}```
#

uh

uncut marsh
#

I forgot that your class is Project1

#

put the extends after Project1

#

not in main method

left tartan
#

so i write extend in applaince

uncut marsh
left tartan
#

oh alright

#

what does hot code mean

uncut marsh
left tartan
#

i ma just cancel

uncut marsh
#

continue

left tartan
#

oh

#

alright

#

it doesn't look like it did anything

uncut marsh
left tartan
#

actaully i just ran it again

#

and it still prints

left tartan
uncut marsh
#

yeah

#

lets create a function named

#

createGUI

#

or createFrame

left tartan
#
import java.util.Arrays;
import javax.swing.*;

public class Project1 extends JFrame {
    
    public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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();
    }
    
    public static void MakeGUI() {
    Project1 gui = new Project1();
    gui.setTitle("Appliances");
    gui.setSize(640, 480);
    gui.setLocationRelativeTo(null);
    gui.setVisible(true);
        
    }
        
}```
uncut marsh
left tartan
#

ok so

#

main gui?

#

what is Main Gui

#

its uppercase

#

so maybe its not the the main method

uncut marsh
#

more like Project1 gui = new Project1();

#

I forgot

left tartan
#

ohhh alright

#

now that makes sense

#

cause it extends that class

#

alright so as for the rest

#

U seem to be doing that

uncut marsh
#

yeah I forgot the close operation

left tartan
#

so this one

#
gui.setLocationRelativeTo(null);```
#

whats the relative to part do

uncut marsh
# left tartan ```java gui.setLocationRelativeTo(null);```

The target screen mentioned below is a screen to which the window should be placed after the setLocationRelativeTo method is called.

If the component is null, or the GraphicsConfiguration associated with this component is null, the window is placed in the center of the screen. The center point can be obtained with the GraphicsEnvironment.getCenterPoint method.```
#

it puts the window on the center

left tartan
#

ohhh

#

its places the box thingy in front of u

uncut marsh
#

yes

left tartan
#

ok so

#
import java.util.Arrays;
import javax.swing.*;

public class Project1 extends JFrame {
    
    public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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();
    }
    
    public static void MakeGUI() {
    Project1 gui = new Project1();
    gui.setTitle("Appliances");
    gui.setSize(640, 480);
    gui.setLocationRelativeTo(null);
    gui.setVisible(true);
    gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
    }
        
}```
#

lets see

#

setTitle

#

i can't code this i should draw it

uncut marsh
#

put gui.setDefaultCloseOperation(EXIT_ON_CLOSE); before setVisible

#

else it wont actually close the program if you click the x

left tartan
#

alright

#

setvisible

#

what does that do

uncut marsh
left tartan
#

ok size obiosuly the windth and hegiht of box

#

title probably shows up on the top

#

ok so rn

#

i wonder if i can use the whiteboard here

#

damn i can't 💀

#

ok i'll draw

#

gimme 1 minute

uncut marsh
#

we probably need a JTable

left tartan
#

It looks like this rn

uncut marsh
#

yeah

left tartan
#

Right?

#

Okie

#

Now for the other panel thingys properly

uncut marsh
#

let's make a constructor for Project1

#

that creates the GUI components

#

so

left tartan
#

thats in the main then still right

uncut marsh
#
public Project1() {

}```
uncut marsh
left tartan
#

oh the class file

uncut marsh
#

like we did in Appliances before

left tartan
#

the capital c is the class but

#

wait i just make another function don't i?

#

cause readfile

#

makegui

#

are funtions

#

and they are under class

uncut marsh
#

but with the constructor is simpler

#

or non-static method

left tartan
#
import java.util.Arrays;
import javax.swing.*;

public class Project1 extends JFrame {
    
    public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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();
    }
    
    public static void MakeGUI() {
    Project1 gui = new Project1();
    gui.setTitle("Appliances");
    gui.setSize(640, 480);
    gui.setLocationRelativeTo(null);
    gui.setVisible(true);
    gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
    }
    
    public Project1() {
        
    }
        
}```
#

right cause Project1 is a class afterall

#

just like applaince

#

its just that it happens to contain a main method

#

i think

#

ok so this contructor is making the gui compenets

#

don't the gui compenets come with JFrame?

uncut marsh
deep ravine
#

dont make your class extend JFrame

uncut marsh
#

like .add()

deep ravine
#

introduce a JFrame object

#
JFrame frame = new JFrame();
// use frame```
left tartan
#

but how come

#

why make the stuff

deep ravine
#

multiple reasons why, the biggest being "too many problems occur when beginners do that"

left tartan
#

when we can just make something do the stuff jframe has

deep ravine
#

the more powerful reason is that extends defines a relationship

#

an "is-a" relationship

#

your program is not a frame. it uses a frame

#

Program is a JFrame.. its not really just a frame, its an entire program

#

which uses a frame

#

i would say Program is NOT a JFrame. your class is not trying to extend the features that a frame has. it is not a frame

#

it uses one

#

other apps cannot use Program as a frame

left tartan
#

i don't mind doing that but i think i'm supose to entend it just from this since he went over entends

#

though i supose it doesn't really specifiy

uncut marsh
deep ravine
#

look at what it says, VS what you are doing

left tartan
#

u mean since it says Create a GUI, we create the class for it

deep ravine
#

the entire program shouldnt exist there

uncut marsh
#

That's why I would make a different class for the GUI

deep ravine
#

what they are showing is not good use of inheritance. but at least its labeled a bit better

#

do what you gotta do. if its a requirement, then do it

left tartan
#

I can't tell if it is tbh

#

Either way I'd be learning something hopefully

uncut marsh
#

But since professor only lets OP to send two files, we would have to put another class in the same .java file

deep ravine
#

its just a very bad way to approach it

left tartan
#

alright

deep ravine
#

"lets use extend so we dont have to code as much"

#

tons of papers documenting why that is bad

#

but that seems to be the route your assignment wants

left tartan
#

ok so

#

ye

deep ravine
#

just dont do it on your own accord

#

didnt realize it was an actual requirement for your assignment

#

i thought we were past that phase, of misusing extends

#

sorry to distract from your issue

left tartan
#

he's kinda old professor

#

so maybe that

deep ravine
#

i can tell

#

whats your current issue? to get things back on-topic

astral glen
left tartan
#
import java.util.Arrays;
import javax.swing.*;

public class Project1 extends JFrame {
    
    public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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();
    }
    
    public static void MakeGUI() {
    Project1 gui = new Project1();
    gui.setTitle("Appliances");
    gui.setSize(640, 480);
    gui.setLocationRelativeTo(null);
    gui.setVisible(true);
    gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
    }
    
    public Project1() {
        
    }

    private Jtable(){

    }  
}```
#

rn, we have a panel

deep ravine
left tartan
#

and we just need to add three different ones in there

uncut marsh
uncut marsh
left tartan
#

so uhm whats a Jtable

uncut marsh
#

that has row and columns

left tartan
#

oh okay just that

#

alright

#

wait within public project1?

#

or outside it

uncut marsh
left tartan
#
import java.util.Arrays;
import javax.swing.*;

public class Project1 extends JFrame {
    
    public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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();
    }
    
    public static void MakeGUI() {
    Project1 gui = new Project1();
    gui.setTitle("Appliances");
    gui.setSize(640, 480);
    gui.setLocationRelativeTo(null);
    gui.setVisible(true);
    gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
    }
    
    public Project1() {
        
    }

    private Jtable table;

}```
uncut marsh
#

no

left tartan
#

i haven't seen a privite funtion

#

thats gotta be wrong

uncut marsh
#

not a function

left tartan
#

ye

uncut marsh
#

private JTable table;

left tartan
#

so just privite Jtable

#

ok so Jtable acts like a datatype

#

and table is the varible?

uncut marsh
left tartan
#

like java private String SRN;

#

ok

#

so that table could be named tree and its fine then

#

ok moving on

#

Jtable , is that built in?

uncut marsh
#

lets make a function that returns a two dimensional array

uncut marsh
left tartan
#

oh ok so it'll make a table for us for anything

uncut marsh
left tartan
#

i see

uncut marsh
#

so

left tartan
#

ok so arr could be box

uncut marsh
#

and separate the Refrigerators and stuff

left tartan
#
import java.util.Arrays;
import javax.swing.*;

public class Project1 extends JFrame {
    
    public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        System.out.println(Arrays.toString(arr));
    }  
    public static Appliance [] arr;
   
    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();
    }
    
    public static void MakeGUI() {
    Project1 gui = new Project1();
    gui.setTitle("Appliances");
    gui.setSize(640, 480);
    gui.setLocationRelativeTo(null);
    gui.setVisible(true);
    gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
    }
    
    public Project1() {
        
    }

    private Jtable table;
    static Appliance[][] getTableArray() {
    Appliance[] refrigerators = new Appliance[arr.length];
    Appliance[] dishwashers = new Appliance[arr.length];
    Appliance[] microwaves = new Appliance[arr.length];

    }

}```
uncut marsh
#

no, no

#

that thing we will make it in a function

#

so we don't fill the constructor

#

so

#
static Appliance[][] getTableArray() {

}```
#

there we will create 3 arrays with the same length as arr

#

Appliance[] refrigerators = new Appliance[arr.length];

left tartan
#

oh and the other names

uncut marsh
#

for every kind of appliance

left tartan
#

at this point my brain will turn to gui fr

#

alright i wrote them in

uncut marsh
#

after that make a for loop that iterates from zero to arr.length

left tartan
#

when i think about it makes sense, we need an array of appliances

uncut marsh
#

yeah for every column

left tartan
#

wait

#

a for loop for all of them?

uncut marsh
#

oh right

left tartan
#

each one?

uncut marsh
#

the assignment tells you to order them

left tartan
#

yeah

#

both inside and with the letters i think

#

i forgot what selection sort did

#

we have the code for it he gave it to us

uncut marsh
left tartan
#

alright so

uncut marsh
left tartan
#
private Jtable table;
    static Appliance[][] getTableArray() {
    Appliance[] refrigerators = new Appliance[arr.length];
    Appliance[] dishwashers = new Appliance[arr.length];
    Appliance[] microwaves = new Appliance[arr.length];

    }

public SelectionsSort(){

}```
left tartan
#

right

uncut marsh
#

remember that method you added to Appliance

left tartan
#

ye

#
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);
        
    }
    
    public boolean equals(Appliance y) {
        return this.SRN.equals(y.SRN);
    }
    

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

    public String getSRN() {
        return SRN;
    }

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

so it comares the numbers

#

and returns

#

actaully

#

how do we know what it returns

#

if it returns the bigger one

#

or smller one

uncut marsh
#

it will give either a negative or positive number if they are different

#

and 0 if they're equal

left tartan
#

ok

#

this feels vague

#

sorted by what

uncut marsh
#

if e1 < than e2

#

it will be negative

left tartan
#

im assuming the lowest goes on top

uncut marsh
uncut marsh
left tartan
#

cause in class

#

he did it that way

#

ok so its swap after the compareTo

#
public SelectionsSort(){
Appliance.compareTo

}```
#

ok hold on

#

since its in the class

#

we call it from applaince right

#

yeah im just gonna go for it

#

but it takes one parameter

uncut marsh
#

its supposed to be in a loop

left tartan
#

are we comparing one array to another?

uncut marsh
left tartan
#

i thought it was inside one array and sort it then move on to the next array

#

i misread it then

#

it chekcs the first letter

uncut marsh
left tartan
#

and see's which array it goes into right?

uncut marsh
#

copy the selection sort code

left tartan
uncut marsh
#

the serial

uncut marsh
left tartan
#

okie

#

lemme copy paste it

#
private static void selectionSort(short[] array, int length) {
  for ( int i = 0; i < length - 1; i++ ) {
    int indexLowest = i;
      for ( int j = i + 1; j < length; j++ ){
        if (array[j].compareTo(array[indexLowest]) < 0)
        indexLowest = j;
          if ( array[indexLowest] != array[i] ) {
            short temp = array[indexLowest];
            array[indexLowest] = array[i];
            array[i] = temp;
          } // if
      } // for i
} // method selectionSort
kind pathBOT
# left tartan ```java private static void selectionSort(short[] array, int length) { for ( i...

Detected code, here are some useful tools:

[WARNING] The code couldn't end properly...

Problematic source code:

private static void selectionSort(short[] array, int length) {
  for ( int i = 0; i < length - 1; i++ ) {
    int indexLowest = i;
      for ( int j = i + 1; j < length; j++ ){
        if (array[j].compareTo(array[indexLowest]) < 0)
        indexLowest = j;
          if ( array[indexLowest] != array[i] ) {
            short temp = array[indexLowest];
            array[indexLowest] = array[i];
            array[i] = temp;
          } // if
      } // for i
} // method selectionSort```
Cause:
The code doesn't compile, there are syntax errors in this code.

## System out
[Nothing]
left tartan
#

wow

#

that looks horrible

uncut marsh
#
if (array[j] < array[indexLowest])```becomes```java
if (array[j].compareTo(array[indexLowest]) < 0)```
deep ravine
#

welcome to programming

left tartan
#

no i meant when it wasn't indented lol

deep ravine
#

ah

left tartan
#

it looked crazy

deep ravine
#

the indentation is a personal thing

#

you used 2 spaces

#

thats the Google standard

#

the usual Java standard is 4 spaces. either way, it looks the same to me

uncut marsh
#
if ( array[indexLowest] != array[i] )```to```java
if ( !array[indexLowest].equals(array[i]) )```
left tartan
#
private static void selectionSort(short[] array, int length) {
  for ( int i = 0; i < length - 1; i++ ) {
    int indexLowest = i;
      for ( int j = i + 1; j < length; j++ ){
        if (arr[j].compareTo(arr[indexLowest]) < 0)
        indexLowest = j;
          if ( !arr[indexLowest].equals(arr[i]) ) ) {
            short temp = arr[indexLowest];
            arr[indexLowest] = arr[i];
            arr[i] = Appliance temp;
          } // if
      } // for i
} // method selectionSort```
deep ravine
#

please learn how to use the debugger.. its built for situations like this

#

to pinpoint logic issues

#

you can solve problems like this on your own pretty easily, once you know where the issue is - debuggers do just that, help you pinpoint where the problem is

uncut marsh
#

declare it as Appliance type

#

and rename array to arr

left tartan
#

like appliance temp?

uncut marsh
#

I think that's all

uncut marsh
#

at the top

left tartan
#

not just the function name

uncut marsh
#

I mean before this loop:
for ( int i = 0; i < length - 1; i++ )

#

in your function

left tartan
#
public static void SelectionsSort(){
  for ( int i = 0; i < arr.length - 1; i++ ) {
    int indexLowest = i;
      for ( int j = i + 1; j < arr.length; j++ ){
        if (arr[j].compareTo(arr[indexLowest]) < 0)
        indexLowest = j;
          if ( !arr[indexLowest].equals(arr[i]) ) ) {
            short temp = arr[indexLowest];
            arr[indexLowest] = arr[i];
            arr[i] = temp;
          } // if
      } // for i
}```
uncut marsh
#

last thing

#

we can delete the parameters

#

since arr is static

#

and instead of length you can use arr.length

#

make SelectionsSort() static

#

so everyone can use it

#

and void type

#

like

#

public static void

left tartan
#

what about the short

uncut marsh
#

ah

#

short temp = arr[indexLowest];

#

temp should be Appliance

#

remove the one at the top, I thought it wasnt declared

left tartan
#

ok

uncut marsh
#

now its done

left tartan
#
public static void SelectionsSort(){
        for ( int i = 0; i < arr.length - 1; i++ ) {
            int indexLowest = i;
                for ( int j = i + 1; j < arr.length; j++ ){
                    if (arr[j].compareTo(arr[indexLowest]) < 0) {
                    indexLowest = j;
                }
                  if ( !arr[indexLowest].equals(arr[i]) )  {
                    short temp = arr[indexLowest];
                    arr[indexLowest] = arr[i];
                    arr[i] = temp;
                  } // if
              } // for i
        }
    }```
uncut marsh
#

now lets go to getTableArray

#

there call SelectionsSort()

left tartan
#

wh is temp red

uncut marsh
#

at the beginning

left tartan
#

if its declared asa short

uncut marsh
#

not short

left tartan
#

lemme remove short then and change it

uncut marsh
#

the old exercise you were working with a short[] array

left tartan
#

the Jtable is red too 💀

#
private Jtable table;
    static Appliance[][] getTableArray() {
    SelctionsSort();
    Appliance[] refrigerators = new Appliance[arr.length];
    Appliance[] dishwashers = new Appliance[arr.length];
    Appliance[] microwaves = new Appliance[arr.length];

    }```
uncut marsh
#

that's why

left tartan
#

ohh

uncut marsh
#

before refrigerators

#

call SelectionsSort

#

and it will be sorted

#

of after

#

i don't think it matters

#

then let's make a for loop

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

    }
    
    public static void SelectionSort(){
        for ( int i = 0; i < arr.length - 1; i++ ) {
            int indexLowest = i;
                for ( int j = i + 1; j < arr.length; j++ ){
                    if (arr[j].compareTo(arr[indexLowest]) < 0) {
                    indexLowest = j;
                }
                  if ( !arr[indexLowest].equals(arr[i]) )  {
                    Appliance temp = arr[indexLowest];
                    arr[indexLowest] = arr[i];
                    arr[i] = temp;
                  } // if
              } // for i
        }
    }```
uncut marsh
#

yk from 0 to arr.length

left tartan
#

yeah first forloop

uncut marsh
#

in that for loop we will have two choices

#
  1. Use ifs
  2. Use switch
left tartan
#

we haven't learned switches

uncut marsh
left tartan
#

so probbaly gonna have to use if

#

ye

uncut marsh
#

do you have getType right?

left tartan
#

ok but ur saying write the if to compare letters?

uncut marsh
#

in Appliance

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);
        
    }
    
    public boolean equals(Appliance y) {
        return this.SRN.equals(y.SRN);
    }
    

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

    public String getSRN() {
        return SRN;
    }

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

getsrn

uncut marsh
#

ah we have convert()

#

that works for this

left tartan
#

it returns a string

#

can we say

#

return char.parsesrn

uncut marsh
#

it works

left tartan
#

i thought parse

#

maybe its only integer

uncut marsh
left tartan
#

u mean its not built in

uncut marsh
#

we need that functionality that returns the first letter

left tartan
#

💀

#

charat

uncut marsh
#

yeah

#

so convert()

left tartan
#

return SRN.charAt?

#

wait but thats in convert

uncut marsh
#

so we can do like this:
if (arr[i].convert() == 'R') refrigerators[r] = arr[i];

left tartan
#

i just relaized we have a convert method

uncut marsh
#

we would need counters for every type though

#

declare this:
int r = 0, d = 0, m = 0;

left tartan
#

eh i've wrote worse

#

it is what it is 💀

#

alright

uncut marsh
#

show what you have done until now

left tartan
#

or in there

uncut marsh
#

but you will add the counter

#

this

#
if (arr[i].convert() == 'R') {
  refrigerators[r] = arr[i];
  r++;
}```
#

and for every type

left tartan
#
private Jtable table;
    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++;
   }
}
}

    }
    
    public static void SelectionSort(){
        for ( int i = 0; i < arr.length - 1; i++ ) {
            int indexLowest = i;
                for ( int j = i + 1; j < arr.length; j++ ){
                    if (arr[j].compareTo(arr[indexLowest]) < 0) {
                    indexLowest = j;
                }
                  if ( !arr[indexLowest].equals(arr[i]) )  {
                    Appliance temp = arr[indexLowest];
                    arr[indexLowest] = arr[i];
                    arr[i] = temp;
                  } // if
              } // for i
        }
}```
#

the count, its okay there?

uncut marsh
left tartan
#

oh i forgot to chnage the name

#

oh

#

after

uncut marsh
#

in TableArray

#

there we have the arrays

left tartan
#

oh above it

#

okk

uncut marsh
#

and the ifs should be put in a for loop

#

from 0 to arr.length

#

just the ifs

left tartan
#

wait in selectionsort?

#
for ( int i = 0; i < arr.length - 1; i++ ) {```
uncut marsh
#

create a new for loop

left tartan
#

that has all the if statements?

uncut marsh
#

too many fors right ☠️

left tartan
#

yea

uncut marsh
left tartan
#

but ye

#
private Jtable table;
    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 SelectionSort(){
        for ( int i = 0; i < arr.length - 1; i++ ) {
            int indexLowest = i;
                for ( int j = i + 1; j < arr.length; j++ ){
                    if (arr[j].compareTo(arr[indexLowest]) < 0) {
                    indexLowest = j;
                }
                  if ( !arr[indexLowest].equals(arr[i]) )  {
                    Appliance temp = arr[indexLowest];
                    arr[indexLowest] = arr[i];
                    arr[i] = temp;
                  } // if
              } // for i
        }
}```
uncut marsh
#

after the for loop

#

we return a 2 dimensional array

#

that contains all 3 arrays

left tartan
#

right this is all under the appliance srray thingy

uncut marsh
#

return new Appliance[][]{refrigerators, dishwashers, microwaves};

left tartan
#

after for loop right

left tartan
uncut marsh
#

tell me if there's any errors

left tartan
#

oh right lemme put that all back in ecipse

#

just bene editing here

#

ah it didn't compile

#

the Jtable thing is red

#
private Jtable table;
    static Appliance[][] getTableArray() {
    SelectionSort();
    Appliance[] refrigerators = new Appliance[arr.length];
    Appliance[] dishwashers = new Appliance[arr.length];
    Appliance[] microwaves = new Appliance[arr.length];```
uncut marsh
#

capital T

left tartan
#

ye

#

well it printed

#

just not sorted

#

btw how do u make it print vertical

#

then i screenshot it

uncut marsh
#

for each

left tartan
#

alright

uncut marsh
#

for (Appliance a : arr) {

}

#

there you put println(a);

left tartan
#

just where the main is right

uncut marsh
#

yes

#

if you want to check if it sorted

#

call SelectionSort before printing

left tartan
#
public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        SelectionSort();

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

i have questions actaully ebfore i do that

uncut marsh
#

ok

left tartan
uncut marsh
#

useful with collections

left tartan
#

no i mean there isn't any iteranting

uncut marsh
#

like Lists

left tartan
#

or stoping

uncut marsh
#

it's like a shorter way to write a for loop

left tartan
#

so it would in reality be for(Appliance a =0;a < arr.length ;a++)?

uncut marsh
#

just hidden

left tartan
#

oh no appliance ok

#

wait so i do that 2 more times

#

how does it know which array i'm talking about though

uncut marsh
#

just arr

left tartan
#

oh ok

#

idk why it took so long to register that we techincially have 4 arrays

#

so the big one

#

we just print it now

uncut marsh
#

yeah run the code

left tartan
#
public static void main (String[] args) {
      readfile();
      Arrays.toString(arr);
      SelectionSort();

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

anyways its the same

deep ravine
#

why did you call Arrays.toString twice?

uncut marsh
#

you can delete

deep ravine
#

we aim to help you understand. not just solve the problem you currently have, but to actually understand the code

left tartan
#

oh right with just that, it prints horizontally

deep ravine
#

that way you wont be back with the same problems

left tartan
#

java System.out.println(Arrays.toString(arr));

#

this line right

uncut marsh
#

yes

#

and the one below readfile() call

left tartan
#
public static void main (String[] args) {
        readfile();
        Arrays.toString(arr);
        SelectionSort();

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

now it prints like

deep ravine
#

Crystal, if theres any code you dont understand, please ask. don't just use code that you dont know

left tartan
#

yeah thats why i've jsut been asking questions

deep ravine
left tartan
#

u mean the selectionsort?

deep ravine
#

Arrays.toString(arr)

left tartan
#

it's has the array of the appliacnes

uncut marsh
#

no

left tartan
#

but when u print it

uncut marsh
#

the name its clear

deep ravine
#

thats very very far

left tartan
#

thats what it prints

#

the applinace numbers

deep ravine
#

right now, its doing nothing. its dead code

uncut marsh
#

converts the array to a string

#

but the value is lost

left tartan
#

so it's not being used

deep ravine
#

exactly. your IDE should be flagging you for it, with a warning

left tartan
#

shouldn't i delete it

uncut marsh
#

you should

deep ravine
#

i mean, its doing nothing right now

#

so yeah

left tartan
uncut marsh
#

it wont crash or anything but its a recommendation

deep ravine
#

however, Arrays.toString may be useful. you just gotta understand it properly, so you dont misuse it

#

thats what i mean, about understanding the code

#

otherwise, itll take longer to solve whatever problems you have, simply cause you arent familiar with what you got

left tartan
#

okay

deep ravine
#

#today-i-teach message

#

dont just use code thats given to you

#

do you understand readFile()?

left tartan
#

well it simply reads the first line

#

and so on

deep ravine
#

do you understand SelectionSort()?

left tartan
#

everytime u call it

#

u put the readfile in a loop

#

u can make it read the whole file

#

line by line

deep ravine
#

right on, where is that data stored in your app?

#

which variable references those lines you read?

#

how does this data get passed to SelectionSort()?

left tartan
#

actaully i'm not sure if it sorted

uncut marsh
#

it sorted well

left tartan
#

whatever was smaller on top

#

so far it sorted that?

deep ravine
#

nemux says it works. you arent sure. thats the problem

#

you need to be sure. nemux cant be the only one who is sure

uncut marsh
#

then the second one, etc

left tartan
uncut marsh
#

it's alphabetically ordered, D is closer to A

#

than M or R

left tartan
#

oh its sorting by the first letter first for the smllest

#

right they never said anything about numbers

#

ok so that means now we have to find a way to sort into arrays

#

based on their letter

#

mrm

deep ravine
#

are you sorting the lines?

left tartan
deep ravine
#

whats the assignment?

left tartan
#

but why is that m r m

uncut marsh
#

strange

left tartan
#

partially filled array

#

and different collums

#

for the different arrays

deep ravine
#

most updated version

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);
        
    }
    
    public boolean equals(Appliance y) {
        return this.SRN.equals(y.SRN);
    }
    

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

    public String getSRN() {
        return SRN;
    }

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

right on, equals is a bit weak, but that shouldn't be a big deal. you created a blueprint. do you understand everything there?

left tartan
#

yeaah

deep ravine
#

equals actually wont work

#

you arent overriding it properly

#

put the @Override annotation on it, like you did with toString()

left tartan
#

everytime i do that

#

it becomes sqiggly

deep ravine
#

should get an error

#

yeah

#

cause your code is wrong

left tartan
deep ravine
#

thats a good thing

#

its pointing out that you messed up

#

you are trying to override. but you didnt

#

remember, equals and toString are defined in Object

left tartan
#

object.equals?

deep ravine
#

these are JavaDocs. a bit scary at first, but youll grow to love them

#

this shows the definition of equals

#

its equals(Object)

#

not equals(Application)

#

so yeah, your code is not overriding, when it should. thats what the squiggly was telling you

left tartan
#

yea it got rid of it

deep ravine
#

thats still an error

#

look at y

#

Object Appliance y doesnt make sense

#

this is what i meant by "you gotta understand the code"

left tartan
#

but appliance is the datatype

deep ravine
#

not here

left tartan
#

and im making a vaarible

#

oh

deep ravine
#

you are overriding an existing method

#

that method is defined in Object. all classes extend Object

#

and Object has no clue about Appliance type

uncut marsh
#

you have to check that the object is an appliance

deep ravine
#

yup, thats one of the things they should do in equals

#

but they arent even there yet

#

if they keep making mistakes like this, itll take 2 generations to solve this relatively simple problem

#

imagine how long a large app would take

#

they gotta understand the code. these are the fundementals, the building blocks

deep ravine
#

the () part is where the "parameters" are defined

#

know what parameters are?

left tartan
#

ok remove appliance

deep ravine
#

but why?

left tartan
#

but then how will it know i'm talking about it

deep ravine
#

because of abstraction

#

one of the pillars, my friend

left tartan
#

and whats that

deep ravine
#

Application is an Object

#

we abstract irl all the time

#

baseball, soccer ball, basketball... they are all Ball

#

Baseball extends Ball
SoccerBall extends Ball
BasketBall extends Ball

left tartan
#

so they are all part of the same thing

deep ravine
#

equals(Obiect) expects an Object

left tartan
#

what does say for appliance

deep ravine
#

an Appliance is an Object

#

it extends object

left tartan
#

alright

deep ravine
#

so you can still pass Appliance objects to it

uncut marsh
#

instead of equals(Appliance y)

deep ravine
#

anything that extends Object, you can pass to that method

uncut marsh
#

its equals(Object y)

left tartan
#

i put the y

#

and now srn is sqiggly

deep ravine
#

show it

#

this is what you get 😂

left tartan
deep ravine
#

because, y datatype

#

its an Object

#

this is where you gotta do some work

uncut marsh
# left tartan

you have to check if y is an Appliance, so you can use SRN

deep ravine
#

instanceof is the keyword here

left tartan
#

but how do u check if something is a class

#

or

left tartan
deep ravine
#
if(y instanceof ...) {

}```
#

look at examples online

left tartan
deep ravine
#

yup

left tartan
#

oh its staying

deep ravine
#

look at examples of equals while you're at it

left tartan
#

y is an instance of appliance

deep ravine
#

easy info

uncut marsh
deep ravine
#

"java equals example"

left tartan
#

wait object has to have a variable too?

deep ravine
#

what do you mean?

left tartan
#
if(y instanceof Appliance){
Appliance y = 
#

well i saw this

deep ravine
#

yup, you need to introduce a new variable

left tartan
deep ravine
#

and cast the value

#

if using newer versions, you could define the variable within the if condition

left tartan
#

wait so in the parenthesis

deep ravine
#
if(y instanceof Appliance app) {
    // can use app
}```
left tartan
#

object needs a letter

deep ravine
#

its called Pattern Matching

#

gotta be on version 16+

left tartan
#

i'm not sure which version

left tartan
#

so for me

#

(appliance) o

#

Appliance y = (Appliance) O;

deep ravine
#

you dont have an o in your code

left tartan
#

i seem to be wrong

left tartan
deep ravine
#

oh, so you changed Object y to Object o

left tartan
#

it was object y

deep ravine
#

and now theres an error on y

#

you should be checking if the parameter is an instanceof Application

left tartan
#

yea it says the letters tharts the instance of

deep ravine
#

the parameter is Object o

deep ravine
left tartan
left tartan
#

i didn't notice until u pointed them out

deep ravine
#

you should use more descriptive names for your variables

#

instead of y, could use obj or something similar

#

other, since it represents another value (something you are comparing with, checking if it equals)

#

instead of Appliance o, should do Appliance appliance or even Appliance app

left tartan
#

the letter feels simple

deep ravine
#

its too simple

#

so simple, you got confused

#

the more descriptive you are, the easier things will be to navigate

#
if(i <= o && j > k)```
#

no one wants to see that

#

when a bug appears, no one wants to be looking through code like that

left tartan
#

could u explain why srn would still be red

deep ravine
#

look at the variable you're using

left tartan
#

cause if it problem was that y wasn't an applaince

#

i made it check

deep ravine
#

which variable?

left tartan
#

u mean o

#

i just tried to follow what i saw on the picture

left tartan
deep ravine
#

thats the problem, dont just blindly follow..

#

which variable are you calling SRN from?

left tartan
#

y

deep ravine
#

what is the type of y?

left tartan
#

Appliance

deep ravine
#

i see an Appliance o

left tartan
#

oh of object

deep ravine
#

yup

#

so right there, its flagging it

#

Object has no SRN member

#

"but i did instanceof and all that jazz"

#

ya did it wrong

#

so your IDE is correct

left tartan
#

the name is missing?

#

SRN

left tartan
deep ravine
#

you arent gonna get it from Object y

#

thats the whole point of Appliance o

#

you check to see if the object is an Appliance. if it is, introduce a new variable

#

assign that new variable, give it the y, but turned into the proper type (casting)

#
Appliance o = (Appliance) y;```
#

y is seen as Object

#

thats why you need a new variable, which has the type Appliance

#

i got the feeling you either missed out on a lot of lessons, or your professor should be fired

left tartan
#

no i go everyday

deep ravine
#

do you pay attention everyday? 😂

left tartan
#

yeah of course

#

we haven't ever talked about this though

#

but i'm trying to understand

#

back to this

#
 @Override
    public boolean equals(Object y) {
        if(y instanceof Appliance) {
            Appliance o = (Appliance) y;
        }
        return this.SRN.equals(y.SRN);
    }```
#

the problem is

#

object y right

#

thats what u said

#

but this part ```java
Appliance o = (Appliance) y;

#

are u saying it should be the other way around

#

I have class in a bit. i'll be back

deep ravine
#

you passed the value to a variable with a different datatype, Application o

#

that's the Application o = y; part

left tartan
#

Ok i'm back

#

I'll be honest, I see what ur telling me

#

But i don't know what to do about it

deep ravine
#

you have Appliance o

#

you arent doing anything with it

left tartan
#

okay lemme put out what i have and think again

#
 @Override
    public boolean equals(Object obj)
) {
        if(obj instanceof Appliance) {
        
    Appliance x = (Appliance) obj;
        
    return this.SRN.equals(other.SRN);
    }```
#

i name it obj

#

for now

deep ravine
left tartan
#

i just wrote that as a placeholder

deep ravine
#

no need for a placeholder

#

use the Appliance variable

#

y didnt have access to SRN, because of the variable type

left tartan
#

so other would be the same way then

deep ravine
#

what do you mean?

left tartan
#

i thought u were saying y didn't have access

#

so why would putting other change anything

deep ravine
#

putting other makes no sense, thats why i asked about it

deep ravine
#

you have a variable Object obj which you never use

#

you have obi instanceof

#

other isnt a variable. you got Application o variable which you never use

#

sometimes you get so focused on solving the issue, you dont realize whats in front of you

#

i saw you edited to fix

#

looks a lot better. but other, you dont know what to put

left tartan
#
@Override
    public boolean equals(Object obj){
        if(obj instanceof Appliance) {
        
    Appliance x = (Appliance) obj;
        
    return this.SRN.equals(x.SRN);
    }```
#

yeah i just

deep ravine
#

you cleaned up 90% of the "what?" right there

left tartan
#

oh wait

#

x

deep ravine
#

there you go

left tartan
#

no nvm

deep ravine
#

no, yes

#

that was it

left tartan
#

wdym yes

deep ravine
#

you saw it

left tartan
#

wait ebfore

deep ravine
#

you arent done, but x.SRN was basically the golden ticket

left tartan
#

i didn't have the letter there or sometuing?

#

but i did

deep ravine
#

hm?

#

before you did obj.SRN

left tartan
#

the if maybe

deep ravine
#

then you didnt know what to put, so you put other

deep ravine
deep ravine
left tartan
#

damn even a semicolon shows error

#

yeah in the if

#

i had y in there

deep ravine
#

theres still a problem. you fixed some problems

#

the biggest one being y.SRN

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

so my x.srn

deep ravine
#

yes

#

obj can accept any value, because of the datatype Object

#

we can do appliance.equals(new Dog()); if we wanted

#

thats why you have the if

#

you wanna make sure the value isnt a dog, or a bicycle, etc.. you are checking if the value is an Appliance

#

does that part make sense?

left tartan
#

but how do u check that it is

deep ravine
#

you check if obj is an instanceof Appliance

left tartan
#

i mean other than the if statement i guess since that can't be it

deep ravine
#

which you are doing

left tartan
#

i gues thats not enough

deep ravine
#

hm? enough for what?

#

thats enough to check if obj is referencing an Appliance object

left tartan
#

and if it is

left tartan
#

why is ther still a bug

#

what am i missing

deep ravine
#

because you dont understand methods properly

#

you are missing a ton, my friend..

#

but in this case, its 1 thing

#

you need to return

left tartan
#

u mean after the if statement?

#

return true or false?

deep ravine
#

yup

left tartan
#

i didn't notice

#

its in a function

#

of course it returns

deep ravine
#

i mean, you do have 1 return statement

#

return this.SRN.equals

left tartan
#

ye i think i was thinking the if had a statement after the condition so it was fine

left tartan
# deep ravine you need to `return`
 @Override
    public boolean equals(Object obj){
    if(obj instanceof Appliance)
    return true;

    Appliance x = (Appliance) obj;
    return this.SRN.equals(x.SRN);
    }```
deep ravine
#

soooooo far off

#

look at what your code says

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

what do you think thats gonna do?

#

this is why im worried about the whole "understand what the code is doing"

#

you were 2 inches away from the solution. but 1 change put you 5 miles away

left tartan
#

if obj is an instance of appliance, its gonna return true

deep ravine
#

yup, and at that point, the method ends

#

no SRN check or anything else

left tartan
#

so i need to keep checking the whole thing somehow

#

should i go back

deep ravine
#

if the object is an appliance, what do you wanna do?

#

forget about code for a sec

left tartan
#

well use it

deep ravine
#

use it for what? do what with it?

#

you got an appliance, now what?

left tartan
#

use it to compare to another serieal number

deep ravine
#

so right there, thats your goal

#

what if the object is not an appliance?

#

what then?

left tartan
#

return false?

deep ravine
#

so you seem to understand what you need to do

#

now look at your code. does it reflect that?

left tartan
#

if its not an appliance, what else can u do, u need to only use appliances

deep ravine
#

exactly

left tartan
#

so i need a return false in there as well

deep ravine
#
if(is appliance) {

} else {
    return false;
}```
#

right?

#

youd use instanceof of course, is isnt Java syntax

left tartan
#

hold on

deep ravine
#

but thats the idea, yeah?

left tartan
#

ye

#

i was about to ask

#
@Override
    public boolean equals(Object obj){
    if(obj instanceof Appliance){
    return true;
    }
    else{  
    return false;
    }

    }```
#

please tell me thats at least closer

deep ravine
left tartan
#

but

#

ok

deep ravine
#

that will at least bring you to a point where the code will run (no squiggles) AND you understand what is going on

#

we can build on this

#

if its not an appliance, return false, easy

#

if it is, what do we do?

#

do we return true immediately?

left tartan
#

yes

#

but when u ask ti like that

deep ravine
#

what about the serial number?

left tartan
#

maybe no

#

we still need to compare

deep ravine
#

yup. if its an appliance, compare

left tartan
#

it only is saying that this varible is an applaince right nowright

deep ravine
#
if(is appliance) {
    // compare
} else {
    return false;
}```
#

yup

left tartan
#

so the other if was for

#

take this applaince

#

and comapre it

#

or uh eqauls

#

to another appliance

deep ravine
#

you need to check if the serials are equal, yeah

left tartan
#

yeah

deep ravine
#
if(serials are equal) {
    return true;
} else {
    return false;
}```
left tartan
#

i have to think about what varibles

#

ok so

#

its saying obj

#

is an appiance

#

if that returns true

#

that measn in the next if statement

#

we say if(obj == this appliance)

#

return true else false