0

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 Strings). 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());





   }

 }
sepp2k
  • 363,768
  • 54
  • 674
  • 675

3 Answers3

1

Since Tester has main method, it should be declared in Tester.java file. This shall solve your issue. Do not see Demo class in uploaded code.

Dark Knight
  • 8,218
  • 4
  • 39
  • 58
  • i don't see how you can declare a file on code lab, i'd understand how to solve the problem via a real IDE but that is not the case lol. thanks anyway. – Jonathan Mallo Mar 28 '16 at 15:24
0
import java.util.Scanner;

class Person{
    private String name;
    private String address;
    private String number;

    //Constructors
    public Person(String name, String address, String number){
        this.name = name;
        this.address = address;
        this.number = number;
    }

    public Person(){}

    //Accessors
    public String getName(){
        return this.name;
    }

    public String getAddress(){
        return this.address;
    }

    public String getNumber(){
        return this.number;
    }

    //Mutators
    public void setName(String n){
        this.name = n;
    }

    public void setAddress(String a){
        this.address = a;
    }

    public void setNumber(String n){
        this.number = n;
    }
}


class Customer extends Person{
    private String customerNumber;
    private boolean recieveMail;

    //Constructors
    public Customer(String name, String address, String number, String customerN, boolean rm) {
        super(name, address, number);
        this.customerNumber = customerN;
        this.recieveMail = rm;
    }

    public Customer(){}

    //Accessors
    public String getCustomerNumber(){
        return this.customerNumber;
    }

    public boolean getRecieveMail(){
        return this.recieveMail;
    }

    //Mutators
    public void setCustomerNumber(String c){
        this.customerNumber = c;
    }

    public void setRecieveMail(boolean r){
        this.recieveMail = r;
    }
}


class Driver {

    public static void main(String args[]){

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter name of customer:");
        String name1 = scanner.nextLine();
        System.out.print("Enter address of customer:");
        String address1 = scanner.nextLine();
        System.out.print("Enter phone number of customer:");
        String number1 = scanner.nextLine();
        System.out.print("Enter customer number:");
        String customerNumber = scanner.nextLine();
        System.out.print("Enter yes/no -- does the customer want to recieve mail?:");
        String answer = scanner.nextLine();
        boolean recieveMail = (answer.equals("yes"));

        Customer customer = new Customer(name1, address1, number1, customerNumber, recieveMail);

        System.out.println("\nCustomer: ");
        System.out.println("Name: "+customer.getName());
        System.out.println("Address: "+customer.getAddress());
        System.out.println("Phone Number: "+customer.getNumber());
        System.out.println("Customer Number: "+customer.getCustomerNumber());
        System.out.println("Recieve Mail?: "+customer.getRecieveMail());


    }
}
-1

Same thing was happening to me and i found the answer for myprogramminglab. in the work area where they show the sample run you can see -SAMPLE RUN #1: java Driver. Simply change Tester for Driver for the class name and delete public.

J.Lopez
  • 11
  • 1