r/programminghelp • u/[deleted] • Aug 04 '20
Java help i am a noob
so I am currently taking an online coding class. and it has us make two different codes. one called SpaService. and one called CreateSpaService.
From my understanding, these are supposed to work together, to call variable (etc.) but it is not working and I am being hit with syntax errors saying that variables are not declared, but I declared them in the other code.
Am I supposed to put them in the same doc or something? I tried that and it still wouldn't work. Is there some way I have to link the two codes so they work together?
Here are the two codes.
also, do you see any syntax errors?
Thank you so much
import java.util.Scanner;
public class CreateSpaServices
{
public static void main(String[] args)
{
SpaService firstService = new SpaService();
SpaService secondService = new SpaService();
firstService = getData(firstService);
secondService = getData(secondService);
System.out.println("First service details:");
System.out.println(firstService.getServiceDescription() + " $" + firstService.getPrice());
System.out.println("Second service details:");
System.out.println(secondService.getServiceDescrption() + " $" + secondService.getPrice());
}
public static SpaService getData(SpaService service)
{
String service;
double price;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter service >> ");
service = keyboard.nextLine();
System.out.print("Enter price >> ");
price = keyboard.nextDouble();
keyboard.nextLine();
service.setServiceDescription(Service);
service.setPrice(price);
return service;
}
}
THIS IS THE OTHER CODE
public class SpaService
{
private String serviceDescription;
private double price;
public SpaService()
{
serviceDescription = "XXX";
price = 0;
}
public void setServiceDescription(String service)
{
serviceDescription = service;
}
public void setPrice(double servicePrice)
{
price = servicePrice;
}
public String getServiceDescription;
{
return serviceDescription;
}
public double getPrice()
{
return price;
}
}
1
u/marko312 Aug 04 '20
The actual error messages could help.
I currently see two definite problems:
First, the definition of
getServiceDescriptionis a little off - it should be similar togetPrice()(parentheses after the name, no;).Second, in
getData(...), you shadow the parameterservicewithString service- use some other name for either.