Write ComputerTester class containing It should have a main method in it. Inside the main method:
o Create a Computer object named myLaptop using “Dell” and 1,000,000.
o Use the setter method to change the instance variable dualCore to true;
o Display the maker, size, speed and dualCore for myLaptop.
o Create a Computer object named myTablet using “Surface” and 150,000
o Display the maker, size, speed and dualCore for myTablet.
#can someone help me start on this problem? i don't know how to do
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Certainly! Here's how you can start on the problem:
- First, create a new Java class called "ComputerTester". This class will contain the main method.
public class ComputerTester {
public static void main(String[] args) {
// Your code goes here
}
}
- Inside the main method, create a new object of the "Computer" class and name it "myLaptop" (or any other name you prefer).
public static void main(String[] args) {
Computer myLaptop = new Computer();
}
- Now you have created a "Computer" object named "myLaptop". However, since we don't have the definition of the "Computer" class yet, you will need to create it separately.
public class Computer {
// Your code for the Computer class goes here
}
At this point, you have created both the "ComputerTester" and "Computer" classes. You can continue working on defining the properties and methods of the "Computer" class based on your requirements.
Let me know if you need any further assistance!
Do you already have a Computer class?
i have the ComputerTester class with the main method
i don't quite understand what objects are
do you understand what a class is?
i can see it here but it also says to create it using "Dell" and 1,000,000
yes
well object is an instance of a class
idk how to put explain it better, but if class was a design then when you make something based on that design that's object. It will have all the same properties.
to my understanding, class is like a category and so the objects i make are based into that category?
idk about category, some folks call it blueprint. But more or less yes, when you do new ClassNameHere() you get an object aka new instance of that class.
ok i believe i get it
class Person{
String gender;
String name;
int age;
public Person(String gender, String name, int age){
// initialize
}
}```
for example, this is a Person class. Each object/instance of Person will have certain properties gender, name and age.
okay, how does this look for my code so far?
public class Computer {
String Dell;
int 1000000;
}
public static void main(String [] args) {
Computer myLaptop = new Computer("Dell", 1000000);
}
}
Detected code, here are some useful tools:
Formatted code
public class ComputerTester {
public class Computer {
String Dell;
int 1000000;
}
public static void main(String[] args) {
Computer myLaptop = new Computer("Dell", 1000000);
}
}
either write that Computer class outside of ComputerTester or in a different file.
You also forgot to add the constructor for your Computer class
okay i'm working on it
my constructor would be something like this.computer = computer right?
This beginner Java tutorial describes fundamentals of programming in the Java programming language
i'm a bit lost
first thing i already mentioned, either make a new file for Computer class or move it outside of ComputerTester class( after the bracket on line 18)
Once you do that, look at the constructors link i shared. Based on that make a new constructor for your Computer class.
yes take your time, you should understand why we use constructor or what does it mean.
this is my constructor
i really don't know what the 1000000 is supposed to be for the assignment question but I assume it's speed
constructors are inside respective class itself and yes your assumption for speed is correct
ok i think i'm getting closer
i'm sorry if i'm so lost. i'm in a fundamentals course and my friend just told me this question is supposed to be an intermediate course question
bc this is object oriented programming
@rancid bison Tbh best bet is trying to learn the basics https://www.youtube.com/watch?v=XqTg2buXS5o
In reality you should make a new class called Computer and this is your model you can put getters and getters and a constructor in here for the variables you want to set and then in your main class you can ether build the object with getters and setters or call the constructor and pass in the variables
This is close the constructor needs to be inside the Computer Class as if its not makes no sense
This tutorial looks horrible. That guy can't even get the class naming conventions right
The guy is legendary
i think i was able to get some more progress. i will update the code when i get home
private String maker;
private int speed;
private int size;
private boolean dualCore;
public void setMaker(String maker) {
this.maker = maker;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public void setSize (int size) {
this.size = size;
}
public void setDualCore(boolean dualCore) {
this.dualCore = dualCore;
}
public String getMaker() {
return maker;
}
public int getSpeed() {
return speed;
}
public int getSize() {
return size;
}
public boolean isDualCore() {
return dualCore;
}
}```
Detected code, here are some useful tools:
Formatted code
class Computer {
private String maker;
private int speed;
private int size;
private boolean dualCore;
public void setMaker(String maker) {
this .maker = maker;
}
public void setSpeed(int speed) {
this .speed = speed;
}
public void setSize(int size) {
this .size = size;
}
public void setDualCore(boolean dualCore) {
this .dualCore = dualCore;
}
public String getMaker() {
return maker;
}
public int getSpeed() {
return speed;
}
public int getSize() {
return size;
}
public boolean isDualCore() {
return dualCore;
}
}
so what's the problem?
i guess i've finished the constructor then. is what's left to display the information through the main method?
these are getters and setters, not constructor. But Java by default provides an empty constructor if you don't declare one. What does that mean for you? You can use setters to set any value for your newly created Computer Object. Do what the assignment says, set some values and print stuff. You are still short on implementation of toString() method for printing these values.