Problem Statement You have been contracted by a local ski shop to develop a soft
ID: 3855752 • Letter: P
Question
Problem Statement
You have been contracted by a local ski shop to develop a software system to hold information about skis in the store. You will create a new class called Ski that will be able to represent different skis for sale in the store. These skis have a name, cost and length in centimeters. You will also need to make a "get method" for each instance variable as well a constructor that takes the name, cost, and length as parameters. Finally, there must also be a method that allows the user to change the cost of a ski.
Assignment
Create a BlueJ project called Outlab1, add a class called Driver and paste the contents of the attached driver.java file into it. Driver should not be modified until you are directed to do so.
Create a new class called Ski (spelling and capitalization important).
Within Ski, declare an instance variable called name that can contain a value such as "Voile V8", an instance variable called cost that can contain a value such as "649.95", and an instance variable called length that can contain a value such as "193" (but not "178.2").
Create a constructor that takes the following parameters (in order):
The ski's name
The ski's cost
The ski's length
Create the method: getName() that returns the name of the ski.
Create the method: getCost() that returns the cost of the ski.
Create the method: getLength() that returns the length of the ski.
Create the method: changeCost(parameter) where "parameter" is the dataType and variable name of the new cost for that ski. Nothing is returned and the cost is updated.
Once the above is done, and your output matches the relevant output described below, modify the Driver by creating a new instance of your Ski class (a new ski). Populate the variables by passing whatever parameter values you wish to the constructor.
Print out the details of the Ski object you created, then change its cost and print out the details again.
Output
If Ski has been implemented correctly, the contents of the attached output.txt file will match the first part of your output when the main method of Driver is run (right click Driver, select "void main(String[] args)", select "Ok"). Once you create a new Ski instance and print out its details in the Driver, your output will also include that.
Hints
Completing this assignment requires knowledge from the class sessions on the 20th and 23rd of January. Don't panic if things don't make sense before then.
Look through and understand the Driver. It will give you a feel for how your class will be utilized.
If your code does not compile at step 8, do not modify the Driver. You will loose points if you modify the Driver by changing method names just to get it to compile (see grading below). Instead, check that your method names are the same as the assignment directs. Once step 8 runs correctly, then add the additional information to the Driver.
Driver
public class Driver
{
public static void main(String[] args)
{
Ski ski1 = new Ski("Voile V8", 649.95, 193);
Ski ski2 = new Ski("La Sportiva Vapor Nano", 959.96, 188);
Ski ski3 = new Ski("Atomic Century", 399.99, 166);
System.out.println("The " + ski1.getLength() + "cm " + ski1.getName() + " costs $" + ski1.getCost() + ".");
System.out.println("The " + ski2.getLength() + "cm " + ski2.getName() + " costs $" + ski2.getCost() + ".");
System.out.println("The " + ski3.getLength() + "cm " + ski3.getName() + " costs $" + ski3.getCost() + ".");
System.out.println(" Changing Costs... ");
ski1.changeCost(599.99);
ski2.changeCost(1200);
ski3.changeCost(351.23);
System.out.println("The " + ski1.getName() + " now costs $" + ski1.getCost() + ".");
System.out.println("The " + ski2.getName() + " now costs $" + ski2.getCost() + ".");
System.out.println("The " + ski3.getName() + " now costs $" + ski3.getCost() + ".");
//Put your additions to the Driver below this, when you get to that part of the assignment.
}
}
OUtput :
Explanation / Answer
Driver.java
public class Driver
{
public static void main(String[] args)
{
Ski ski1 = new Ski("Voile V8", 649.95, 193);
Ski ski2 = new Ski("La Sportiva Vapor Nano", 959.96, 188);
Ski ski3 = new Ski("Atomic Century", 399.99, 166);
System.out.println("The " + ski1.getLength() + "cm " + ski1.getName() + " costs $" + ski1.getCost() + ".");
System.out.println("The " + ski2.getLength() + "cm " + ski2.getName() + " costs $" + ski2.getCost() + ".");
System.out.println("The " + ski3.getLength() + "cm " + ski3.getName() + " costs $" + ski3.getCost() + ".");
System.out.println(" Changing Costs... ");
ski1.changeCost(599.99);
ski2.changeCost(1200);
ski3.changeCost(351.23);
System.out.println("The " + ski1.getName() + " now costs $" + ski1.getCost() + ".");
System.out.println("The " + ski2.getName() + " now costs $" + ski2.getCost() + ".");
System.out.println("The " + ski3.getName() + " now costs $" + ski3.getCost() + ".");
//Put your additions to the Driver below this, when you get to that part of the assignment.
}
}
Ski.java
public class Ski {
private String name;
private double cost;
private int length;
public Ski(String name, double cost, int length) {
this.name = name;
this.cost=cost;
this.length=length;
}
public String getName() {
return name;
}
public double getCost() {
return cost;
}
public int getLength() {
return length;
}
public void changeCost(double cost) {
this.cost = cost;
}
}
Output:
The 193cm Voile V8 costs $649.95.
The 188cm La Sportiva Vapor Nano costs $959.96.
The 166cm Atomic Century costs $399.99.
Changing Costs...
The Voile V8 now costs $599.99.
The La Sportiva Vapor Nano now costs $1200.0.
The Atomic Century now costs $351.23.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.