Anesthetize wrote: » One thing to point out - never use single letters for variable or parameter names. Use something descriptive. Other people need to be able to understand what the code is doing just by reading the code.
the whole year inn wrote: » This is the question,how does the code look?Am I along the right lines?
bpmurray wrote: » This pretty much gives you the answer. Take the start of the description and that forms your rectangle class: package rectangledemo; public class Rectangle { // Private variables private double length; private double width; // Constructor - set the values Rectangle(double length, double width) { setLength(length); setWidth(width); } // Set the length public void setLength(double length) { this.length = length; } // Set the width public void setWidth(double width) { this.width = width; } // Calculate the area public double area() { return length * width; } // Calculate the perimeter public double perimeter() { return (length * 2) + (width * 2); } // Display the rectangle information public void printRectangle() { System.out.println("Length:" + length); System.out.println("Width:" + width); } }
package rectangledemo; public class Rectangle { // Private variables private double length; private double width; // Constructor - set the values Rectangle(double length, double width) { setLength(length); setWidth(width); } // Set the length public void setLength(double length) { this.length = length; } // Set the width public void setWidth(double width) { this.width = width; } // Calculate the area public double area() { return length * width; } // Calculate the perimeter public double perimeter() { return (length * 2) + (width * 2); } // Display the rectangle information public void printRectangle() { System.out.println("Length:" + length); System.out.println("Width:" + width); } }
the whole year inn wrote: » d) Create the Class Rectangle for the object class definition below. Rectangle private: length: double width: double public: Rectangle(double length, double width) void setLength(double length) void setWidth(double width) double area() double perimeter() void printRectangle() Information: The output of the printRectangle () method should be: Length: length Width: width E.g. Length: 2.0, Width: 3.0, The area method() should return the area of the Rectangle i.e. length * width; The perimeter() method should return the perimeter of the Rectangle i.e. (length * 2) +( width * 2);
Buford T Justice wrote: » If you're trying to learn how to do the assignment, what is preventing you from using google as a study aid? Also, what have you tried in the if statement. and use code tags when adding code
the whole year inn wrote: » The exam is closed book so have to remember the code. Dont know how im supposed to know the code with out googling.I can have an idea how to go about and learn the code and then try and implement it to the questions. Yea i have an if statement just the if statement i have is wrong or doesnt work
Senna wrote: » In all honesty, if I had that question in college, I'd be googling how to find out what a prime number is, I'm sure you are told not to Google code but theory's are find to Google. For the record, I wouldn't remember code on how to find prime numbers, if I had to do it tomorrow, I'd be straight on Google first, but you will need an if statement in a for loop, testing each number.
the whole year inn wrote: » I got the enter the number of intergers the user wants and to enter the numbers. Im stuck now on using only prime number so was thinking going along the lines if the value can be /2 then dont use which i think is if (value % 2==1) And use an else statement am I along the right lines?
Senna wrote: » Read this part again, you need something between the two comments. Think about what you want to happen here. Also delete the input.close // Read the users input // Close the input stream input.close();
the whole year inn wrote: » When i do this it runs put prints out please enter number what ever number I enter first?I cant enter the numbers onlynthe number of intergers I want to enter.
Senna wrote: » You have a lot going on in that code, if I was you, I'd first work out how to find if a number was prime(sure you don't mean even?). Then work out how to find average and sum. Best way to learn is to write 3 different programs (methods), each working out a different calculation. Once you have all 3 working, combine them into one program where you only enter the numbers once Break all problems down to as small as possible, much easier to get an answer.
Senna wrote: » Ask a lecturer for a grading scheme for a past paper. Written code exams arent that bad, you have a question with 5 marks, but you could get all those 5 marks for written code that wouldn't even compile. You might get a mark for using am IF statement, another mark for have two conditions, another mark for declaring a variable, another mark for setting the result to a variable. Most of the time you lose no marks for silly syntax mistakes. Your answer above could have got full marks even with leaving out the variable name from the if statement.
croo wrote: » All the more reason to use a simple editor rather than an IDE that will auto-complete the code as you type! I'm afraid learning programming languages is just like that. Even when you know a few and need to learn another, you just need to practise lots and lots and suddenly you'll find that you are writing valid code! that;s how it is for me anyway. When following examples I always type the code rather than any copy & pasting just to practise writing it. Realistically though, in the real world, people are using IDE that, these days, write a lot of the code and even correct simple typos (much like your phone will).
Its a written exam
Takes hours to learn simple things
croo wrote: » I've made the same mistake myself ,,, more than once over the years. But, as I said in stakeoverflow, if you read the syntax error message produced carefully you can see it did give some good clues. (ps. you can accept my stackoverflow answer if you wish ) And learning to reading those compiler errors is a good skill to learn, so I would agree with your lecturer that, in these early stages of learning the language, a simple editor can be better than an ide.
croo wrote: » if(bag >= 10 && bag < 20)
if(bag >= 10 && < 20)