Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
// Sandwich.java

public class Sandwich
{ 
   private String mainIngt;
   private String breadType;
   private double price;  
   
   //Default Constructor:  
   public Sandwich ()
   {
      mainIngt = "";
      breadType = "";
      price = 0.0;
      }
   
   // Getters / Accessors:
   public String getMainIngt ()
   {
      return mainIngt;
      }
      public String getBreadType ()
   {
      return breadType;
      }
      public double getPrice ()
   {
      return price;
      }
   
   //Setters / Mutators:
      public void setMainIngt (String MainInt)
   {
      mainIngt = mainIngt;
      }
      public void setBreadType (String BreadType)
   {
      breadType = breadType;
      } 
      public void setPrice (double Price)
   {
      price = price;
      }

 }


// TestSandwich.java

public class TestSandwich
{
   public static void main (String[] args)
   {
      Sandwich justinsSupper = new Sandwich ();
      
      justinsSupper.setMainIngt ("Turkey");
      justinsSupper.setBreadType ("Sourdough");
      justinsSupper.setPrice (7.50);
      
      System.out.println ("Justin's Supper is " +  
            justinsSupper.getMainIngt () + "on" +
            justinsSupper.getBreadType () + " at a cost of $ " +
            String.format ("%.2f", justinsSupper.getPrice () )
           );
   }

}


What I have tried:

I have gotten rid of minor spelling errors, I think I may be compiling them wrong.
also, I keep getting "No main methods, JavaFX Application, Applets, or MIDlets found in file."
Posted
Updated 30-Oct-20 23:10pm
v2
Comments
Afzaal Ahmad Zeeshan 30-Oct-20 17:01pm    
Depends, which file are you using as the entry point for the program?

You should be using TestSandwich, please verify that from the IDE.

1 solution

The setters in your Sandwich class are wrong, they use the wrong names for the input variables. They should be:
Java
//Setters / Mutators:
public void setMainIngt (String mainIngt)
{
   this.mainIngt = mainIngt;
}
public void setBreadType (String breadType)
{
   this.breadType = breadType;
}
public void setPrice (double price)
{
   this.price = price;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900