I am doing an assignment for school on pearson myprogramming lab, which completely sucks by the way, and I am getting no output from my program. However, on netbeans my application is solid, compiling and giving desired output. I've looked through the forums and found a similar problem but the fix suggest did not work for my application.
Here is the assignment:
Design a class named Person
with fields for holding a person's name, address and telephone number (all as String
s). Write a constructor that initializes all of these values, and mutator and accessor methods for every field.
Next, design a class named Customer
, which inherits from the Person
class. The Customer
class should have a String
field for the customer number and a boolean
field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these values and the appropriate mutator and accessor methods for the class's fields.
Demonstrate the Customer
class in a program that prompts the user to enter values for the customer's name, address, phone number and customer number, and then asks the user whether or not the customer wants to receive mail. Use this information to create a customer object and then print its information.
Put all of your classes in the same file. To do this, do not declare them public. Instead, simply write:
class Person { ... }
class Customer { ... }
Upon submission of the code below this is the error I receive:
Driver.java:103: error: class Demo is public, should be declared in a file named Demo.java
public class Demo
^
1 error
Code:
import java.util.Scanner;
class Person
{
private String name;
private String address;
private String number;
public Person(String name, String address, String number)
{
super();
this.name = name;
this.address = address;
this.number = number;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getAddress()
{
return address;
}
public void setAddress(String a)
{
address = a;
}
public String getNumber()
{
return number;
}
public void setNumber(String number){
this.number = number;
}
}
class Customer extends Person
{
private String custNumber;
private boolean wants;
public Customer(String name, String address, String number, String custNumber, boolean wants)
{
super(name, address, number);
this.custNumber = custNumber;
this.wants = wants;
}
public String getcustNumber()
{
return custNumber;
}
public boolean isWants()
{
return wants;
}
public void setWants(boolean wants)
{
this.wants = wants;
}
}
/**
*
* @author Jonathan
*/
public class Tester
{
public static void main(String[] args)
{
String name, address, number;
String custNumber;
String decide;
boolean wants;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter name of customer:Enter address of customer:Enter phone number of customer:Enter yes/no -- does the customer want to recieve mail?:");
name = keyboard.nextLine();
address = keyboard.nextLine();
number = keyboard.nextLine();
custNumber = keyboard.nextLine();
decide = keyboard.nextLine();
wants = decide.equals("yes");
Customer one = new Customer(name, address, number, custNumber, wants); // creates new Customer Object.
System.out.println("Customer: ");
System.out.println("Name: " + one.getName());
System.out.println("Address: " + one.getAddress());
System.out.println("Phone Number: " + one.getNumber());
System.out.println("Receive Mail?: " + one.isWants());
}
}