FromYesterday
This commit is contained in:
14
ClassesAndObjects/src/main/java/com/example/Customer.java
Normal file
14
ClassesAndObjects/src/main/java/com/example/Customer.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.example;
|
||||
|
||||
class Customer {
|
||||
//add all necessary attributes here
|
||||
String firstName, secondName;
|
||||
int age, roomNumber;
|
||||
|
||||
public void saveCustomerInfo() {
|
||||
System.out.println("First name: " + firstName);
|
||||
System.out.println("Second name: " + secondName);
|
||||
System.out.println("Age: " + age);
|
||||
System.out.println("Room number: " + roomNumber);
|
||||
}
|
||||
}
|
@ -1,10 +1,57 @@
|
||||
package com.example;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
|
||||
Loading load = new Loading();
|
||||
load.LoadingMessage();
|
||||
|
||||
Vehicle v = new Vehicle();
|
||||
v.horn();
|
||||
v.color = "Red";
|
||||
v.fuelCapacity = 15;
|
||||
v.maxSpeed = 250;
|
||||
v.wheels = 15;
|
||||
|
||||
/*
|
||||
Class Attributes
|
||||
You are the administrator of a hotel and must create customer information cards for your new customers. On the card, you must note the customer’s first and last name, age, and room number.
|
||||
The program you are given takes a guest's data (first name, last name, age, and room number) as input.
|
||||
Complete the class by adding corresponding attributes so that the saveCustomerInfo() method works correctly. Also assign taken data values to attributes of created object.
|
||||
Sample Input
|
||||
John
|
||||
Smith
|
||||
35
|
||||
204
|
||||
Sample Output
|
||||
First name: John
|
||||
Second name: Smith
|
||||
Age: 35
|
||||
Room number: 204
|
||||
*/
|
||||
Scanner read = new Scanner(System.in);
|
||||
String firstName = read.nextLine();
|
||||
String secondName = read.nextLine();
|
||||
int age = read.nextInt();
|
||||
int roomNumber = read.nextInt();
|
||||
Customer customer = new Customer();
|
||||
customer.firstName = firstName;
|
||||
customer.secondName = secondName;
|
||||
customer.age = age;
|
||||
customer.roomNumber = roomNumber;
|
||||
|
||||
String name = read.nextLine();
|
||||
age = read.nextInt();
|
||||
Student student = new Student();
|
||||
student.name = name;
|
||||
|
||||
//set the age via Setter
|
||||
student.setAge(age);
|
||||
|
||||
System.out.println("Name: " + student.name);
|
||||
System.out.println("Age: " + student.getAge());
|
||||
}
|
||||
}
|
22
ClassesAndObjects/src/main/java/com/example/Student.java
Normal file
22
ClassesAndObjects/src/main/java/com/example/Student.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.example;
|
||||
|
||||
class Student {
|
||||
|
||||
public String name;
|
||||
private int age;
|
||||
|
||||
public int getAge() {
|
||||
//complete Getter
|
||||
return age;
|
||||
|
||||
}
|
||||
public void setAge(int age) {
|
||||
//complete Setter
|
||||
if(age >= 0){
|
||||
this.age = age;
|
||||
}else{
|
||||
age = 0;
|
||||
System.out.println("Invalid age");
|
||||
}
|
||||
}
|
||||
}
|
22
ClassesAndObjects/src/main/java/com/example/Vehicle.java
Normal file
22
ClassesAndObjects/src/main/java/com/example/Vehicle.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.example;
|
||||
|
||||
public class Vehicle {
|
||||
int maxSpeed;
|
||||
int wheels;
|
||||
String color;
|
||||
double fuelCapacity;
|
||||
|
||||
void horn() {
|
||||
System.out.println("Beep!");
|
||||
}
|
||||
|
||||
//Getter
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
// Setter
|
||||
public void setColor(String c) {
|
||||
this.color = c;
|
||||
}
|
||||
}
|
BIN
ClassesAndObjects/target/classes/com/example/Customer.class
Normal file
BIN
ClassesAndObjects/target/classes/com/example/Customer.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
ClassesAndObjects/target/classes/com/example/Student.class
Normal file
BIN
ClassesAndObjects/target/classes/com/example/Student.class
Normal file
Binary file not shown.
BIN
ClassesAndObjects/target/classes/com/example/Vehicle.class
Normal file
BIN
ClassesAndObjects/target/classes/com/example/Vehicle.class
Normal file
Binary file not shown.
Reference in New Issue
Block a user