Question
this is a beginner Java program for Dance classes registration below, I needhelp to improve program using array list . That contains name of the
this is a beginner Java program for Dance classes registration below, I needhelp to improve program using array list .
That contains name of the class, class length and price of the class:
Name Hip hop
Class 45 min long
Price $65
How to incorporate arrays list containning folloving information
Hip hop 45min $65
Tap/ballet 1 hour $75
jazz 1;30pm $100
into following programm:
1.
ublic class DanceClass {
private int age;
/**
* The constructor accepts an argument * for the age field.
*/
public DanceClass(int age) {
this.age = age;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public String getDanceClass() {
String danceClass;
Level level = Level.valueOf("AGE"+age);
if (age == 3)
danceClass = "Level: "+level.showLevel(age)+" Dance Type: "+DanceType.TAPBALLET+" Time: "+"Saturday 10am";
else if(age == 4) danceClass = "Level: "+level.showLevel(age)+" Dance Type: "+DanceType.TAPBALLET+" Time: "+"Saturday 10:30am";
else if(age == 5) danceClass = "Level: "+level.showLevel(age)+" Dance Type: "+DanceType.HIPHOP+" Time: "+"Saturday 11:30am";
else if(age == 6) danceClass = "Level: "+level.showLevel(age)+" Dance Type: "+DanceType.JAZZ+" Time: "+"Saturday 12:30am";
else danceClass = "class is not available";
return danceClass;
}
}
2.
public enum DanceType {
TAPBALLET,
HIPHOP,
JAZZ;
}
3
public enum Level { AGE3(3),AGE4(4),AGE5(5),AGE6(6); private String level; int age; Level(int age){ age = age; } String showLevel(int age){ if(age>2 && age < 5) level = "BEGINNER"; else level = "INTERMEDIATE"; return level; } }
4.
public class UserRegistrationForm {
private String name;
private String address;
private String phoneNumber;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
5.
import java.util.Scanner;
public class danceClassResults {
public static void main(String[] args) {
int age;
// To hold a age of a student String danceClass;
// to hold schedule for the class
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
//Get user registration details for the kid
UserRegistrationForm newUser = new UserRegistrationForm();
System.out.println("Please provide your information.");
System.out.println("Name:");
newUser.setName(keyboard.nextLine());
System.out.println("Address:");
newUser.setAddress(keyboard.nextLine());
System.out.println("PhoneNumber:");
newUser.setPhoneNumber(keyboard.nextLine());
// Get age
System.out.println("Enter child's age and " + "I will tell you the schedule: ");
age = keyboard.nextInt();
// Create a danceclass object .
DanceClass test = new DanceClass(age);
// Get the dance class.
String danceClass = test.getDanceClass();
// Display the class.
System.out.print("Available class is " + danceClass);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started