What's new

Java Help

_KaNeKi_

Eternal Poster
Joined
Jan 15, 2017
Posts
921
Solutions
1
Reaction
151
Points
438
Age
24
mga sir, pano kaya masolve tong error nato?

1639395137234.png
 

Attachments

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());
    }
}
 
Last edited:
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.
 

Similar threads

Back
Top