🔒 Closed Help

Status
Not open for further replies.

_KaNeKi_

Eternal Poster
mga sir, pano kaya masolve tong error nato?

1639395137234.webp
 
Maybe ganito?

Java:
class FavoriteClass{
    private String favorite1;
      private Integer favorite2;
      private Double favorite3;
   
      public FavoriteClass(String fav1, Integer fav2, Double fav3){
          this.favorite1 = fav1;
          this.favorite2 = fav2;
          this.favorite3 = fav3;
      };
   
      public String getFav1(){
          return this.favorite1;
    }
    public Integer getFav2(){
          return this.favorite2;
    }
    public Double getFav3(){
          return this.favorite3;
    }

}
public class Main
{
    public static void main(String[] args) {
        FavoriteClass a = new FavoriteClass("dasdadsadad", 100, 100.00);
        System.out.println("My favorites are " + a.getFav1() + ", " + a.getFav2() + " and " +  a.getFav3());
    }
}

output:
My favorites are dasdadsadad, 100 and100.0

DEMO: You do not have permission to view the full content of this post. Log in or register now.



Or even better with override string to get rid of getFav1 functions
You do not have permission to view the full content of this post. Log in or register now.

Java:
import java.text.MessageFormat;

class FavoriteClass{
      private String favorite1;
      private Integer favorite2;
      private Double favorite3;
   
      public FavoriteClass(String fav1, Integer fav2, Double fav3){
          this.favorite1 = fav1;
          this.favorite2 = fav2;
          this.favorite3 = fav3;
      }
   
    @Override
    public String toString() {
        return MessageFormat.format(
            "My favorites are: {0}, {1} and {2} ",
            this.favorite1, this.favorite2, this.favorite3
        );
    }
}
public class Main
{
    public static void main(String[] args) {
        FavoriteClass a = new FavoriteClass("dasdadsadad", 100, 100.00);
        System.out.println(a.toString());
    }
}
 
Maybe ganito?

Java:
class FavoriteClass{
    private String favorite1;
      private Integer favorite2;
      private Double favorite3;
  
      public FavoriteClass(String fav1, Integer fav2, Double fav3){
          this.favorite1 = fav1;
          this.favorite2 = fav2;
          this.favorite3 = fav3;
      };
  
      public String getFav1(){
          return this.favorite1;
    }
    public Integer getFav2(){
          return this.favorite2;
    }
    public Double getFav3(){
          return this.favorite3;
    }

}
public class Main
{
    public static void main(String[] args) {
        FavoriteClass a = new FavoriteClass("dasdadsadad", 100, 100.00);
        System.out.println("My favorites are " + a.getFav1() + ", " + a.getFav2() + " and " +  a.getFav3());
    }
}

output:
My favorites are dasdadsadad, 100 and100.0

DEMO: You do not have permission to view the full content of this post. Log in or register now.



Or even better with override string to get rid of getFav1 functions
You do not have permission to view the full content of this post. Log in or register now.

Java:
import java.text.MessageFormat;

class FavoriteClass{
      private String favorite1;
      private Integer favorite2;
      private Double favorite3;
  
      public FavoriteClass(String fav1, Integer fav2, Double fav3){
          this.favorite1 = fav1;
          this.favorite2 = fav2;
          this.favorite3 = fav3;
      }
  
    @Override
    public String toString() {
        return MessageFormat.format(
            "My favorites are: {0}, {1} and {2} ",
            this.favorite1, this.favorite2, this.favorite3
        );
    }
}
public class Main
{
    public static void main(String[] args) {
        FavoriteClass a = new FavoriteClass("dasdadsadad", 100, 100.00);
        System.out.println(a.toString());
    }
}
thank u sir.
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 2
    Replies
  • 367
    Views
  • 2
    Participants
Last reply from:
_KaNeKi_

Online now

Members online
895
Guests online
689
Total visitors
1,584

Forum statistics

Threads
2,276,945
Posts
28,973,258
Members
1,229,658
Latest member
hihiwae
Back
Top