🔒 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.

About this Thread

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

Trending Topics

Online now

Members online
1,239
Guests online
1,466
Total visitors
2,705

Forum statistics

Threads
2,287,342
Posts
29,044,002
Members
1,216,478
Latest member
kirolololol
Back
Top