Hej! Försöker göra en enkel klass med InteliJ
.
import java.awt.print.Book;
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.print("Hello and welcome!");Book test = new Book();
test.setTitle("Java for Dummies");
System.out.print(test.getTitle());
}
}
public class Book {
private String title; //Variabel som endast kan nås i klassen.
private String author;
private int price;//egenskaper (properties). Används för att förhindra åtkomst till privata variabler.
//Getter for "title"
public String getTitle()
{
return title;
}// Setter for "title"
public void setTitle(String title)
{
this.title = title;
}//Getter for "author"
public String Author() {
return author;
}// Setter for "author"
public void setAuthor(String author) {
this.author = author;
}//Getter for "price"
public int Price() {
return price;
}// Setter for "price"
public void setPrice(int price) {
this.price = price;
}}
Att skapa objektet går bra men när jag ska använda getter och setter får jag detta:
C:\Java\konstruktorTest\src\Main.java:13:13
java: cannot find symbol
symbol: method setTitle(java.lang.String)
location: variable test of type java.awt.print.Book