It's on enums and for this website we're told not to use the first "public" for the class declaration.
Question in pic - my attempt is here:
class SerialPublication {
public enum Frequency {DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY, UNDEFINED}
protected Frequency frequency;
public SerialPublication(){ frequency = Frequency.UNDEFINED; }
public SerialPublication(String freq){ this.setFrequency(freq); }
public void setFrequency(freq){ frequency = Frequency.freq; }
public Frequency getFrequency(){ return frequency; } }
Mason Peterson
This is the error message I got
Nolan Campbell
bump
Thomas Bailey
bumping
Jason Robinson
>public void setFrequency(freq) Don't do Java but shouldn't you be declaring what type of variable "freq" is?
>public void setFrequency(String freq)
Dylan Rivera
this.
Charles Martinez
POO IN LOO PAJEET BACK TO LE REDDITZ XDDDDDD
Lincoln Russell
You were missing the type in the setter. And I wouldn't bother with the constructor setting the property default, just assign it like I've done
public class SerialPublication {
public enum Frequency {DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY, UNDEFINED}
private Frequency frequency = Frequency.UNDEFINED;
public SerialPublication(String freq){ this.setFrequency(Frequency.valueOf(freq)); }
public void setFrequency(Frequency freq) { frequency = freq; }
public Frequency getFrequency(){ return frequency; } }
Isaac Cooper
Oh and I forgot, use Frequency.valueOf to convert from a string to the enum. But beware this should have error handling to handle non-matching strings.
David Reed
Read the brief, the OP had a solution which would have got better marks than yours.
Alexander Cox
This some high level techno babel up in here.
Austin Evans
yes yes, but I didn't look at his brief just the code..
Landon Reyes
This is probably more what you want, cba to check, too bloody tired..
class SerialPublication {
public enum Frequency {DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY, UNDEFINED}
protected Frequency frequency;
public SerialPublication() { this.frequency = Frequency.UNDEFINED; }
public void setFrequency(Frequency freq) { this.frequency = freq; }
public String getFrequency(){ return this.frequency.name().toLowerCase(); }
public static void main(String [] args) { SerialPublication sp = new SerialPublication("foo"); System.out.println(sp.getFrequency()); } }
Lucas King
OP here. You're right guys, dumb mistake - my attempt timed out but this was my updated code and new error message:
class SerialPublication {
public enum Frequency {DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY, UNDEFINED}
protected Frequency frequency;
public SerialPublication(){ frequency = Frequency.UNDEFINED; }
public SerialPublication(String freq){ setFrequency(freq); }
public void setFrequency(Frequency freq){ frequency = freq; }
public Frequency getFrequency(){ return frequency; } }
Bentley Rivera
gfdgfdsgdfs
Jacob Collins
SerialPublication passes String freq to setFrequency which expects a Frequency
Xavier Barnes
OHHH
thank you so much!
Henry Powell
I've worked with a lot of students who are learning coding at it seems that none of them do it as a hobby and therefore never grasp the basics.
As an oldfag, I grew up with no access to computers until a friend of my mom leant me a ZX81 (Yes I am that old!) I taught myself to code BASIC and over the years have mastered everything from Assembly, C++ to Swift.
With some basic ground knowledge and a willingness to code at home for fun, there is no limit to what can be achieved. However if you just want to code to earn good money, you _will_ fail.
Christian Fisher
I'm gonna keep posting questions that may be really stupid here for anyone that might stick around. Thanks for the help on the previous q!
Jeremiah Perry
I agree I want to learn how to code myself and I do enjoy it but it's always so much easier doing it of my own accord VS learning how to do it because an assignment is due really soon.
In this case where I'm under some pressure to learn it just clicks a lot slower for me
Christopher Evans
This one is to do with inheritance and it looks like a really short answer.
This is just one of those where I don't know syntax or what to do because I haven't gotten my head around inheritance.
Zachary Anderson
bump
this one looks like a simple one
Christian Ward
Use the "this" operator when instantiating the vegetable and weightinkg class variables, just like the provided class in that example.