FromYesterday

This commit is contained in:
2024-09-15 20:18:39 +02:00
parent 063ecdfcdd
commit 113fcbc694
8 changed files with 105 additions and 0 deletions

View 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);
}
}

View File

@ -1,10 +1,57 @@
package com.example; package com.example;
import java.util.Scanner;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello world!"); System.out.println("Hello world!");
Loading load = new Loading(); Loading load = new Loading();
load.LoadingMessage(); 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 customers 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());
} }
} }

View 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");
}
}
}

View 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;
}
}